437

Image Example

I kept on getting an error that there is a duplicate error in classes. This is what I have under org.jetbrains.kotlin folder .idea/libraries

It seems like the problem is because there is two different dependencies for Kotlin, from stdlib and stdlibjdk8, but I don't know how to remove either one from my module/project dependencies. How can I do it?

Here's the full error code:

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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
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.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)

I've tried deleting the files from the org.jetbrains.kotlin, but whenever I build the app in Android Studio, the files will be redownloaded again.

This is my module app Gradle code:


plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

android {
    compileSdk 33

    defaultConfig {
        applicationId "com.example.umfs"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildFeatures {
        viewBinding true
    }

    namespace 'com.example.umfs'
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.firebase:firebase-database:20.1.0'
    implementation 'androidx.preference:preference:1.2.0'
    implementation 'com.google.firebase:firebase-auth:21.1.0'
    implementation 'com.google.firebase:firebase-core:21.1.1'
    implementation 'androidx.navigation:navigation-fragment:2.5.3'
    implementation 'androidx.navigation:navigation-ui:2.5.3'
    implementation 'com.google.firebase:firebase-firestore:24.4.1'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    implementation "androidx.cardview:cardview:1.0.0"
    implementation 'com.google.firebase:firebase-firestore:24.4.1'
    implementation 'com.google.firebase:firebase-storage:20.1.0'
    implementation 'com.google.firebase:firebase-database'
    implementation platform('com.google.firebase:firebase-bom:28.4.0')
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.makeramen:roundedimageview:2.3.0'
    implementation 'com.github.bumptech.glide:glide:4.14.2'
    implementation 'com.github.marlonlom:timeago:4.0.3'
    implementation "androidx.core:core-ktx:+"

}

apply plugin: 'com.google.gms.google-services'
6
  • 71
    I thought I was the only one who got this error while having had no use of Kotlin anywhere in my large project.. Then I came across this very-obvious-to-me-now answer and it solved it very simply for me... stackoverflow.com/a/75315276/4355877
    – Mick
    Commented Mar 6, 2023 at 16:11
  • 3
    @Mick Thank you so much for the tip, a lifesaver for those shunning Kotlin.
    – Hong
    Commented Mar 28, 2023 at 15:58
  • @midnighthowlers Try this solution once: stackoverflow.com/a/75974885/16765223
    – MDEV
    Commented Apr 10, 2023 at 6:59
  • This answer worked for me. It's on page 2, that's why I'm adding this as a comment here: stackoverflow.com/a/75550269/4833705 Commented Jul 26, 2023 at 10:37
  • Why do we need 62 answers to this question? Commented Dec 3, 2023 at 3:31

66 Answers 66

336

Simply. For me, just change this Gradle plugin from 1.7.10 to 1.8.0 Then synchronise → invalidate caches → build

From:

plugins {
    ....
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

To:

plugins {
    ....
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
14
  • 69
    Note: After updating to '1.8.0', do not forget to update kotlinCompilerExtensionVersion as '1.4.0' . Commented Feb 4, 2023 at 23:22
  • 14
    I get a compilation error: This version (1.3.2) of the Compose Compiler requires Kotlin version 1.7.20 but you appear to be using Kotlin version 1.8.0 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!). Commented Feb 10, 2023 at 12:15
  • 2
    Question as a noob: Where should I add the above? Commented Feb 12, 2023 at 22:02
  • 3
    @PrasannjeetSingh It is build.gradle file
    – kangkyu
    Commented Mar 25, 2023 at 8:24
  • 5
    @IgorGanapolsky - You can update the kotlinCompilerExtensionVersion to 1.4.4 in app level build.gradle. You can find this in ComposeOptions {} block. Check the link below to find the correctly mapped version (developer.android.com/jetpack/androidx/releases/compose-kotlin)
    – Mazhar
    Commented May 5, 2023 at 15:18
250

See this note in the official Kotlin documentation for an explanation of how alignment works with these dependencies and build flags. The below original answer is an alternative approach which doesn't take this into account.

This is because kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8 are older dependencies that should be replaced by kotlin-stdlib (As @MrPNG pointed out from the what's new docs for Kotlin 1.8). However, other libraries may still declare a dependency on them, which needs to be replaced with a dependency on kotlin-stdlib.

You can override how the jdk7 and jdk8 versions are resolved like this (in your app/build.gradle):

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")
        }
    }
}

