【问题标题】:Hilt java.lang.IllegalStateException: Unsupported metadata version. Check that your Kotlin version is >= 1.0Hilt java.lang.IllegalStateException:不支持的元数据版本。检查您的 Kotlin 版本是否 >= 1.0
【发布时间】:2022-11-25 15:25:22
【问题描述】:

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

插件

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'realm-android'
    id 'androidx.navigation.safeargs.kotlin'
    id 'kotlin-parcelize'
}

依赖关系

//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'

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
}

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

Hilt Unsupported metadata version in Kotlin

Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException

Upgrading Android kotlin version to 1.5.0 throwing error message on build

如果需要更多信息,请告诉我。提前致谢。您的努力将不胜感激。

【问题讨论】:

  • kotlin 和 hilt 不能一起工作,我用 kotlin.android 1.6.21 尝试了 hilt 2.41 并且可以工作
  • @AagitoEx 如果我的应用程序没有刀柄怎么办?仍然收到此错误!

标签: android kotlin dependency-injection dagger-hilt


【解决方案1】:

添加以下依赖项为我修复了它。 我的代码中没有 Hilt 但有 Dagger 2.41

kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0"

【讨论】:

    猜你喜欢
    • 2022-10-13
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    • 2016-02-13
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多