223

The following error occurs when I tried to build the app:

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

screenshot

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

Simon Forsberg
  • 13,086
  • 10
  • 64
  • 108
Saheel Sapovadia
  • 2,755
  • 3
  • 11
  • 22

36 Answers36

265

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

Ali Raza
  • 2,809
  • 1
  • 6
  • 9
  • 6
    It does work, but could you please tell me how it works. – Justin Jun 04 '21 at 02:30
  • 1
    From what I think, Sometimes, Android Studio stops supporting Kotlin Older versions, especially when your android studio is up to date. This is just my thinking, I also don't know the exact reason. But this solution works for sure everytime. – Ali Raza Jun 05 '21 at 10:37
  • 1
    In My case, this problem arose, when I updated some plugins in Android Studio. – Ali Raza Jun 05 '21 at 10:40
  • 5
    Yes changing the version of `gradle-6.7.1` to `gradle-6.9` in `gradle-wraper-properties` file and also changing the `ext.kotlin-version = '1.4.32'` resolve the issue. – Akki Jangir Jul 25 '21 at 18:47
  • 5
    Setting to `1.5.31` in a `flutter@2.5.2` project fixed it for me. – Nick Ribal Oct 08 '21 at 15:19
  • With `Kotlin v1.6.0`, if you are using `Moshi` library you need to update it to `v1.13.0`. Also with `Moshi v1.13.0`, you need to update `Gradle` and `AGP` to `v7.+` or disable Jetifier for `Moshi` library as a workaround! See this https://issuetracker.google.com/issues/184622491 – YUSMLE Dec 14 '21 at 15:43
  • ```./gradlew cleanBuildCache``` – Saugat Rai Feb 21 '22 at 07:17
  • This works if you use `kotlin_version` property somewhere for version – wMaN Feb 22 '22 at 08:28
  • in my case latest version 1.6.10 is not work, but 1.6.0 is works fine. – 9Dragons Mar 30 '22 at 23:36
  • 1
    This dependencies type in flutter is a mood killer – zmeul Apr 21 '22 at 10:22
  • 3
    This did not solve my problem. What worked for me was - I got this error, when I was adding another library released later than the kotlin library I was using. So when I replaced the added library with a version older than the kotlin version, my problem was resolved. Hope this helps. – truespan Jun 20 '22 at 06:50
  • I have this error: Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2. What should I do? – CodeBy Dec 20 '22 at 19:48
  • also I have `dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"`, do I need change it to 1.6.0? – CodeBy Dec 20 '22 at 20:07
  • @AliRaza In my case (an Android Studio React Native project) the variable turned out to be called `kotlinVersion`, not `kotlin_version` – rkok Jan 28 '23 at 05:03
  • This solution does not work with React Native. Some 3rd party libraries are not able to use the latest Kotlin, therefore, the app does not build or crashes on open – Lenka Pitonakova Jul 03 '23 at 15:03
68

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

Sir Codesalot
  • 7,045
  • 2
  • 50
  • 56
  • 13
    Don't do this. Just follow Ali Raza's answer. – Kishan Solanki Jul 28 '21 at 16:01
  • 11
    @KishanSolanki could you please explain why? Ali Raza's answer didn't help me! – Sir Codesalot Jul 29 '21 at 07:23
  • 1
    Ali's answer didn't work for me either error remained the same – marchinram Oct 19 '21 at 16:32
  • Many answers and comments are very specific to versions that are now outdated. A more generic answer would have been more helpful. – Ingo Steinke Apr 23 '22 at 09:23
  • I just added a new version in android/build.gradle file. In fact, if you get kotlin version error, it will take you to kotlin website, you can copy the version from there and put in android/build.gradle file. But sometimes you may need to get correct version from dependencies { classpath 'com.android.tools.build:gradle:7.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } If you hover on it, it will tell you the correct one and put it there – dylan Aug 23 '22 at 07:07
43

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.

Ved Singh
  • 705
  • 9
  • 4
20

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

Dyno Cris
  • 1,823
  • 1
  • 11
  • 20
12

In my case, I don't have a buildScript block or ext.kotlin_version in my ProjectRoot/build.gradle. Instead, there is a plugins block which describe my kotlin version.

plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.5.30' apply false
}

