452

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, 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'
Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
askedJan 27, 2023 at 20:28
midnighthowlers's user avatar
6
  • 80
    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/4355877CommentedMar 6, 2023 at 16:11
  • 3
    @Mick Thank you so much for the tip, a lifesaver for those shunning Kotlin.CommentedMar 28, 2023 at 15:58
  • @midnighthowlers Try this solution once:stackoverflow.com/a/75974885/16765223CommentedApr 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/4833705CommentedJul 26, 2023 at 10:37
  • Why do we need 62 answers to this question?CommentedDec 3, 2023 at 3:31

70 Answers70

339

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}
Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answeredJan 28, 2023 at 13:46
Jurpro's user avatar
Sign up to request clarification or add additional context in comments.

14 Comments

Note: After updating to '1.8.0', do not forget to update kotlinCompilerExtensionVersion as '1.4.0' .
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 (orsuppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
Question as a noob: Where should I add the above?
@PrasannjeetSingh It isbuild.gradle file
@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)
|
256

Seethis 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)

Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answeredJan 31, 2023 at 14:19
David Fraser's user avatar

11 Comments

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?
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
@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).
It works now. You can also find information inyoutrack.jetbrains.com.
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?
|
192

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"))   ... ... ...}
Eric Aya's user avatar
Eric Aya
70.2k36 gold badges190 silver badges266 bronze badges
answeredMar 13, 2023 at 8:48
Zakaria Bin Abdur Rouf's user avatar

10 Comments

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/…
This fixed my issue as well
This also worked for me. I think this is sufficient if you are not using Kotlin directly.
Fixed it for me as well: project is pure Java (no Kotlin).
This should be marked as correct answer (y)
|
61

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'
Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answeredFeb 25, 2023 at 18:48
Prashanth's user avatar

2 Comments

I'm not using kotlin in a project and this solved my problem.
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.
40

Upgrade kotlin android plugin and kotlin compiler

plugins {    id 'org.jetbrains.kotlin.android' version '1.8.10'}android {    composeOptions {        kotlinCompilerExtensionVersion = "1.4.3"    }}
answeredFeb 23, 2023 at 20:58
Tran Chien's user avatar

3 Comments

This worked for me. Although I only needed to upgrade the kotlin android plugin. Thanks!
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.
same here; adding "implementation (platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))" fixed the issue, EVEN if I have no kotlin code.
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"))}
alea's user avatar
alea
1,0991 gold badge15 silver badges19 bronze badges
answeredMay 19, 2023 at 11:30
Mada AFLAK's user avatar

4 Comments

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
Can anyone please elaborate on why this works? I have no clue how it fixed my issue of duplicate classes.
the only fix that worked for me is this, thanks!
@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.
30

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.

answeredMay 20, 2023 at 17:01
Humayun MHA's user avatar

1 Comment

Thanks a lot. This saved the day. I recommend everyone to try this first.
27

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"
Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answeredJan 28, 2023 at 14:02
Mohamed Medhat's user avatar

Comments

19

edit app/build.gradle file in flutter

dependencies {    (...)    // Fix Duplicate class    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))}
answeredAug 10, 2023 at 4:41
user22367497's user avatar

Comments

18

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.

answeredAug 15, 2023 at 7:37
Arbaz Alam's user avatar

Comments

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

Attif's user avatar
Attif
1,15013 silver badges17 bronze badges
answeredJul 22, 2023 at 7:59
Harsh kumar's user avatar

2 Comments

If you have a new question, please ask it by clicking theAsk Question button. Include a link to this question if it helps provide context. -From Review
For me, this line works as expected, in dependencies from the build.gradle (Module: app) add: implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0")) I find here:github.com/fluttercommunity/plus_plugins/issues/2018
13

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"
answeredMar 7, 2023 at 16:44
patel dhruval's user avatar

Comments

12

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.

Procrastinator's user avatar
Procrastinator
2,67445 gold badges31 silver badges37 bronze badges
answeredJun 28, 2024 at 9:41
Kalyan Chandra's user avatar

Comments

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.

IgorGanapolsky's user avatar
IgorGanapolsky
26.9k23 gold badges121 silver badges151 bronze badges
answeredFeb 1, 2023 at 12:31
riggaroo's user avatar

Comments

9

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...

answeredMay 21, 2023 at 8:06
Ashfaque's user avatar

Comments

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.

Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answeredJun 6, 2023 at 15:50
Anton Miroshnyk's user avatar

2 Comments

This solution literally fixed the problem. Thanks!
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.
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.

answeredMay 28, 2024 at 17:44
Arpit Verma's user avatar

Comments

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 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 false

Then, 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.

answeredApr 6, 2023 at 18:20
Ashana.Jackol's user avatar

Comments

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.

answeredApr 19, 2023 at 12:27
ΓDΛ's user avatar

Comments

6

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'  }}
answeredMay 14, 2023 at 12:56
Fakhriddin Umarov's user avatar

Comments

6

add this inside yourdependencies, it will solve theerror.

dependencies {    (...)    // Fix Duplicate class    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))}
answeredSep 12, 2023 at 7:57
safXcode's user avatar

2 Comments

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.
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'. ```
6

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")        }    }}
Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answeredMay 6, 2023 at 8:30
Alexander Dyagel's user avatar

Comments

4

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.

answeredJan 28, 2023 at 4:03
Luiz Rodrigo's user avatar

Comments

4

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}
answeredMar 20, 2023 at 22:17
AouledIssa's user avatar

Comments

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.

answeredJun 13, 2023 at 7:11
MartijndeM's user avatar

1 Comment

I had the same issue. Downgraded from2.7.2 to2.5.3 and it worked. But why is the new version not working? I don't know...
4

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

answeredJun 26, 2023 at 4:02
Rasel's user avatar

Comments

4

The issue may be easely fixed by one line only:

dependencies {.....    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0'}
answeredJul 31, 2023 at 21:18
Anatolii Shuba's user avatar

Comments

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 whenandroid studio was added in my Gradle modulesktx:+ dependency.

Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answeredJan 29, 2023 at 16:00
Gregory's user avatar

1 Comment

Same here. Had to downgrade material3 version to'1.1.0-alpha04'
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 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 else
Roshin Raphel's user avatar
Roshin Raphel
2,7195 gold badges28 silver badges43 bronze badges
answeredMar 5, 2023 at 11:42
Mawuli's user avatar

Comments

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

answeredApr 11, 2023 at 16:53
Fortran's user avatar

Comments

Protected question. To answer this question, you need to have at least 10 reputation on this site (not counting theassociation bonus). The reputation requirement helps protect this question from spam and non-answer activity.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.