gpt4 book ai didi

android - 编译项目时出现 Dagger 错误

转载 作者:行者123 更新时间:2023-12-05 00:42:31 26 4
gpt4 key购买 nike

使用 Dagger 时出现以下错误

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

请注意,我已经关注了 stackoverflow 和其他文档中的一些主题 Hilt Unsupported metadata version in Kotlin

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

https://github.com/google/dagger/issues/2379

使用下面的app gradle配置

 compileSdk 32

defaultConfig {
applicationId "com.test.plantdemo"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
}

安卓插件

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}

应用级依赖

   dependencies {
implementation "androidx.work:work-runtime-ktx:2.5.0"
kapt 'androidx.hilt:hilt-compiler:1.0.0'
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt "com.google.dagger:hilt-android-compiler:2.35.1"
kapt "com.google.dagger:hilt-compiler:2.35.1"
implementation "com.google.dagger:hilt-android:2.35.1"
}

我使用的顶级依赖

 dependencies {
// other plugins...
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40'
}

顶级 gradle 插件

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
id 'com.google.dagger.hilt.android' version '2.41' apply false
}

错误窗口显示以下错误


[Hilt] Processing did not complete.

See error above for details.Execution failed for task ':app:kaptDebugKotlin'.A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkActionjava.lang.reflect.InvocationTargetException (no error message)


添加库后我遵循的步骤

Step1:Android应用类

@HiltAndroidApp
class PlantApplication: Application() {
}

第二步:模块类

@Module
@InstallIn(SingletonComponent::class)
object MainModule {
}

第三步:查看模型

@HiltViewModel
class PlantListBaseViewModel @Inject constructor(): ViewModel() {
}

第四步: fragment

@AndroidEntryPoint
class PlantListBaseFragment : Fragment() {
}

最佳答案

我建议使用 Dagger 的最新稳定版本。我正在使用这些版本:

classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"

implementation "com.google.dagger:dagger-android-support:2.42"
implementation "com.google.dagger:hilt-android:2.42"

我希望它会工作

更新:

如果您对原因感到好奇,请看这里:

Looks like Dagger needs to update the kotlin-metadata-jvm library to 0.4.0 which supports reading metadata from Kotlin 1.7, current version is 0.3.0, you might be able to work around the issue by forcing an update on the transitive dep, likely depending on it directly, something like this:

dependencies {
//Not a processor, but forces Dagger to use newer metadata lib
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.4.2"
}

您可以在此处关注:https://github.com/google/dagger/issues/3383

关于android - 编译项目时出现 Dagger 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73061190/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com