
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, fromstdlib andstdlibjdk8, 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 appGradle 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'- 80I 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/4355877Mick– Mick2023-03-06 16:11:06 +00:00CommentedMar 6, 2023 at 16:11
- 3@Mick Thank you so much for the tip, a lifesaver for those shunning Kotlin.Hong– Hong2023-03-28 15:58:23 +00:00CommentedMar 28, 2023 at 15:58
- @midnighthowlers Try this solution once:stackoverflow.com/a/75974885/16765223MDEV– MDEV2023-04-10 06:59:23 +00:00CommentedApr 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/4833705Lance Samaria– Lance Samaria2023-07-26 10:37:45 +00:00CommentedJul 26, 2023 at 10:37
- Why do we need 62 answers to this question?Peter Mortensen– Peter Mortensen2023-12-03 03:31:02 +00:00CommentedDec 3, 2023 at 3:31
70 Answers70
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 Comments
suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).build.gradle fileSeethis 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 becausekotlin-stdlib-jdk7 andkotlin-stdlib-jdk8 are older dependencies that should be replaced bykotlin-stdlib (As @MrPNG pointed out fromthe 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 onkotlin-stdlib.
You can override how the jdk7 and jdk8 versions are resolved like this (in yourapp/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") } }}Theconstraints section above can be added in alongside your other dependencies. Choose the version (here1.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 haveapply 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 tothis blog)
11 Comments
'implementation' is defined by 'dependencies' but used within 'constraints'. Any idea why, and how to get rid of it?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")) ... ... ...}10 Comments
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 Comments
Upgrade kotlin android plugin and kotlin compiler
plugins { id 'org.jetbrains.kotlin.android' version '1.8.10'}android { composeOptions { kotlinCompilerExtensionVersion = "1.4.3" }}3 Comments
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 Comments
I tried many ways to solve this same prolem but didnt workI 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 Comment
I solved the problem by changing the Kotlin class path dependency in the rootbuild.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"Comments
edit app/build.gradle file in flutter
dependencies { (...) // Fix Duplicate class implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))}Comments
Add the below line in yourbuild.gradle(Module:app)
dependencies {(...)// Fix Duplicate classimplementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))}This is becausekotlin-stdlib-jdk7 andkotlin-stdlib-jdk8 are older dependencies that should be replaced bykotlin-stdlib. However, other libraries may still declare a dependency on them, which needs to be replaced with a dependency onkotlin-stdlib.
Comments
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 Comments
I was usingorg.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.Usingorg.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 componentsimplementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.0"Comments
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.
Comments
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.
Comments
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...
Comments
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 Comments
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.
Comments
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 version1.8.0, the latest one1.8.10 not compatible with compose1.4.0 So I used,
id 'org.jetbrains.kotlin.android' version '1.8.0' apply falseThen, adjust thecomposeOptions 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.
Comments
lifecycle-viewmodel-ktx-2.6.1down
lifecycle-viewmodel-ktx-2.5.1I managed to get it working by lowering the dependency values.
Comments
I fixed it by making Compose Compiler and JetBrains Kotlin plugins compatible
First, make sure are you usingorg.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 updatebuild.gradle(app):
https://developer.android.com/jetpack/androidx/releases/compose-kotlin#pre-release_kotlin_compatibility
android { ... composeOptions { kotlinCompilerExtensionVersion '1.4.7' }}Comments
add this inside yourdependencies, it will solve theerror.
dependencies { (...) // Fix Duplicate class implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))}2 Comments
Workaround for earlier KGP versions now is:
Fileapp/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") } }}Comments
According to the release notes of Kotlin 1.8.0 (https://kotlinlang.org/docs/whatsnew18.html#updated-jvm-compilation-target), you shouldn't specifykotlin-stdlib-jdk7 norkotlin-stdlib-jdk8 as dependencies anymore and, instead, just usekotlin-stdlib.
Comments
I ran into this issue today and I fixed it by upgrading bothKotlinstd-lib for android and thestd-lib itself.Also it's worth mentioning that if you're using compose, you have upgrade thekotlinCompilerExtensionVersion
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}Comments
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 Comment
2.7.2 to2.5.3 and it worked. But why is the new version not working? I don't know...If I update kotlin version to 1.8.0 then it forces me to useview 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 solveduplicate class issues though it is a temporary solution.Here my AGP version is7.4.1 and Gradle version is7.5
Comments
The issue may be easely fixed by one line only:
dependencies {..... implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0'}Comments
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 whenandroid studio was added in my Gradle modulesktx:+ dependency.
1 Comment
'1.1.0-alpha04'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 Fromplugins {....id 'org.jetbrains.kotlin.android' version '1.7.10' apply false}Toplugins {....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 elseComments
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
Comments
Explore related questions
See similar questions with these tags.



































