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

19

C:/Users/LENOVO/.gradle/caches/transforms-2/files-2.1/2bcd0a6b95744b6f0ee26f9336bd22eb/jetified-annotation-jvm-1.6.0-beta01.jar!/META-INF/annotation.kotlin_module: 模块是使用不兼容的 Kotlin 版本编译的。其元数据的二进制版本为 1.8.0,预期版本为 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'
    }
}

我已经有了这个问题的解决方案,你可以在这个链接中查看 >> https://dev59.com/Mn4QtIcB2Jgan1znx_1W#75269801 - Chit Anuchit
它对我起作用了,当我只是添加了 ext.kotlin_version = '1.8.0' 并根据 Android Studio 的建议增加了 Gradle 版本。 - Satheesh Guduri
当我按照Android Studio的建议,只需添加"ext.kotlin_version = '1.8.0'"并增加Gradle版本时,它对我起了作用。 - undefined
7个回答

7

最近,我在使用Compose Material3模板创建新项目时遇到了类似的问题。

所以我升级了以下库/插件来解决我的问题,并附上了我的gradle文件供参考。

kotlin版本升级至1.8.0

kotlinCompilerExtensionVersion升级至'1.4.0'

compose_version升级至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
}

这个解决方案对我来说有效,使用的是Gradle 7.5和AGP 7.4.0。 - esteban21

1

这个项目包含一些不兼容甚至危险的内容,这也导致了你遇到的问题:

  • jcenter() 不再提供服务,需要用 mavenCentral() 替换它,否则你的依赖将无法正确解析。
  • 你同时指定了 Kotlin 的 1.4.32 (已不再维护)和 1.6.10 (不太理想但仍可用),这两个版本的类肯定是不兼容的。
  • 有些其他依赖可能使用 Kotlin 1.8.0 或更新版本,因此旧的运行时环境将无法读取它们的元数据。

jcenter目前为止是只读的。使用它不会阻止解析依赖项。 - btraas
jcenter目前是只读状态,无限期地。使用它不会阻止解析依赖项。 - undefined

1
可能更新Android Studio就能解决问题。 如果你必须使用旧版本的Android Studio,尝试降级kotlin和appcompat依赖项。
我已经从:
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'

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

这解决了我的问题。

但是现在你有过时的依赖关系 - Thelouras

0
如果您不想或无法更新Kotlin,您可以在项目结构中简单地设置适当的Android Gradle插件版本(文件->项目结构)。在Android Studio中,它将寻找与您当前的Kotlin版本兼容的模块,而不是下载使用较高Kotlin版本构建的最新模块。

0
对我来说,解决方案是Arpit Patel的答案的一部分。当我升级了我的kotlin插件和模块依赖项时,我开始遇到这个错误。
为了解决这个问题,我只需要在项目的build.gradle中将org.jetbrains.kotlin.android插件版本升级到1.8.0
以下是修复后的build.gradle文件:
根目录下的build.gradle:
plugins {
    // ...
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

模块的 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'
}

希望这能帮助到那些使用新的 root build.gradle 格式的人,其中没有 classpath。

0
我不得不将Kotlin和Compose版本更新到最新版本。 这是Kotlin和Compose版本的兼容性列表:https://developer.android.com/jetpack/androidx/releases/compose-kotlin 在build.gradle(:app)的android{}中:
composeOptions {
    kotlinCompilerExtensionVersion '1.5.3'
}

在我添加了Dagger Hilt之后,我遇到了问题,所以这也很重要:
在build.gradle(:app)的dependencies{}中:
implementation 'com.google.dagger:hilt-android:2.48'
annotationProcessor 'com.google.dagger:hilt-compiler:2.48'

在build.gradle(项目)中:
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
}

-3
我遇到了这个错误 - 但它的原因不同。
请确保在settings.gradle中使用:
includeBuild('../node_modules/@react-native/gradle-plugin')

而不是:

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

希望这能对其他人有所帮助。

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