DEV Community

Cover image for Fix React Native Android builds "Duplicate class kotlin.collections.* found in modules jetified-kotlin-stdlib-1.8.0"
Davyd NRB
Davyd NRB

Posted on

Fix React Native Android builds "Duplicate class kotlin.collections.* found in modules jetified-kotlin-stdlib-1.8.0"

When I got up this morning, I was perplexed to see that our CI/CD builds were failing repeatedly with the following error:

Execution failed for task ':app:checkStagingReleaseDuplicateClasses'.
> 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.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     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.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10)
     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.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     Duplicate class kotlin.io.path.ExperimentalPathApi found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10)
     Duplicate class kotlin.io.path.PathRelativizer found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10)
     Duplicate class kotlin.io.path.PathsKt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10)
     Duplicate class kotlin.io.path.PathsKt__PathReadWriteKt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10)
     Duplicate class kotlin.io.path.PathsKt__PathUtilsKt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10)
     Duplicate class kotlin.jdk7.AutoCloseableKt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10)
     Duplicate class kotlin.jvm.jdk8.JvmRepeatableKt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     Duplicate class kotlin.random.jdk8.PlatformThreadLocalRandom found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     Duplicate class kotlin.streams.jdk8.StreamsKt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$1 found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$2 found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$3 found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$4 found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     Duplicate class kotlin.text.jdk8.RegexExtensionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
     Duplicate class kotlin.time.jdk8.DurationConversionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.6.10 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10)
Enter fullscreen mode Exit fullscreen mode

I looked for any problems relating to this but came up empty-handed. After making a few attempts, I discovered a workaround:

Your android/app/build.gradle file has to be updated in order to align kotlin-stdlib versions:

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

UPDATE (27-01-2023):

In the android/app/build.gradle file, there is a better way to apply constraints for the two kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8 modules:

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")
        }
    }
Enter fullscreen mode Exit fullscreen mode

Top comments (26)

Collapse
 
mwerder profile image
werder

Thank you so much! Wasted like 3 hours on that!

Collapse
 
davelsan profile image
David Velasco

Just logged in to say thank you.

Collapse
 
retyui profile image
Davyd NRB

You're the best.

Collapse
 
tjdesigner profile image
Tiago de Jesus

Thank you so much!!! I lost a lot of time with this problem. God bless you! 🚀🚀🚀

Collapse
 
abbasalim profile image
Abbasali

great! this worked for me also

Collapse
 
brankoeisi profile image
Branko Bajic

Created an account just to thank you

Collapse
 
petermalinovskiy profile image
Peter Malinovsky • Edited

Thank you for the post. I meet the same errors and your first solution helped to fix them. I try to find a better sollution. I upgraded Kotlin to the latest version and it works fine.

Collapse
 
retyui profile image
Davyd NRB

Please give additional information about how you updated Kotlin in your project or on CI?

Collapse
 
jensneuber profile image
Jens Neuber

Thanks!

Collapse
 
nbimmosnapp profile image
nb-immosnapp

Thanks you so much!

Collapse
 
phen1x profile image
pheN1x

Thank you so much my friend! 100+ build failed yesterday can you explain us how did you find this?

Collapse
 
haripriya_dhall_430c9d258 profile image
Haripriya Dhall

I am also getting a duplicate class error. Please help me to solve it.

Duplicate class com.facebook.jni.DestructorThread found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.DestructorThread$1 found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.DestructorThread$Destructor found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.DestructorThread$DestructorList found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.DestructorThread$DestructorStack found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.DestructorThread$Terminus found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.HybridClassBase found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.HybridData found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.HybridData$Destructor found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.IteratorHelper found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)
Duplicate class com.facebook.jni.MapIteratorHelper found in modules conceal-2.0.2.aar -> jetified-conceal-2.0.2-runtime (com.facebook.conceal:conceal:2.0.2) and fbjni-0.6.0.aar -> jetified-fbjni-0.6.0-runtime (com.facebook.fbjni:fbjni:0.6.0)

I am facing difficulty to solve it. Tried this below solution to solve it.

`configurations.all {

    exclude  module: 'conceal'
    //exclude group: 'com.facebook.conceal', module: 'conceal'
Enter fullscreen mode Exit fullscreen mode

}`

But it throws next error, which related to conceal.

FATAL EXCEPTION: create_react_context
Process: com.propstream, PID: 9831
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/android/crypto/keychain/SharedPrefsBackedKeyChain;