Dagger-hilt error while compiling project
Asked Answered
I

3

7

Getting error below while using dagger-hilt

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

Please note that I already followed some topics from stackoverflow and other documentation 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

Using below app gradle configuration

 compileSdk 32

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

Android plugin

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

App level dependency

   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"
}

Top level dependency I used

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

Top level gradle Plugin

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
}

Error window shows below error


[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$KaptExecutionWorkAction java.lang.reflect.InvocationTargetException (no error message)


step I followed after adding library

Step1: Android application class

@HiltAndroidApp
class PlantApplication: Application() {
}

Step2: Module calss

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

Step3: View Model

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

Step4: fragment

@AndroidEntryPoint
class PlantListBaseFragment : Fragment() {
}
Involucrum answered 21/7, 2022 at 5:39 Comment(0)
F
11

I recommend using the latest stable version of Dagger. Mine is working with these versions:

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"

I hope it'll work

Update:

If you are curious about the reason, here:

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"
}

you can follow that here: https://github.com/google/dagger/issues/3383

Fredericton answered 21/7, 2022 at 13:4 Comment(1)
thanks exact same gradle dependancy it will work , but what about if I Put classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0" it will gives same error. If you find any solution please update the answerInvolucrum
T
1

It seems they aligned the needed versions of metadata in dagger in hilt 2.50 - in my case updating it worked (did not work on 2.44 though)

Timbered answered 1/1, 2024 at 19:56 Comment(0)
T
1

If you are still facing this issue, I recommend you update to these versions:

kotlin = "1.9.0"
hiltAndroid = "2.48"
hiltAndroidCompiler = "2.48"

Also, make sure to update the hilt version in project-level build gradle.

id("com.google.dagger.hilt.android") version "2.48" apply false
Tobytobye answered 24/6, 2024 at 5:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.