react-native: Issue building android duplicate versions of jetified-kotlin-stdlib-1

Description

running npx react-native android

I get the following error:

Execution failed for task ':app:mergeDebugJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'META-INF/kotlin-stdlib-jdk7.kotlin_module'.

This repros in CI as well

Version

0.63.5

Output of npx react-native info

System: OS: macOS 13.0.1 CPU: (16) x64 Intel® Core™ i9-9880H CPU @ 2.30GHz Memory: 136.32 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 14.18.0 - ~/.nvm/versions/node/v14.18.0/bin/node Yarn: 1.22.18 - /usr/local/bin/yarn npm: 8.19.2 - ~/.nvm/versions/node/v14.18.0/bin/npm Watchman: 2022.09.19.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 4.2 AI-202.7660.26.42.7351085 Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: 11.0.16.1 - /usr/bin/javac Python: 3.10.3 - /Users/Jake/.pyenv/shims/python npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.63.5 => 0.63.5 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

npx react-native android

Snack, code example, screenshot, or link to a repository

NA

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 14
  • Comments: 24 (1 by maintainers)

Commits related to this issue

Most upvoted comments

This fix worked for me in the meantime:

dependencies {
     constraints {
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
            because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
        }
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
            because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
        }
    }
}

(android/app/build.gradle)

I think if using a modern Kotlin Gradle Plugin you can also add the Gradle property kotlin.stdlib.jdk.variants.version.alignment=false (https://kotlinlang.org/docs/whatsnew18.html#usage-of-the-latest-kotlin-stdlib-version-in-transitive-dependencies)

Below fixed work for me.

implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

Checkout here

In my company’s case I did a comparison of the gradle dependency graph to identify what introduced the change in the build dependencies.

The problem, in our case, was introduced by this library’s use of a version wildcard: https://github.com/proyecto26/react-native-inappbrowser/issues/398

And the solution we went with was to specify androidXAnnotation = "1.5.0" as an ext in the android/build.gradle file

I believe this is the same issue I’ve been battling with for a couple of hours now.

* What went wrong:
Execution failed for task ':app:checkReleaseDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > 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.4.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10)

I found a potential fix of upgrading kotlinVersion to 1.8.0 in build.gradle, but that didn’t help. Apparently because React Native has version 1.4.10 on it.

I thought I was the only one, I have also been getting this same issue since today.

In my company’s case I did a comparison of the gradle dependency graph to identify what introduced the change in the build dependencies.

The problem, in our case, was introduced by this library’s use of a version wildcard: proyecto26/react-native-inappbrowser#398

And the solution we went with was to specify androidXAnnotation = "1.5.0" as an ext in the android/build.gradle file

this should be the best workaround

Closing as the workaround is reported as working fine.

implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

This worked for me.

Below fixed work for me.

implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

Checkout here

Saved my day

This fix worked for me in the meantime:

     constraints {
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
            because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
        }
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
            because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
        }
    }

(android/app/build.gradle)

I think if using a modern Kotlin Gradle Plugin you can also add the Gradle property kotlin.stdlib.jdk.variants.version.alignment=false (https://kotlinlang.org/docs/whatsnew18.html#usage-of-the-latest-kotlin-stdlib-version-in-transitive-dependencies)

This worked for me, thanks!

implementation(platform(“org.jetbrains.kotlin:kotlin-bom:1.8.0”))

Me too. But I sinceraly don’t understand why after creation Java-project with Android Studio’s wizard I have any problems with Kotlin.

I believe this is the same issue I’ve been battling with for a couple of hours now.

* What went wrong:
Execution failed for task ':app:checkReleaseDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > 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.4.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10)

I found a potential fix of upgrading kotlinVersion to 1.8.0 in build.gradle, but that didn’t help. Apparently because React Native has version 1.4.10 on it.