6

I am rebuilding my android project which is in java and some classes are written in kotlin. I have search on google but my problem didn't solve. I am getting below error while building my project:

/home/bansal/.gradle/caches/transforms-2/files-2.1/0bea321a20a76ca878f594ef198fedcf/jetified-core-ktx-1.10.0-alpha02-api.jar!/META-INF/core-ktx_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.

Below is my build.gradel

ext.kotlin_version = '1.6.10'
repositories {
    google()
    jcenter()
    maven {
        url 'http://dl.bintray.com/amulyakhare/maven'
    }
}
dependencies {
    classpath "com.android.tools.build:gradle:4.0.1"
    classpath 'io.realm:realm-gradle-plugin:3.2.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

and module build.gradle

  compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

dependencies{
    implementation 'androidx.core:core-ktx:1.7.0'


    annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'android.arch.lifecycle:viewmodel:1.1.1'
    implementation 'android.arch.lifecycle:extensions:1.1.1'

    //Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1'
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
    implementation "androidx.core:core-ktx:+"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

Tried solutiuon: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15

D.J
  • 1,439
  • 1
  • 12
  • 23

3 Answers3

3

This same issue i got before a few days .. and solution is too easy for this

In your build.gradle file (which you pasted first) , same classpath is written twice so remove any once of them

From

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10" // you can remove this
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

In your module level build.gradle file , same dependency is mentioned twice

From

implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.core:core-ktx:+" // you can remove this

sync gradle and try to run to your project

jayesh gurudayalani
  • 1,368
  • 1
  • 9
  • 14
  • I am done same but issue not resolved – D.J Jan 30 '23 at 10:28
  • update your gradle files here so we can verify and go ahead – jayesh gurudayalani Jan 30 '23 at 10:34
  • when I am using androidx 1.7.0 then getting error: Could not resolve all artifacts for configuration ':classpath'. > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0. Required by: project : > Cannot choose between the following variants of org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0: – D.J Feb 03 '23 at 12:29
1

I had a similar problem and found a dissimilar solution. Android Studio suggested I update to Electric Eel from Dolphin. Figuring things couldn't get worse, I did it, and ta da - the problem went away!

steveA
  • 56
  • 1
  • 2
0

I ran into a problem like this today.

This error message indicates that the version of Kotlin used to compile the

jetified-core-ktx

library is not compatible with the version of Kotlin used in your project. The

jetified-core-ktx

library was compiled with Kotlin version 1.8.0, while your project expects version 1.6.0.

You can fix this issue by updating the Kotlin version used in your project to match the version used by the

jetified-core-ktx

library. To do this, you can change the Kotlin version specified in your project’s build.gradle file to 1.8.0:

buildscript {
    ext.kotlin_version = '1.8.0'
    ...
}

After making this change, you should sync your project and rebuild it. I hope this helps.

Dikascode
  • 21
  • 5