50
votes

I am a beginner in Kotlin App Development. The following error is occurred when I tried to build the app -

e: C:/Users/Lenovo/.gradle/caches/transforms-2/files-2.1/32f0bb3e96b47cf79ece6482359b6ad2/jetified-kotlin-stdlib-jdk7-1.5.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: 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

enter image description here

Is it about updating the module? Then how to update it?

10
Can you show up your app and project build.gradleAnaniya Jemberu
In my case problem occurs with the Jetpack DataStore library. I removed it and rebuild. the problem removed, but don't able to know why this happens.!!!Zeeshan Akhtar

10 Answers

57
votes

for someone who is still looking for answer to this, here is the working solution for this problem. In your project level gradle file, just increase the ext.kotlin.version from whatever version you have, to '1.4.32' or whatever the latest version is available. Thanks

38
votes

Happened to me when updating from Kotlin 1.4.30 to 1.5.0. Seems to be some sort of Gradle caching issue. I was able to resolve it by updating Gradle from 6.7.1 to 6.9 (or any other version).

Just go to gradle-wrapper.properties and change this line from

distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-all.zip

to

distributionUrl=https://services.gradle.org/distributions/gradle-6.9-all.zip

16
votes

this Works:

your_project_name_folder\android\build.gradle

change version to this: ext.kotlin_version = '1.4.32'

(dart/flutter2.2/vs code)

4
votes

I updated kotlin versions to latest and it helped me.

Here

enter image description here

And fixed yellow prompt by Android Studio from this implementation "androidx.core:core-ktx:+" to this implementation "androidx.core:core-ktx:1.5.0"

enter image description here

4
votes

In my case Problem occurs when I upgrade androidx.core:core-ktx:1.3.1 to androidx.core:core-ktx:1.6.0

In release notes of this library mentioned that

Note: Core and Core-ktx Version 1.5.0 and above versions will only compile against the Android 11 SDK.**

https://developer.android.com/jetpack/androidx/releases/core#core_and_core-ktx_version_150_2

Solution: downgrade your library below to 1.5.0 and sync. if this is the case then the error will be gone.

1
votes

For me I had to update Android Studio to 4.2.2. Update gradle to 7.0. As well as perform the kotlin migration(might not have had anything to do with it). And lastly updated my ext.kotlin_version to 1.5.20. After all of that I invalidated caches and restarted Android studio.

0
votes

Recently my Jenkins build was failing with similar lines of error messages. And tried below to mitigate the issue:

Possible Reasons:

  1. Offline work mode is ON in the Gradle settings options which failing some dependencies while compilation
  2. Updated Android Studio stop supporting older Kotlin version. (very less likely)
  3. Incompatible Gradle distribution version wrt Gradle plugin (com.android.tools.build:gradle)
  4. Gradle caching issue
  5. From the error statement it seems the module was compiled with an incompatible version of Kotlin. For example you have added some sdk dependency in your project which was compiled with different (incompatible) kotlin version than your app is using.

Possible Solutions:

  1. Offline work mode should be turned OFF in the Gradle settings options,

  2. Restart the Kotlin plugin and restart the Android Studio

  3. Remove/upgrade the newly added sdk dependency from your project

  4. Validate if the Gradle distribution version is compatible with Android grade plugin here

  5. Change the “distributionUrl” url according to latest version (or higher version) in gradle-wrapper.properties
    Command Line (better way): `./gradlew wrapper --gradle-version X.Y.Z'.

    Manual: change the distributionUrl property in the Wrapper’s gradle-wrapper.properties file.

    find the latest version of Gradle that is going to use in gradle-wrapper.properties from here

  6. Upgrade the Kotlin version: The ext.kotlin.version from whatever version you have, to '1.4.32' or whatever the latest version is available here

Please note there could be many possible reason and so that the solution. In My case the combination of solution#5 & 6 worked well.

0
votes

Go to app level build.gradle file and check the lineimplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" and see the suggested kotlin version change it in the class level build.gradle file and change ext.kotlin_version = "x.x.xx" to the one which was suggested.

0
votes

I just updated everything to the latest version. And the latest mentioned by the android studio itself.

e.g

    ext.kotlin_version = '1.5.20'

    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha04"
    }

And

distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip

In gradle-wrapper.properties

-1
votes

If this error happens during the build then upgrading the kotlin version is proven fix.

But it is not due to android version or kotlin version gradle version compatibility.

I created a brand new blank project in latest android studio(4.2.1) with default settings in kotlin 1.3.72 and it builds perfectly.

So, the problem may be due to some other libraries or something else.