Change org.jetbrains.kotlin.android to 1.7.10, like:

plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

This finally get worked, hope to help someone.

Penut Chen
  • 121
  • 1
  • 3
9

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

methodsignature
  • 4,152
  • 2
  • 20
  • 21
8

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Zeeshan Akhtar
  • 441
  • 1
  • 4
  • 9
8

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'
    ...
}
Datow King
  • 161
  • 5
  • 11
6

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

Eray Hamurlu
  • 657
  • 7
  • 9
5

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
  • Do Invalidate Caches And Restart
  • Rebuild project

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

Toshal Agrawal
  • 173
  • 2
  • 7
Alex
  • 448
  • 7
  • 14
  • This did not work for me. After running it, I got another message about cache files no longer existing causing me to have to kill all running gradle instances with `pkill -f gradle`. After that, it went back to the original error message that the OP described. – rkok Jan 28 '23 at 05:01
5

First, we need to know where the conflict comes from.

The binary version 1.5.1 isn't the version of kotlin-stdlib used which can be known by examining the dependency tree. In my case, I was using androidx.core:core-ktx:1.6.0 which depends on org.jetbrains.kotlin:kotlin-stdlib:1.5.10

The expected version depends on the version of kotlin-gradle-plugin used in build.gradle project file.

So in my case, there was incompatibility between androidx.core:core-ktx and kotlin-gradle-plugin version. To resolve the conflict, I had two options. Either upgrade KGP or downgrade ktx.

In build.gradle (Project)

ext.kotlin_version = '1.3.40'     // not compatible with ktx:1.6.0
//  ext.kotlin_version = '1.4.31' // upgrading KGP fixes the issue
dependencies {
    classpath 'com.android.tools.build:gradle:3.5.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

In build.gradle (Module)

//  implementation "androidx.core:core-ktx:1.2.0" // downgrading ktx fixes the issue
implementation "androidx.core:core-ktx:1.6.0"     // not compatible with kotlin_version = '1.3.40'

In gradle-wrapper.properties

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

The rule here is to choose a ktx version whose release date is close to the release date of KGP. Links of both can be found below.

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

https://developer.android.com/studio/releases

https://developer.android.com/studio/releases/past-releases

https://developer.android.com/studio/releases/gradle-plugin

Hasan El-Hefnawy
  • 1,249
  • 1
  • 14
  • 20
5

The issue is happening for RN since 4th Nov 2022, Please refer below link for resolution. https://github.com/facebook/react-native/issues/35210

Anupam Chaplot
  • 1,134
  • 1
  • 9
  • 22
  • Link-only answers are discouraged because they become invalid when the link goes stale. Please copy the relevant portions over from the link (keeping it as additional reference). – geisterfurz007 Nov 17 '22 at 06:21
4

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

Fazal Hussain
  • 1,129
  • 12
  • 28
4

Inside android/build.gradle you need to change, or add, if you don't have:

dependencies {
  ...
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.1"
}
Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
2

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.

Akki
  • 775
  • 8
  • 19
2

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.

Tor Brick
  • 61
  • 3
2

you have juste rebuild your project:

  1. Open IntelliJ IDE
  2. Build
  3. Rebuild Project
Mounir bkr
  • 1,069
  • 6
  • 6
2

For library builders only. If you are creating a library using a newer version of Kotlin (eg. 1.8.10) and you want the library to work in projects with older versions of Kotlin (eg. 1.5.0) you need to set languageVersion and apiVersion:

compileKotlin {
    kotlinOptions {
        jvmTarget = '1.8'
        languageVersion = '1.4'
        apiVersion = '1.4'
    }
}

Keep in mind that the lower the version the fewer new Kotlin features you would be able to use in the source code of the library.

Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
1

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.

Salahuddin Ahmed
  • 4,854
  • 4
  • 14
  • 35
Chris Lee
  • 11
  • 1
1

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
heathkev
  • 153
  • 1
  • 10
1

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

AR Hakim
  • 106
  • 7
1

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

ext.kotlin_version = '1.6.0'
Yasser Benmman
  • 151
  • 2
  • 2
1

enter image description here

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.3.61, to the version 1.4.0 (Whatever is latest at that time). Thanks

Boken
  • 4,825
  • 10
  • 32
  • 42
1

in my case flutter project and Android studio IDE, kotlin version and gradle version was updated before.

file > Invaladate caches was worked like charm.

Sajjad
  • 2,593
  • 16
  • 26
1

For react native following solution works

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    // ...
}