The constraints section above can be added in alongside your other dependencies. Choose the version (here 1.8.0) to match the one you actually want to be used, which should be the one that your non-jdkN-named version is in the duplicate class error (e.g., (org.jetbrains.kotlin:kotlin-stdlib:1.8.0))

If you have apply plugin: 'kotlin-android' in this file, then it doesn't need to separately also say to depend on the stdlib in dependencies, so remove any lines that look like this:

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

(thanks to this blog)

11
  • 7
    I have a project where the build failed for the same reason as above. And I am not using any kotlin code in my project. Is there a way to disable any and all kotlin dependencies so that I can't possibly get a "duplicate classes" for kotlin dependencies?
    – AJW
    Commented Mar 9, 2023 at 0:10
  • 1
    If you're not using any kotlin code, it sounds like a very different problem even if it has the same error message... probably worth posting as a separate question Commented Mar 10, 2023 at 14:22
  • 5
    @AJW You may think that you don't use any Kotlin code in your project, but the dependencies you use can use Kotlin code inside them (for example various AndroidX libraries are written in Kotlin).
    – Robyer
    Commented Mar 17, 2023 at 11:00
  • 2
    It works now. You can also find information in youtrack.jetbrains.com.
    – Blue Ocean
    Commented Mar 23, 2023 at 10:22
  • 1
    With Android Studio Giraffe (2022.3.1 Beta 1), I get a warning in the IDE: 'implementation' is defined by 'dependencies' but used within 'constraints'. Any idea why, and how to get rid of it? Commented Apr 26, 2023 at 8:39
179

I have tried all the previous solutions but after adding the below code it was working.

dependencies {
   ... ... ...
   implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
   ... ... ...
}
9
  • 12
    This worked for me even though our project is a pure Java project without any Kotlin code. The clue that it would came from here: youtrack.jetbrains.com/issue/KT-55297/…
    – Tom Ladek
    Commented Apr 21, 2023 at 14:59
  • 3
    This fixed my issue as well
    – Climax
    Commented May 4, 2023 at 16:48
  • 2
    This also worked for me. I think this is sufficient if you are not using Kotlin directly.
    – isomeme
    Commented Jun 5, 2023 at 4:49
  • 3
    Fixed it for me as well: project is pure Java (no Kotlin).
    – dazed
    Commented Jun 23, 2023 at 11:58
  • 1
    This should be marked as correct answer (y)
    – Gonzalo GM
    Commented Jul 10, 2023 at 17:10
60

I was getting the same error after upgrading the Android annotation library from version 1.4.0 to 1.6.0,

implementation 'androidx.annotation:annotation:1.6.0'

So I downgraded to 1.5.0 and the error was gone:

implementation 'androidx.annotation:annotation:1.5.0'
2
  • 10
    I'm not using kotlin in a project and this solved my problem.
    – joninx
    Commented Mar 23, 2023 at 11:46
  • 2
    Unfortunately Kotlin is now a dependency for many of the Android core libraries, so now you are using Kotlin indirectly whether you want it or not. Unfortunately, that means we get the build problems that come with it.
    – Dustin
    Commented Jun 12, 2023 at 3:00
40

Upgrade kotlin android plugin and kotlin compiler

plugins {
    id 'org.jetbrains.kotlin.android' version '1.8.10'
}
android {
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"
    }
}
3
  • 3
    This worked for me. Although I only needed to upgrade the kotlin android plugin. Thanks! Commented Apr 10, 2023 at 20:11
  • 5
    Adding the plugin worked for me, although my project is only Java and I don't use Kotlin at all. This really looks to me like a flaw in Android Studio, if not completely a bug.
    – Gabriel
    Commented Apr 11, 2023 at 13:57
  • same here; adding "implementation (platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))" fixed the issue, EVEN if I have no kotlin code. Commented Jun 19, 2023 at 10:24
35

You can now update the lifecycle dependencies to the most up-to-date versions, and simply add the following line in your build.gradle

