Mohamed Ali
Mohamed Ali

Reputation: 103

Duplicate class kotlin classes kotlin version 1.3.70

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

Upvotes: 7

Views: 17571

Answers (5)

heet kanabar
heet kanabar

Reputation: 300

So I finally figured it out and here's how :-

So the main problem is you have injected 2 dependency of same class. Here he used 2 dependency for Kotlin which conflict in runtime to fix that you have to check which dependency is duplicated. (It is most case scenario. It can be with any other dependency i.e. Hilt)

  1. Go to File > Project structure > Dependencies

  2. Check which dependency are repeating. In this case it will have (androidx.core:core:1.8.0) and (androidx.core:core:+)

as you can see there are 2 dependency with same classes version 1.8.0 will have all the class which core:+ will have and this is causing a error.

  1. Now delete (androidx.core:core:+) and hit Apply and sync project.

Now you should be good to go. here is structure after changing dependency.

Note:- This method will show all the android dependency which you might be not included but you will see all the dependency which any app has. Please remove the dependency who are you familiar with do not remove any dependency without any proper knowledge.

Upvotes: 0

VAIBHAV NERLE
VAIBHAV NERLE

Reputation: 322

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

Upvotes: 1

Nistix
Nistix

Reputation: 753

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'
}

Upvotes: 6

AyTee
AyTee

Reputation: 519

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

Upvotes: 14

Mohamed Ali
Mohamed Ali

Reputation: 103

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

Upvotes: 0

Related Questions