9

I am getting the next error appearing on running npx react-native run-android. It came out of nowhere - no changes have been committed.

Execution failed for task ':app:checkDebugDuplicateClasses'.
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.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)

Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
     
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
     
Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)
     
Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)

What I tried:

  1. Follow again the installation steps on official react native documentation page: https://reactnative.dev/docs/environment-setup

     brew install node
     brew install watchman
     brew tap homebrew/cask-versions
     brew install --cask zulu11
    
  2. Uninstall and install Android Studio

  3. Set kotlinVersion = "1.8.0" in android/build.gradle:

     buildToolsVersion = "32.0.0"
     minSdkVersion = 21
     compileSdkVersion = 33
     targetSdkVersion = 33
     // here
     kotlinVersion = "1.8.0"
    

It looks like if I get rid of "react-native-inappbrowser-reborn": "^3.7.0" library the error is gone and the app launches successfully. But what if I need react-native-inappbrowser-reborn in my project?

Thank you mates in advance!

7
  • 2
    I'm glad I saw this because I thought I was going crazy! It was working fine yesterday, and now with no changes to my code, I also get this very similar error! Commented Jan 27, 2023 at 3:26
  • 1
    Oh, happy not to be alone here! Will post solution as I find it Commented Jan 27, 2023 at 7:00
  • 1
    Does this answer your question? Execution failed for task ':app:checkReleaseDuplicateClasses' Commented Jan 27, 2023 at 8:27
  • Thank you for response but it didn't work for me :( Commented Jan 27, 2023 at 8:35
  • 1
    @spatak Are you using react-native-onesignal? When I remove it, it compiles. I tried upgrading it but it still fails... researching... Commented Jan 27, 2023 at 15:11

6 Answers 6

19

This is caused by the Kotlin plugin update. You can fix it easily by using configure below:

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.android.support:multidex:2.0.1'
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    // Add this line here
    implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')

    //...omit some code
}

You can refer this one: Kotlin Document

Sign up to request clarification or add additional context in comments.

1 Comment

// android/app/build.gradle
1

Add this to android/app/build.gradle

configurations.all {
resolutionStrategy {
    eachDependency {
        if ((requested.group == "org.jetbrains.kotlin") && (requested.name.startsWith("kotlin-stdlib"))) {
            useVersion("1.6.10")
        }
    }
}

}

4 Comments

Why did you copy-paste the solution from the user above?
I'm the first one who write the solution, check the time please before judging people
Checked, yesterday. You were 2 minutes late
That's for me: 20:44:59 That's for Eli: 20:46:39
0

For me, it was a combination of the react-native-iap and the react-native-onesignal packages that was causing the issue.

Upgrading react-native-onesignal didn't work, so I upgraded react-native-iap as far as I could go without breaking changes, and for me, that was v7.5.6.

After upgrading iap to 7.5.6, I also had to add this to my ../android/app/build.gradle file for it to compile:

defaultConfig {
    ...
    missingDimensionStrategy 'store', 'play'
}

Edit: I think what's happening is that one of your packages has a loose dependency, which caused an unexpected update. So each case could be different.

Comments

0

I was having this for @shopify/flash-list. There is a github issue [1] for it.

To fix it, add kotlinVersion = "1.8.10" on your build.gradle file

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        kotlinVersion = "1.8.10" // 👈🏻 this to be added
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath ("com.google.gms:google-services:4.3.15")
    }
}

References

1: https://github.com/Shopify/flash-list/issues/862

Comments

0

This fixed my issue

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        kotlinVersion = "1.7.22" // add this
        ndkVersion = "23.1.7779620"
    }
    ...
}

Comments

-1

In your android/app/build.gradle file set kotlin-stdlib to use the same verion

for example:

configurations.all {
    resolutionStrategy {
        eachDependency {
            if ((requested.group == "org.jetbrains.kotlin") && (requested.name.startsWith("kotlin-stdlib"))) {
                useVersion("1.7.20")
            }
        }
    }
}

1 Comment

I think it is not an elegant solution. This error occurred instantly - not due to any code changes or something like this. I think there is something wrong with kotlin or jdk - probably need to update them etc

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.