Hilt java.lang.IllegalStateException:不支持的元数据版本。检查您的 Kotlin 版本是否 >= 1.0

Gok*_*oku 4 android dependency-injection kotlin dagger-hilt

我在项目中添加 hilt 依赖项时遇到问题

插件

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'realm-android'
    id 'androidx.navigation.safeargs.kotlin'
    id 'kotlin-parcelize'
}
Run Code Online (Sandbox Code Playgroud)

依赖关系

//Dependency injection with Hilt 
implementation("com.google.dagger:hilt-android:2.38.1")
kapt("com.google.dagger:hilt-android-compiler:2.38.1")
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Run Code Online (Sandbox Code Playgroud)

build.gradle 项目级别

buildscript {

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.1'
        classpath "io.realm:realm-gradle-plugin:10.11.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.0"
        classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
plugins {
    id 'com.android.application' version '7.2.1' apply false
    id 'com.android.library' version '7.2.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}


task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过以下堆栈溢出的答案,但没有找到解决方案

Hilt Kotlin 中不支持的元数据版本

元数据版本不受支持。检查您的 Kotlin 版本是否 >= 1.0:java.lang.IllegalStateException

将 Android kotlin 版本升级到 1.5.0 在构建时抛出错误消息

如果需要更多信息,请告诉我。提前致谢。您的努力将受到赞赏。

Var*_*A M 10

添加以下依赖项为我解决了这个问题。我的代码中没有 Hilt,但有 Dagger 2.41

kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0"
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

5927 次

最近记录:

2 年,9 月 前