allprojects {
    repositories {
+       exclusiveContent {
+           // We get React Native's Android binaries exclusively through npm,
+           // from a local Maven repo inside node_modules/react-native/.
+           // (The use of exclusiveContent prevents looking elsewhere like Maven Central
+           // and potentially getting a wrong version.)
+           filter {
+               includeGroup "com.facebook.react"
+           }
+           forRepository {
+               maven {
+                   // NOTE: if you are in a monorepo, you may have "$rootDir/../../../node_modules/react-native/android"
+                   url "$rootDir/../node_modules/react-native/android"
+               }
+           }
+       }
        // ...
    }
}
Rajesh N
  • 6,198
  • 2
  • 47
  • 58
0

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

shehzy
  • 2,215
  • 3
  • 25
  • 45
0

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.

0

The actual issue why this happens is because of incompatibility with the kotlin compiler version and the gradle plugin version

I spawned up a new Android project in Chipmunk and I find that the kotlin_version variable under the ext block is not there and build.gradle will hardcode the kotlin version

So change your build.gradle (global) like this

buildscript {
    ext {
        compose_version = '1.2.0-beta02'
        kotlin_version = '1.6.21'// This might be missing, you can add it
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.2.0"
    


// Do not hardcode this version, instead make it rely on the global variable you declared on top

//No
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20"
//Yes
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:2.38.1"
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


gtxtreme
  • 1,830
  • 1
  • 13
  • 25
0

Why simply upgrading the Kotlin version works: At least one of your dependencies was compiled against a version of Kotlin that is not backward compatible with the Kotlin version you are compiling your app or lib against.

Alternatively, you can find out which dependency it is and downgrade it. However, this can be limiting, so upgrade Kotlin versions if you can.

Remember the pain, and if you ever write a Kotlin library for others to use, consider being conservative in the Kotlin version you compile against, and list that version in the release notes.

actualadam
  • 31
  • 4
0

I just added a new version in android/build.gradle file. In fact, if you get kotlin version error, it will take you to kotlin website, you can copy the version from there and put in android/build.gradle file. But sometimes you may need to get correct version from

 dependencies {
    classpath 'com.android.tools.build:gradle:7.1.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} 

If you hover on it, it will tell you the correct one and put it there More here https://youtu.be/WTEPNOQdpB0

dylan
  • 319
  • 2
  • 4
0

Sometimes the conflict comes from the saved android studio project settings. Try to sync you project with Gradle files android studio shortcut.

from: File -> Sync Project with Gradle Files

This will rebuild the and download all the necessary files.

0

Upgrade the gradle plugin to the latest version. Android Studio v3.0+ will prompt to update gradle if there is an update available.

For a Flutter project, open the Android application in Android Studio and upgrade gradle as mentioned above.

Akbar ibrahim
  • 5,110
  • 3
  • 26
  • 23
0

I encountered this error while I ran the command react-native run-android after a few weeks to run my project. After running the command I noticed that react-native-0.71.0-rc.0-debug.aar is being downloaded. After digging around on internet I came across this issue on github and this comment which stated the cause of the problem. as the comment states:

  • typical react-native publish does not publish to maven central.
  • this RC was published to maven central and has a higher version than local
  • typical react-native build.gradle thus pulls the new (unwanted) RC version from maven central

This issue was the solution to the problem, what is says is that people at react-native have prepared patch fixes to which you can update your current version of react-native, to fix the problem. I was using react-native version 0.68.2 and I updated to the patch version of 0.68.5 as the issue stated and it fixed the problem.

Gandalf
  • 2,921
  • 5
  • 31
  • 44
-1

I've tried all the listed answers, none of them worked with the latest react native (0.70.6).

My solution was using android studio to run app on AVD or device first and make sure it installs all the required sdks or libraries. I am surprised since I went through the instructions before to bootstrap RN.

For me, it took some time to initial run on device or AVD. after doing so, running the app from cli worked for me.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
helloworld331
  • 166
  • 2
  • 9
-2

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.

Кobak
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 21 '21 at 01:06
-2

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