skip to Main Content

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.3.31 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31)

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.3.31 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31)

**./gradlew clean **

build.gradle file:



buildscript {
    ext {
        buildToolsVersion = "30.0.0"
        minSdkVersion = 23
        compileSdkVersion = 33
        targetSdkVersion = 30
        googlePlayServicesAuthVersion = "16.0.1"
        kotlinVersion = "1.8.0"
    }
    
    firebase: [
        bom           : "26.0.0"
    ]
    
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {

        classpath "com.android.tools.build:gradle:4.2.0" 
        classpath "com.google.gms:google-services:4.3.4"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

    }
}
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
    repositories {
        configurations.all {
            resolutionStrategy {

                force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
            }
        }
        mavenLocal()
        maven {

            url("$rootDir/../node_modules/react-native/android")
        }
        maven {

            url("$rootDir/../node_modules/jsc-android/dist")
        }
        maven { url 'https://maven.google.com' }
        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

6

Answers


  1. Chosen as BEST ANSWER

    Thanks all, I solve it by doing two things

    In android/build.gradle update the following

    kotlinVersion = "1.8.0"

    In android/app/build.gradle add the following in dependencies

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


  2. I started having the same issue in react native native on the android side. I upgraded Kotlin to version 1.8.0 and built the app again and the issue was fixed. Maybe trying upgrading the kotlin version.

    In android/build.gradle update the following

    kotlinVersion = "1.8.0"

    and add this under dependencies

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

    Login or Signup to reply.
  3. I was having the same problem since yesterday.
    I found that the reason behind this could be the artifact merge in Kotlin 1.8.0. Here is an issue talking about this breaking change.

    So setting kotlinVersion = "1.8.0" as @Narasimha said works. But I still didn’t figure out what dependency changed overnight that somehow made kotlin-stdlib:1.8.0 appear in the build logs.

    Login or Signup to reply.
  4. This can happen when you’re using different versions for different Kotlin dependencies.

    Try to check all Kotlin dependencies. In my case, issue was with this core-ktx

    implementation "androidx.core:core-ktx:+"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    

    Updating to this resolved issue

    implementation "androidx.core:core-ktx:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    

    Here kotlin_version = '1.7.0'. You can use your desired version.
    Hope this will help others.

    Login or Signup to reply.
  5. I had the same problem with my app. It failed to build because of duplicate classes found in modules jetified-kotlin-stdlib-1.8.0 and jetified-kotlin-stdlib-jdk8-1.6.10

    With the link, shared by Igor VANIAN : https://kotlinlang.org/docs/whatsnew18.html#usage-of-the-latest-kotlin-stdlib-version-in-transitive-dependencies
    I added

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

    to my android/app/build.gradle and Android builds fine now

    Login or Signup to reply.
  6. I had the same issue today and I fixed it in a different way, if it helps anyone:
    When I upgraded my kotlin to version 1.8 it started happening and I had to change my hilt version to 2.44. Now it’s running normally.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search