7

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

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
Mohamed Ali
  • 103
  • 1
  • 2
  • 9

5 Answers5

14

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

AyTee
  • 489
  • 1
  • 8
  • 19
6

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'
}
Nistix
  • 723
  • 10
  • 7
  • This can break in runtime in case if moshipack actually calls something from `kotlin.reflect`. Better to update `moshipack` to a version that uses a more recent version of `kotlin-reflect` (e.g. 1.2 and higher) which doesn't have such conflict with a recent `kotlin-stdlib`. – Ilya Jun 26 '20 at 17:54
1

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

VAIBHAV NERLE
  • 322
  • 2
  • 12
0

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

Mohamed Ali
  • 103
  • 1
  • 2
  • 9
0

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.

heet kanabar
  • 212
  • 3
  • 12