英文:
I get a Duplicate Class error when running my Android project
问题
I am getting a Duplicate class
error when running my Android project. It is giving the following error:
Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in
modules kotlin-stdlib-1.8.21
(org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and
kotlin-stdlib-jdk8-1.7.20
(org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20) Duplicate class found
My build.gradle code is this:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
apply plugin:'kotlin-parcelize'
android {
namespace 'com.example.quitanda'
compileSdk 33
defaultConfig {
applicationId "com.example.quitanda"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.2'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
// Minha implementação
implementation 'androidx.appcompat:appcompat:1.6.1'
//2.6.0-alpha09
implementation "androidx.navigation:navigation-compose:2.6.0-beta01"
//def moshiVersion = "1.10.0"
//implementation "com.squareup.moshi:moshi:$moshiVersion"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0-RC1'
//1.0.0-alpha18
implementation "androidx.paging:paging-compose:1.0.0-alpha19"
//implementation "com.google.accompanist:accompanist-swiperefresh:0.14.0"
implementation "com.google.accompanist:accompanist-pager:0.21.3-beta"
implementation "io.coil-kt:coil-compose:2.2.2"
//1.4.2
implementation "androidx.compose.material:material-icons-extended:1.4.3"
implementation "androidx.datastore:datastore:1.0.0"
implementation "androidx.datastore:datastore-preferences:1.0.0"
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.google.maps.android:maps-compose:2.11.0'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
}
I tried excluding the duplicate classes using the code below:
apply plugin: 'org.jetbrains.kotlin'
configurations {
all {
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib-jdk8"
}
}
I added the above code, but then I got this error:
Plugin with id 'org.jetbrains.kotlin' not found
When I remove the apply it gives the error:
Duplicate class found
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations$ReflectSdkVersion found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.DirectoryEntriesReader found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.ExperimentalPathApi found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org
<details>
<summary>英文:</summary>
I am getting a `Duplicate class` error when running my Android project. It is giving the following error:
Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in
modules kotlin-stdlib-1.8.21
(org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and
kotlin-stdlib-jdk8-1.7.20
(org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20) Duplicate class found
My build.gradle code is this:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
apply plugin:'kotlin-parcelize'
android {
namespace 'com.example.quitanda'
compileSdk 33
defaultConfig {
applicationId "com.example.quitanda"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.2'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
// Minha implementação
implementation 'androidx.appcompat:appcompat:1.6.1'
//2.6.0-alpha09
implementation "androidx.navigation:navigation-compose:2.6.0-beta01"
//def moshiVersion = "1.10.0"
//implementation "com.squareup.moshi:moshi:$moshiVersion"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0-RC1'
//1.0.0-alpha18
implementation "androidx.paging:paging-compose:1.0.0-alpha19"
//implementation "com.google.accompanist:accompanist-swiperefresh:0.14.0"
implementation "com.google.accompanist:accompanist-pager:0.21.3-beta"
implementation "io.coil-kt:coil-compose:2.2.2"
//1.4.2
implementation "androidx.compose.material:material-icons-extended:1.4.3"
implementation "androidx.datastore:datastore:1.0.0"
implementation "androidx.datastore:datastore-preferences:1.0.0"
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.google.maps.android:maps-compose:2.11.0'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
}
I tried excluding the duplicate classes using the code below:
apply plugin: 'org.jetbrains.kotlin'
configurations {
all {
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib-jdk8"
}
}
I added the above code, but then I got this error:
Plugin with id 'org.jetbrains.kotlin' not found
When I remove the apply it gives the error:
```Duplicate class found
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations$ReflectSdkVersion found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.DirectoryEntriesReader found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.ExperimentalPathApi found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.FileVisitorBuilder found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.FileVisitorBuilderImpl found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.FileVisitorImpl found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.LinkFollowing found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathNode found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathRelativizer found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathTreeWalk found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathTreeWalk$bfsIterator$1 found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathTreeWalk$dfsIterator$1 found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathTreeWalkKt found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathWalkOption found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathsKt found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathsKt__PathReadWriteKt found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.io.path.PathsKt__PathUtilsKt found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
Duplicate class kotlin.jdk7.AutoCloseableKt found in modules kotlin-stdlib-1.8.21 (org.jetbrains.kotlin:kotlin-stdlib:1.8.21) and kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)
[SOLVED]
My solution was to add below command to 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")
}
}
}
答案1
得分: 2
将以下内容添加到我的 build.gradle(模块:app)的末尾解决了此问题:
dependencies {
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
because("kotlin-stdlib-jdk7 现在是 kotlin-stdlib 的一部分")
}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
because("kotlin-stdlib-jdk8 现在是 kotlin-stdlib 的一部分")
}
}
}
英文:
Adding this at the end to my build.graddle (Module:app) solved it:
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")
}
}
答案2
得分: 0
错误意味着在您添加的两个或多个依赖中使用了相同的类。Android Studio 不知道在运行应用程序时要使用哪个类。因此,会引发错误。在您的情况下,类 kotlin.collections.jdk8.CollectionsJDK8Kt 在两个不同的 Kotlin 版本中被使用。要解决这个问题:
apply plugin: 'com.package.domain'
android {
...
buildTypes {
...
}
configurations {
all {
exclude group: "com.package.domain", module: "YOUR_MODULE_NAME"
}
}
}
用冲突类的相应值替换 com.package.domain
和 YOUR_MODULE_NAME
。
在您的情况下,group 将为 org.jetbrains.kotlin.android
,module 将为 kotlin-stdlib-jdk8
。这将排除其中一个 Kotlin 版本。
英文:
The error means that the same class used in two or more dependencies that you have added. Android Studio doesn’t know which class to use when running the app. So, the error is thrown. In your case, the class kotlin.collections.jdk8.CollectionsJDK8Kt is used in two different Kotlin versions. To solve it:
apply plugin: 'com.package.domain'
android {
...
buildTypes {
...
}
configurations {
all {
exclude group: "com.package.domain", module: "YOUR_MODULE_NAME"
}
}
}
Replace com.package.domain
and YOUR_MODULE_NAME
with the respective values of the conflicting classes.
In your case, the group would be org.jetbrains.kotlin.android
and module would be kotlin-stdlib-jdk8
. This will exclude one of the Kotlin versions.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论