编译时使用了不兼容的 Kotlin 版本。其元数据的二进制版本为 1.8.0,而期望的版本为 1.6.0。

8

我正在重建我的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.gradle文件:

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
}

和模块 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"
}

尝试的解决方案:模块使用了与 Kotlin 不兼容的编译版本。其元数据的二进制版本为 1.5.1,而期望版本为 1.1.15
3个回答

3

我之前几天也遇到了同样的问题...解决方法非常简单

在你的build.gradle文件中(你之前粘贴的),有一个classpath被重复写了两次,所以删除其中任意一个即可。

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

在您的模块级build.gradle文件中,同一依赖项被提及两次。
从:
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.core:core-ktx:+" // you can remove this

同步Gradle并尝试运行您的项目。


我做了相同的事情,但问题没有得到解决。 - D.J
请在此处更新您的Gradle文件,以便我们进行验证并继续。 - jayesh gurudayalani
当我使用androidx 1.7.0时,出现错误:无法解析配置“:classpath”的所有工件。
无法解析org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0。 需要: 项目 : 不能在以下org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0变体之间进行选择:
- D.J

1

我曾经遇到过类似的问题,但找到了一种不同的解决方案。Android Studio建议我从Dolphin升级到Electric Eel。想着事情不会变得更糟,我就这么做了,结果问题迎刃而解!


这对我来说就可以了,因为我没有重复的“classpath”。 - zzarbi
工作了一天...第二天就停止工作了。 - zzarbi
对我来说没有改变。我目前拥有的是 - steveA
对我来说并没有改变。我有 kotlin_version = '1.8.10'classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - steveA

0
今天我遇到了这样的问题。
此错误消息表明,用于编译 jetified-core-ktx 库的 Kotlin 版本与您的项目中使用的 Kotlin 版本不兼容。jetified-core-ktx 库是使用 Kotlin 版本 1.8.0 编译的,而您的项目期望使用版本为 1.6.0。
您可以通过将项目的 Kotlin 版本更新为与 jetified-core-ktx 库相匹配的版本来解决此问题。为此,您可以更改项目的 build.gradle 文件中指定的 Kotlin 版本为 1.8.0:
buildscript {
    ext.kotlin_version = '1.8.0'
    ...
}

在进行此更改后,您应该同步您的项目并重新构建它。希望这可以帮助到您。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接