Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I have different versions of Kotlin JARs in the classpath?

I decided to add a couple Kotlin files to an existing Java Android project in AS 3.0.

Once I added Kotlin files, I let the assistant add the appropriate lines to my build.gradle files, in particular:

project build.gradle

buildscript {
    ext.kotlin_version = '1.2.21'
    //...
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

app build.gradle

// top of file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
//....
dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Unfortunately all builds now produce this warning:

Warning:Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
/Users/sddsfsd/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.21/88bfff5aa470143a83b0bc5ec00c0be8cabd7cad/kotlin-stdlib-jdk7-1.2.21.jar (version 1.2)
/Applications/Android Studio.app/Contents/gradle/m2repository/org/jetbrains/kotlin/kotlin-stdlib-jre7/1.1.51/kotlin-stdlib-jre7-1.1.51.jar (version 1.1)
/Users/sddsfsd/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.21/d64187eb2d9d1521be3421aa8c6774a8625cdde8/kotlin-stdlib-1.2.21.jar (version 1.2)

Why does Android Studio have its own older version of Kotlin in the classpath? How do I remove it?

like image 861
ray Avatar asked Feb 02 '18 14:02

ray


People also ask

How do I fix the module was compiled with an incompatible version of Kotlin the binary version of its metadata is 1.5 1 Expected version is 1.1 16?

The solution is to change the kotlin version in build. gradle to 1.5. 0 and change the Gradle version in the project structure to 6.9.

What is kotlin Stdlib?

The Kotlin Standard Library provides living essentials for everyday work with Kotlin. These include: Higher-order functions implementing idiomatic patterns (let, apply, use, synchronized, etc). Extension functions providing querying operations for collections (eager) and sequences (lazy).


1 Answers

Why do I have different versions of Kotlin JARs in the classpath?

You have different versions because some of your dependencies depend on Kotlin 1.1 version.

Why does Android Studio have its own older version of Kotlin in the classpath? How do I remove it?

Updating your dependencies like I explained here in a related question about renamed stdlib-jre7 and already explained here for conflictive dependencies that have not been renamed.

Kotlin reference - binary compatibility warnings:

Runtime JAR files in the classpath should have the same version.

Some runtime JAR files in the classpath have an incompatible version.

Consider removing them from the classpath.

This means that you have a dependency on libraries of different versions, for example the 1.1 standard library and the 1.0 reflection library.

To prevent subtle errors at runtime, we recommend you to use the same version of all Kotlin libraries. In this case, consider adding an explicit dependency.

In your case, the indirect dependency was renamed and you need to update the library that uses it:

Find conflictive dependencies via command, or build tab since AS 3.1

./gradlew -q dependencies app:dependencies --configuration variantDebugCompileClasspath

enter image description here

enter image description here

enter image description here

enter image description here

In the related question, the warning was removed updating Realm version to 4.3.2.

Note: I checked my path and I also have outdated dependencies there but it's ok if you don't use it.

like image 94
albodelu Avatar answered Oct 12 '22 02:10

albodelu