Parmit Singh Malik
Parmit Singh Malik

Reputation: 397

The binary version of its metadata is 1.8.0, expected version is 1.6.0. Module was compiled with an incompatible version of Kotlin

C:/Users/LENOVO/.gradle/caches/transforms-2/files-2.1/2bcd0a6b95744b6f0ee26f9336bd22eb/jetified-annotation-jvm-1.6.0-beta01.jar!/META-INF/annotation.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.

buildscript {
    ext.kotlin_version = '1.4.32'
    ext.anko_version='0.10.8'
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
      google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.2'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.1'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        // Add the dependency for the Performance Monitoring plugin
        classpath 'com.google.firebase:perf-plugin:1.4.1'
    }
}

Upvotes: 25

Views: 75791

Answers (14)

SRD
SRD

Reputation: 58

in my case I upgraded the KTOR library and now I got the message "The binary version of its metadata is 2.0.0, expected version is 1.8.0."

Finally the solution was to upgrade to the latest version of Gradle from 8.4 to 8.11.1

Upvotes: 0

Pritesh Rane
Pritesh Rane

Reputation: 21

I was also facing similar issue. I changed Kotlin version, And it got resolve.

From:

    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'

To:

    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0'

After that I was facing issue "'compileLiveAppDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsLiveAppDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version."

Then I have done below changes in App Level build.gradle

compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
    jvmTarget = '17'
}

Note: After doing above all changes you need to do kotlin language syntax related changes in app. For example: "'when' expression must be exhaustive error when using adapters"

Upvotes: 2

Tetiana Tort
Tetiana Tort

Reputation: 1

The binary version of its metadata is 1.8.0 expected version is 1.6.0

I had an old project, which I decided to update. Firstly I got other issues, regarding my old version. I've spent too much time to fix that so I decided to delete android folder and create it again. Right after I faced with new issues: The binary version of its metadata is 1.8.0 expected version is 1.6.0.

To fix it I decided to stick to version 1.9.23. Here are the places where I made changes and errors were gone:

project/android/build.gradle:

buildscript {
ext.kotlin_version = '1.9.23'
repositories {
    google()
    mavenCentral()
  }
dependencies {
    classpath 'com.android.tools.build:gradle:4.1.3'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  }
}
allprojects{...

app/build.gradle:

plugins{...
android{...
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.23"
}

android/settings.gradle

pluginManagement {...
plugins{
    ...
    id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

Hopefully it will help

Upvotes: 0

Pratik Gondaliya
Pratik Gondaliya

Reputation: 420

My Error: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

I was getting above error. I have seen multiple solutions as well which I tried at the end what worked for me I am just explaining below.

In my case I was working with react native. So on native android side I encountered that error which was due to a mismatch between the kotlin version used to compile some libraries and the kotlin version expected by your project.

I went to app/gradle/build.gradle (Project level) and I changed

ext
{
  kotlinVersion = 1.9.10
} 

then second step which I performed was

I went to app/gradle/build.gradle.kts and I changed

plugins {
  kotlin("jvm") version "1.9.10"
  id("java-gradle-plugin")
}

these steps solved my issue. Let me know if you need more help in this regard.

Thank you!!!!!!

Upvotes: 0

Jonathan Applebaum
Jonathan Applebaum

Reputation: 5986

In build.gradle of the project, Updating the version number from this:

plugins {
    id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}

to this:

plugins {
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

finally solved the problem.

Upvotes: 1

user112380
user112380

Reputation: 369

For this you have check three files to confirm

android/settings.gradle : In plugins make sure you have the correct version of the org.jetbrains.kotlin.android

eg:

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version '8.3.2' apply false
    id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

android/build.gradle : In dependencies Make sure org.jetbrains.kotlin:kotlin-gradle-plugin has the correct version

Eg : dependencies {

    classpath 'com.android.tools.build:gradle:8.3.2' // Make sure this version matches your Android Gradle Plugin version
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23" // Make sure the Kotlin plugin version is compatible

}

android/app/build.gradle : Make Sure org.jetbrains.kotlin:kotlin-stdlib has the correct version

Eg : dependencies {

// Consolidated to use only the necessary Kotlin stdlib based on your Kotlin version
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.23"

}

Upvotes: 1

Mori
Mori

Reputation: 4611

In this case, this error will appear when two dependencies are updated :

implementation 'com.google.android.material:material:1.7.0'

to new version 1.11.0 (sdk 34)

implementation 'androidx.core:core-ktx:1.9.0'

to new version 1.12.0 (sdk 34)

There are two ways:

1- Back to the previous version

2- Change the version of Kotlin plugins for Gradle to Version 2.0.0-Beta2 (latest) but 1.8.0 can be acceptable

plugins{    
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
    
}

Upvotes: 0

StonedCodingTom
StonedCodingTom

Reputation: 151

I had to update kotlin and compose versions to the newest one. Here is the compatibility list for kotlin and compose versions: https://developer.android.com/jetpack/androidx/releases/compose-kotlin

In build.gradle(:app) in android{}:

composeOptions {
    kotlinCompilerExtensionVersion '1.5.3'
}

Problem happened to me after adding dagger hilt so that was important too:

In build.gradle(:app) in dependencies{}:

implementation 'com.google.dagger:hilt-android:2.48'
annotationProcessor 'com.google.dagger:hilt-compiler:2.48'

In build.gradle(project):

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {

        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.48'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10"
    }
}
plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
}

Upvotes: 3

Aishwarya
Aishwarya

Reputation: 361

Probably updating Android Studio will do the trick. If you have to use older version of Android Studio, try to downgrade both kotlin and appcompat dependencies.

I have changed from:

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'

to

 implementation 'androidx.core:core-ktx:1.6.0'
 implementation 'androidx.appcompat:appcompat:1.3.1'

And this resolved my issue.

Upvotes: 4

Prem Suman
Prem Suman

Reputation: 36

For me the solution was part of Arpit Patel's answer. I started getting this error when I upgraded my kotlin plugin and modules dependencies.

To solve this, I just had to upgrade the org.jetbrains.kotlin.android plugin version to 1.8.0 in project's build.gradle.

Following are my build.gradle files after the fix:

root build.gradle:

plugins {
    // ...
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

module's build.gradle:

dependencies {
    implementation 'androidx.core:core-ktx:1.10.1'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
    implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
}

Hope this helps people with the new root build.gradle format where classpath isn't there.

Upvotes: 0

SH DM
SH DM

Reputation: 31

If you don't want or can't update Kotlin, you can simply set appropriate Android Gradle Plugin Version in project structure. (File->Project Structure) in android studio, it will look for modules compatible with your current Kotlin version rather than downloading the latest ones built with higher Kotlin versions.

Upvotes: 1

Wex
Wex

Reputation: 4686

I was getting this error - but it had a different cause.

Make sure that in settings.gradle you are using:

includeBuild('../node_modules/@react-native/gradle-plugin')

And not:

includeBuild('../node_modules/react-native-gradle-plugin')

Hope this helps someone else out.

Upvotes: -3

Arpit Patel
Arpit Patel

Reputation: 8047

Recently, I faced a similar issue on creating a new project in Android studio with Compose Material3 template.

So I upgraded below libraries/plugins solve my issue. I also attached my gradle files for reference.

kotlin version to 1.8.0

kotlinCompilerExtensionVersion '1.4.0'

compose_version to 1.3.1

build.gradle(app)

    plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.example.appname'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.appname"
        minSdk 23
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.4.0'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
    implementation 'androidx.activity:activity-compose:1.6.1'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.compose.material3:material3:1.1.0-alpha05'


    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}

build.gradle(project)

    buildscript {
    ext {
        compose_version = '1.3.3'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.1' apply false
    id 'com.android.library' version '7.4.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

Upvotes: 13

Luiz Rodrigo
Luiz Rodrigo

Reputation: 535

This project contains a few incompatible or even dangerous things, that also lead you to the problem you're having:

  • jcenter() is not in service anymore, so it should be replaced by mavenCentral() or your dependencies will not be correctly resolved.
  • You specify both Kotlin 1.4.32 (no longer maintained) and 1.6.10 (no longer ideal, but still usable) and the classes will definitely not be compatible between them.
  • Some of your other dependencies might be even newer and use Kotlin 1.8.0, so your older runtimes won't be able to read their metadata.

Upvotes: 2

Related Questions