dependencies {

    (...)

    // Fix Duplicate class
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

}
4
  • 2
    Everything complied fine. Then I updated androidx fragments from 1.5.7 to 1.6 and about 100 kotlin duplicate class errors occurred. What worries me is that they did not vanish when I got back to 1.5.7 and deleted build and invalidate cache. Its like black magic - it messes you up and sticks with you even if you revert back to older version! Still this implementation fixes those duplicate classes thank you Commented Jun 15, 2023 at 12:22
  • Can anyone please elaborate on why this works? I have no clue how it fixed my issue of duplicate classes. Commented Jul 15, 2023 at 6:35
  • the only fix that worked for me is this, thanks! Commented Jul 28, 2023 at 13:13
  • 1
    @WahajMubeen apparently we are using mutliple dependencies in pubsec.yaml file, and they all need the kotlin versions to be aligned, but each uses a diff version, which causes this issue, the fix mentioned above , is a solution to fix the duplicate class error. It resolves the conflict by using the Kotlin Bill of Materials (BOM) to ensure that all Kotlin dependencies in your project use the same version. Commented Jul 28, 2023 at 13:16
30

I tried many ways to solve this same prolem but didnt work I tried to add this dependencies below in my "build.gradle(module:app)"..

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

and then synce now, it will resolve this error.

1
  • 2
    Thanks a lot. This saved the day. I recommend everyone to try this first. Commented Jun 21, 2023 at 9:55
27

I solved the problem by changing the Kotlin class path dependency in the root build.gradle file from

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20-RC"

to

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
19

edit app/build.gradle file in flutter

dependencies {

    (...)

    // Fix Duplicate class
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

}
18

Add the below line in your build.gradle(Module:app)

dependencies {

(...)

// Fix Duplicate class
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

}

This is because kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8 are older dependencies that should be replaced by kotlin-stdlib. However, other libraries may still declare a dependency on them, which needs to be replaced with a dependency on kotlin-stdlib.

14

This problem will be solved by adding the dependency in build.gradle(app) file

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0"

it's working properly

2
13

I was using org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10 before in our SDK and then I updated kotlin to v1.8.0 and that's when I started getting the above error in our Android Java front end application. Using org.jetbrains.kotlin:kotlin-bom resolved the issue with transitive dependencies and might be a cleaner approach since it doesn't leak Kotlin details into the Java application.

so I just replaced

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10"

with below which solved the problem for me.

// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.0"
0
10

enter image description here

You will get this type of Duplicate Kotlin Class Issue

Fix for This Issue:

android/app/build.gradle--->

dependencies {

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

}

Add this dependency and it will fix the issue immediately.

0
9

If you are using Compose you need to update the Compose Compiler (https://developer.android.com/jetpack/androidx/releases/compose-compiler) to 1.4.2 and Kotlin to 1.8.10 at the same time.

8

Use:

configurations.all {
    resolutionStrategy {
        force 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.10'
    }
}

Adding this to the end of the Gradle file helps.

2
  • This solution literally fixed the problem. Thanks!
    – ElyasAsmad
    Commented Jun 29, 2023 at 16:55
  • Fixed it. For me it was important to know that it needs to go into the android/app/build.gradle file, and not in the android/build.gradle file.
    – novas1r1
    Commented Aug 8, 2023 at 7:33
8

Step 1: Add this

plugins {
        id 'com.android.application'
        id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
    }

Step 2: Add this on the dependencies

dependencies {

.....

  constraints{
        implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10'
        implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.10'
    }
}

Note: version '1.8.10', jdk7:1.8.10 and jdk8:1.8.10 are the same...

7

Go to the settings.gradle, change the following line:-

From :

plugins {
....
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false 

}

To :

plugins {
....
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false

}

Then run your app.

6

I had the same error on my Kotlin project. When I add Ktor to my project and upgraded the library versions, and then I got the wired long error. This is how I fixed it.

I used compose version 1.4.0

ext {
    compose_ui_version = '1.4.0'
}

kotlin version 1.8.0, the latest one 1.8.10 not compatible with compose 1.4.0 So I used,

id 'org.jetbrains.kotlin.android' version '1.8.0' apply false

Then, adjust the composeOptions on app level build.gradle file, like

composeOptions {
    kotlinCompilerExtensionVersion '1.4.0'
}

These are the three changes that I have done and I got escaped from the wired error. Hope this will help someone.

0
6
lifecycle-viewmodel-ktx-2.6.1

down

lifecycle-viewmodel-ktx-2.5.1

I managed to get it working by lowering the dependency values.

6

I fixed it by making Compose Compiler and JetBrains Kotlin plugins compatible

First, make sure are you using org.jetbrains.kotlin.android plugin version above 1.8.0.

build.gradle(Project)

plugins {
  ...
  id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
}

Then check compatible version of Compose Compiler from below link and update build.gradle(app):
https://developer.android.com/jetpack/androidx/releases/compose-kotlin#pre-release_kotlin_compatibility

android {
  ...
  composeOptions {
    kotlinCompilerExtensionVersion '1.4.7'
  }
}
6

add this inside your dependencies, it will solve the error.

dependencies {

    (...)

    // Fix Duplicate class
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

}
2
  • 1
    Great! Using the Kotlin Bill of Materials (BOM) is indeed a good approach to manage the Kotlin version and ensure consistency throughout your project. By specifying the Kotlin BOM, you're effectively managing the Kotlin version for your project and avoiding conflicts related to duplicate class issues. Including the Kotlin BOM allows you to define the Kotlin version in a single place, making it easier to manage dependencies and prevent version conflicts. It's a good practice, especially when dealing with Kotlin in multi-module or complex projects. Commented Oct 4, 2023 at 18:03
  • Working through this one now. I added this and got past the duplicate class error but now run into: ``` ERROR:D8: com.android.tools.r8.kotlin.H ERROR:D8: com.android.tools.r8.kotlin.H Execution failed for task ':app:mergeExtDexDebug'. ``` Commented Feb 5 at 14:09
5

Workaround for earlier KGP versions now is:

File app/build.gradle

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")
        }
    }
}
4

