Search code examples
androidkotlinandroid-jetpack-composekotlin-coroutinesdagger-hilt

Android getting error Hilt when running app


I am getting this error while running my android project, can someone please help. I have the latest android studio jellyfish installed and i am using hilt version 2.51.1

error: [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
    at dagger.hilt.processor.internal.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:200)
    at dagger.hilt.processor.internal.kotlin.KotlinMetadata.from(KotlinMetadata.java:182)
    at java.base/java.util.HashMap.computeIfAbsent(Unknown Source)

  [Hilt] Processing did not complete. See error above for details.
1 error

this is my gradle app file, I have added all the latest plugins still getting the error

import com.android.build.gradle.internal.utils.isKotlinKaptPluginApplied

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)
    id("kotlin-kapt")
    id("com.google.dagger.hilt.android")
}

dependencies {

    //Dagger - Hilt
    implementation("com.google.dagger:hilt-android:2.51.1")
    kapt ("com.google.dagger:hilt-compiler:2.51.1")
    implementation ("androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03")
    kapt ("androidx.hilt:hilt-compiler:1.0.0")
    implementation ("androidx.hilt:hilt-navigation-compose:1.0.0-alpha03")
}
kapt {
    correctErrorTypes=true
}

Solution

  • I faced this same issue. I solved this using these versions:

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

    Please make sure to change the hilt version in plugins of the project-level build gradle:

    id("com.google.dagger.hilt.android") version "2.48" apply false