Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

different kotlin versions in android project

I can't figure out what problem I can get if I have different Kotlin versions in the project and in the dependencies of that project.

Option 1:

  • the project include Kotlin 1.3.72
  • some libraries (okhttp for example) include Kotlin 1.4.10. (We now use Kotlin 1.4.x functional interfaces for Authenticator, Interceptor, and others.)

Option 2:

  • the project include Kotlin 1.4.0
  • some libraries include Kotlin 1.3.71

In option 2 I get next warning:
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath: /.gradle/caches/transforms-2/files-2.1/ab41544fa06f7b55dec847efe3b9899c/jetified-kotlin-stdlib-jdk7-1.3.71.jar (version 1.3) .gradle/caches/transforms-2/files-2.1/a4c6c3b949eb40b555dea1468ae75f87/jetified-kotlin-stdlib-1.4.10.jar (version 1.4) .gradle/caches/transforms-2/files-2.1/f98f62bf33e752598311020043618780/jetified-kotlin-stdlib-common-1.4.10.jar (version 1.4)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

like image 344
Dmitry Avatar asked Oct 07 '20 07:10

Dmitry


People also ask

How do I change project Kotlin version?

Go to Intellij Preferences -> Build, Execution, Deployment -> Kotlin Compiler. Update Language version and Api version to the one you wish. This should be the accepted answer.

What Kotlin version should I use?

If you already use IntelliJ IDEA or Android Studio, your IDE will suggest updating Kotlin to 1.5. 20 automatically.

How do I know what version of Kotlin project I have?

IntelliJ IDEA and Android Studio suggest updating to a new release once it is out. When you accept the suggestion, it automatically updates the Kotlin plugin to the new version. You can check the Kotlin version in Tools | Kotlin | Configure Kotlin Plugin Updates.

In which file do we change the version of Kotlin in Android app?

Select your module in the Project window, and then select File > New, select any Android template, and then choose Kotlin as the Source language.


3 Answers

/.gradle/caches/transforms-2/files-2.1/ab41544fa06f7b55dec847efe3b9899c/jetified-kotlin-stdlib-jdk7-1.3.71.jar (version 1.3)

this can be resolved with including this in your app build.gradle dependencies:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Also, I have personally learned to add the following dependencies to avoid these errors:

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

Also, make sure you have ext.kotlin_version = "1.4.10" in your project build.gradle

like image 185
Vitaliy-T Avatar answered Oct 17 '22 00:10

Vitaliy-T


What problems you can get? When the differences are not just in the minor release version (like 1.3.70 / 1.3.72) but are between a 1.3.x and a 1.4.x release, you risk e.g. that one library will use a function that has changed its signature in the new release, and so there will be a runtime error. This does not necessarily happen, but it can happen (unless you know for certain that your dependency libraries do no use any functions that have changed).

like image 22
H Ystad Avatar answered Oct 17 '22 00:10

H Ystad


If your project target Java 8 so just include the dependency on that Java version

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

Follow the same rule if you target Java 6 or 7.

You clarify more about that in the post https://medium.com/@mbonnin/the-different-kotlin-stdlibs-explained-83d7c6bf293

like image 1
Filipe Bezerra de Sousa Avatar answered Oct 17 '22 00:10

Filipe Bezerra de Sousa