According to the release notes of Kotlin 1.8.0 (https://kotlinlang.org/docs/whatsnew18.html#updated-jvm-compilation-target), you shouldn't specify kotlin-stdlib-jdk7 nor kotlin-stdlib-jdk8 as dependencies anymore and, instead, just use kotlin-stdlib.

4

I ran into this issue today and I fixed it by upgrading both Kotlin std-lib for android and the std-lib itself. Also it's worth mentioning that if you're using compose, you have upgrade the kotlinCompilerExtensionVersion

Here is the final setup

  • gradle file at Module level
composeOptions {
    kotlinCompilerExtensionVersion '1.4.3'
}
  • root project gradle file
plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.8.10' apply false
}
4

This happened to me when upgrading one of these

implementation 'androidx.navigation:navigation-fragment:2.5.3'
implementation 'androidx.navigation:navigation-ui:2.5.3'

To version 2.6.0. When rolling back to 2.5.3 the error went away.

1
  • I had the same issue. Downgraded from 2.7.2 to 2.5.3 and it worked. But why is the new version not working? I don't know...
    – zomega
    Commented Oct 3, 2023 at 14:33
4

If I update kotlin version to 1.8.0 then it forces me to use view binding

i.e. classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10'

then if you want to keep kotlin version as it was before then just add it in app level gradle-

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0"

it will solve duplicate class issues though it is a temporary solution. Here my AGP version is 7.4.1 and Gradle version is 7.5

4

The issue may be easely fixed by one line only:

dependencies {
.....
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0'
}
4

It is maybe some updated version dependency. In my new compose app, when I updated

implementation 'androidx.compose.material3:material3:*'(new version) from 1.0.0-alpha11

I will got this error. Try revert updated dependency.

Also, I was getting this error when android studio was added in my Gradle modules ktx:+ dependency.

1
  • Same here. Had to downgrade material3 version to '1.1.0-alpha04'
    – Blaupunkt
    Commented Feb 23, 2023 at 8:13
3

I had the same errors in my project. What finally helped me was the following steps

1-I have updated the buildScript: as below

buildscript {
    ext {
        compose_ui_version = '1.3.3'
    }
}
then change pluggin 
From

plugins {
....
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false

}

To

plugins {
....
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
}

lastly updated in build.grade(app)

Change in android scope {}

    android {
    ......
    composeOptions {
            kotlinCompilerExtensionVersion '1.2.0'
        }
    .......
    }

To the following and the errors were gone

 composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"
    }

Hope it helps someone else 
3

kotlinCompilerExtensionVersion(compose) -> kotlin_version

1.4.4 -> 1.8.10

1.4.3 -> 1.8.10

1.4.2 -> 1.8.10

1.4.1 -> 1.8.0

1.4.0 -> 1.8.0

1.4.0-alpha02 -> 1.7.21

1.4.0-alpha01 -> 1.7.20

1.3.2 ->1.7.20

...

Other versions: https://developer.android.com/jetpack/androidx/releases/compose-kotlin

Not the answer you're looking for? Browse other questions tagged or ask your own question.