HiltkotlinIllegalStateException: Unsupported metadata version. Check that your Kotlin version is

Posted guangdeshishe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HiltkotlinIllegalStateException: Unsupported metadata version. Check that your Kotlin version is相关的知识,希望对你有一定的参考价值。

问题:

在kotlin+java混合项目中接入Hilt后编译时报错如下:

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

根据提示,执行Run with --info后得到跟Hilt有关报错信息如下:

Caused by: java.lang.IllegalStateException: Unsupported metadata version. Check that your Kotlin version is >= 1.0
	at dagger.internal.codegen.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:218)
	at dagger.internal.codegen.kotlin.KotlinMetadata.from(KotlinMetadata.java:196)
	at dagger.internal.codegen.kotlin.KotlinMetadataFactory.create(KotlinMetadataFactory.java:56)

原因:

版本兼容问题

解决办法:

更新前用的Hilt版本是2.28-alpha将Hilt和插件版本都更新到最新版2.37问题就解决了

  • 项目根目录build.gradle:
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.37'
  • 模块build.gradle
api 'com.google.dagger:hilt-android:2.37'
kapt 'com.google.dagger:hilt-android-compiler:2.37'

以上是关于HiltkotlinIllegalStateException: Unsupported metadata version. Check that your Kotlin version is的主要内容,如果未能解决你的问题,请参考以下文章