Duplicate class kotlin classes kotlin version 1.3.70

Viewed 8616

Error while adding MoshiPack Library in Kotlin latest version 1.3.70 to gradle.build application Moshi pack

implementation 'com.daveanthonythomas.moshipack:moshipack:1.0.1'

Error Message

Duplicate class kotlin.reflect.KClasses found in modules jetified-kotlin-reflect-1.1.1.jar (org.jetbrains.kotlin:kotlin-reflect:1.1.1) and jetified-kotlin-stdlib-1.3.70.jar (org.jetbrains.kotlin:kotlin-stdlib:1.3.70)

Any suggestions how to solve this issue or any other library I can use in Kotlin so I can use Message Pack.

Thanks in advance

4 Answers

Try to add this to your dependencies:

    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

and make sure you specified your Android NDK location under File>Project Structure...>SDK Location

Starting Kotlin 1.3.70 some basic useful members on KClass included in Kotlin standard library (they were in a kotlin-reflect before).

See "Working with KClass" in https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-3-70-released/

In your case MoshiPack adds a kotlin-reflect library that conflicts with standard library.

You should exclude transitive dependency to resolve the conflict.

If you use KotlinDSL, in build.gradle.kts:

implementation ("com.daveanthonythomas.moshipack:moshipack:1.0.1") {
    exclude(group = "org.jetbrains.kotlin", module = "kotlin-reflect")
}

If you use Groovy, in build.gradle:

implementation ('com.daveanthonythomas.moshipack:moshipack:1.0.1') {
    exclude group: 'org.jetbrains.kotlin', module: 'kotlin-reflect'
}

I tried this and it worked implementation "org.jetbrains.kotlin:kotlin-reflect:1.4.10"

i think the only way to solve it , to go back to kotlin version 1.3.61 , so remove 1.3.70 and use 1.3.61

Related