"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"

AndroidAndroid StudioKotlin

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

For someone who is still looking for answer to this, here is the working solution for this problem. In your project level open build.gradle file, increase the ext.kotlin_version from whatever current version that you have like 1.5.0, to the latest stable version 1.6.0 (Whatever is latest at that time). Thanks

You can get latest version from here:

https://kotlinlang.org/docs/releases.html#release-details

Solution 2 - Android

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

Solution 3 - Android

I was facing same issue in IntelliJ IDEA Version: Ultimate 2019.3

Issue occurred when I changed jar version multiple times and click on debug button to run the application.

Issue fixed when i used below steps:

Open IntelliJ >> Build >> Rebuild Project.

After that I run the application again and it worked for me.

Solution 4 - Android

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

Solution 5 - Android

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.

Solution 6 - Android

Go project build.gradle and update "ext.kotlin_version = 1.5.0"

Solution 7 - Android

I had to update the Kotlin Gradle plugin to match Kotlin standard library. In {project}/build.gradle.

buildscript {
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:{kotlin version}"
    }
}

I also removed callout to dependency on standard library as that is now baked into Gradle based on my dependencies, though this is less directly related. Delete this line in {project}/{app module}/build.gradle:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:{kotlin version}"
    ...
}

Reference: Exception Error blog post

Solution 8 - Android

This happened to me today when I added a new project to an existing big project with latest Android Studio, but I could not find the above-mentioned ext.kotlin_version anywhere to fix it. Anyway, after comparing the build.gradle file with the one from a new standalone project that works fine, I found out that changing 1.6.0 in here:

dependencies {
    implementation 'androidx.core:core-ktx:1.6.0'
    ...
}

to 1.3.2 fixes the issue:

dependencies {

    implementation 'androidx.core:core-ktx:1.3.2'
    ...
}

Solution 9 - Android

After putting off dealing with this for almost a year, the solution was very easy to implement after finding.

I had to replace the deprecated jcenter() with mavenCentral() in my build.gradle file in the "repositories" section.

Solution 10 - Android

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.

Solution 11 - Android

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.

Solution 12 - Android

For me updating the kotlin plugin, kotlin version and distribution url worked Kotlin Plugin

kotlin_version = '1.4.32'

AND

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

Solution 13 - Android

If anyone face this issue in future kindly check the following versions of dependencies and classpath

ext.kotlin_version = "1.4.32"

> Esure that the gradle-wrapper.properties has the compitable > distribution url with your kotlin version

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

App level build.gradle check

implementation 'androidx.core:core-ktx:1.5.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'

Note: Check these dependencies it might be causing the issue, In my case coroutines-android was using 1.6.0-RC2 which is very latest version of coroutine then I checked the github releases and got the right version for my project gradle configuration

You can check the kotlinx-coroutines-android version from github releases section

https://github.com/Kotlin/kotlinx.coroutines/releases

You can also check the core-ktx version from developer.android.com

https://developer.android.com/jetpack/androidx/releases/core

Solution 14 - Android

I had this problem yesterday. 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.

ext.kotlinVersion = '1.5.0'

enter image description here

Solution 15 - Android

After 4 hours testing different versions of Kotlin being my project NOT A KOTLIN PROJECT this solution solved my life:

Go to Intellij and disable the Kotlin plugin. Then compile everything again.

Solution 16 - Android

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

Solution 17 - Android

Create new project again helped for me :| And if you need to fix another project you may try copy android/build.gradle and android/app/build.gradle from new flutter project template to an other project.

Solution 18 - Android

Finally, the working solution is that we need to upgrade your kotlin version from your project build.gradle file.

Solution 19 - Android

Uncleared Gradle cache could also be an issue. I faced this same issue and resolved it by deleting .gradle/caches directory in the root folder.

Steps:

  • Delete caches directory in the location, [RootFolder]/.gradle/caches
  • Rebuild project

Refer: https://stackoverflow.com/a/23029580/10506244

Solution 20 - Android

In your build.gradle file, increase the ext.kotlin_version to 1.6.0

ext.kotlin_version = '1.6.0'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSaheel SapovadiaView Question on Stackoverflow
Solution 1 - AndroidAli RazaView Answer on Stackoverflow
Solution 2 - AndroidSir CodesalotView Answer on Stackoverflow
Solution 3 - AndroidVed SinghView Answer on Stackoverflow
Solution 4 - AndroidDyno CrisView Answer on Stackoverflow
Solution 5 - AndroidZeeshan AkhtarView Answer on Stackoverflow
Solution 6 - AndroidEray HamurluView Answer on Stackoverflow
Solution 7 - AndroidmethodsignatureView Answer on Stackoverflow
Solution 8 - AndroidDatow KingView Answer on Stackoverflow
Solution 9 - AndroidTor BrickView Answer on Stackoverflow
Solution 10 - AndroidAkkiView Answer on Stackoverflow
Solution 11 - AndroidChris LeeView Answer on Stackoverflow
Solution 12 - AndroidheathkevView Answer on Stackoverflow
Solution 13 - AndroidFazal HussainView Answer on Stackoverflow
Solution 14 - AndroidAR HakimView Answer on Stackoverflow
Solution 15 - AndroidCharly MonzonView Answer on Stackoverflow
Solution 16 - AndroidshehzyView Answer on Stackoverflow
Solution 17 - AndroidКobakView Answer on Stackoverflow
Solution 18 - Androidmainsh agrahariView Answer on Stackoverflow
Solution 19 - AndroidAlexView Answer on Stackoverflow
Solution 20 - AndroidYasser BenmmanView Answer on Stackoverflow