proyecto26 / react-native-inappbrowser

📱InAppBrowser for React Native (Android & iOS) 🤘
https://www.npmjs.com/package/react-native-inappbrowser-reborn
MIT License
1.29k stars 220 forks source link

New androidXAnnotation version breaks Android builds #398

Closed IgorVanian closed 8 months ago

IgorVanian commented 1 year ago

Which platform(s) does your issue occur on?

TL;DR

This line currently installs version 1.6.0 of annotations https://github.com/proyecto26/react-native-inappbrowser/blob/e028173df5ffea7b8c1f3214669cdde33981ee14/android/build.gradle#L67

This version has a kotlin-stdlib:1.8.0 dependency. By default gradle is using the higher version of this lib in the project, which makes this issue to pop up.

Long version

Hello. After a lot of debugging, I finally found why current Android builds fail with the following error:

[09:58:03]: ▸ > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
[09:58:03]: ▸ > Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.7.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10)

This is due to the merge of jdk7 & jdk8 artifacts that occured in kotlin-stdlib:1.8.0. This results in an error if you use packages that have kotlin-stdlib-jdk7/8 < 1.8.0.

From gradle dependencies I saw that this package is requiring the latest version of annotations:

image

Which can be found here:

https://github.com/proyecto26/react-native-inappbrowser/blob/e028173df5ffea7b8c1f3214669cdde33981ee14/android/build.gradle#L61

The latest 1.6.0 version includes a kotlin 1.8.0 dependency that enables this issue and makes the build fail.

To fix this issue for the moment, we had to specify a fixed kotlinVersion=1.8.0 in the build.gradle file.

balasasidhar commented 1 year ago

+1

shuklaaalind commented 1 year ago

How can we resolve this for now?

IgorVanian commented 1 year ago

@shuklaaalind I opened a PR for this. But for the moment you can add a custom kotlin version to your project like so:

buildscript {
    ext {
        buildToolsVersion = "32.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 32
        androidXBrowser = "1.4.0"

        kotlinVersion = "1.8.0"
    }
...
}
taltrui commented 1 year ago

For those who setting kotlinVersion = "1.8.0" in build.gradle doesn't fix the issue, you can set androidXVersion = "1.5.+" instead.

If you look in the inappbrowser build.gradle:

def androidXVersion = safeExtGet('androidXVersion', null)
  if (supportLibVersion && androidXVersion == null) {
    implementation "com.android.support:support-annotations:$supportLibVersion"
    implementation "com.android.support:customtabs:$supportLibVersion"
  } else {
    def defaultAndroidXVersion = "1.+"
    if (androidXVersion == null) {
      androidXVersion = defaultAndroidXVersion
    }

def androidXVersion = safeExtGet('androidXVersion', null) This line will get the androidXVersion defined in your build.gradle and use it instead of the default "1.+".

costaDZ commented 1 year ago

Took for me two days of investigation , after adding kotlinVersion = "1.8.0" to the build.gradle file it's working for me right now .