使用不兼容的 Kotlin 版本编译。其元数据的二进制版本是1.8.0,预期版本是1.6.0

Dhe*_*sal 12 android kotlin build.gradle kotlin-android-extensions

我正在重建我的 android 项目,它是用 java 编写的,一些类是用 kotlin 编写的。我在谷歌上搜索过,但我的问题没有解决。我在构建项目时遇到以下错误:

/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:模块已编译与 Kotlin 版本不兼容。其元数据的二进制版本是1.8.0,预期版本是1.6.0。

下面是我的 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
}
Run Code Online (Sandbox Code Playgroud)

和模块 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"
}
Run Code Online (Sandbox Code Playgroud)

尝试过的解决方案:模块是使用不兼容的 Kotlin 版本编译的。其元数据的二进制版本是1.5.1,预期版本是1.1.15

小智 3

几天前我也遇到了同样的问题..解决方案对此来说太简单了

在您的 build.gradle 文件(您首先粘贴的)中,相同的类路径被写入两次,因此删除其中的任何一个

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10" // you can remove this
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Run Code Online (Sandbox Code Playgroud)

在模块级 build.gradle 文件中,相同的依赖项被提及两次

implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.core:core-ktx:+" // you can remove this
Run Code Online (Sandbox Code Playgroud)

同步 gradle 并尝试运行到您的项目