Hilt Unsupported metadata version in Kotlin

Viewed 35299

I was tried to run my code in Kotlin 1.5.10 With plugin as

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

and dependencies as below

dependencies {
    ...
    //Dagger - Hilt
    implementation "com.google.dagger:hilt-android:2.33-beta"
    kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
    kapt "androidx.hilt:hilt-compiler:1.0.0-beta01"
    implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha01'

    implementation 'com.android.support:palette-v7:28.0.0'

When I migrate to kotlin_version = "1.5.10", it just errors out stating

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.internal.codegen.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:206) at dagger.internal.codegen.kotlin.KotlinMetadata.from(KotlinMetadata.java:186) at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133) ...

Can anyone help me? I spent a lot of time on it, your answer will help me a lot

9 Answers

Go to https://dagger.dev/hilt/gradle-setup check Hilt currently version

Update: For now, you can use the newest version.

Kotlin:1.7.0 with Hilt:2.42

Update: kotlin:1.6.0 is compatible with hilt:2.40.5, thanks @Nazanin Nasab

Currently, Kotlin 1.5.21 is compatible with Hilt 2.38.

dependencies {
    ...
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
    classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
}

I got the same error. I changed two gradle files and It worked for me.

Project Gradle

plugins {
   
    //    dependencies for dagger hilt
    id 'com.google.dagger.hilt.android' version '2.42' apply false

}

Module Gradle

dependencies {

    implementation 'com.google.dagger:hilt-android:2.42'
    kapt 'com.google.dagger:hilt-compiler:2.42'
    implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")

}

Thanks for the answer , i had to do a slight tweak in order to work for me because i'm using Arctic Fox, hopefully this answer will help as well

Build.gradle (project)

buildscript {
ext {
    compose_version = '1.0.0'
}
repositories {
    google()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:7.1.0-alpha05'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
    classpath "com.google.dagger:hilt-android-gradle-plugin:2.37"
}
}

Build.gradle (app)

//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.34-beta"
kapt "com.google.dagger:hilt-android-compiler:2.34-beta"
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'

general solution - in AS build console click link at bottom - build with -stacktrace param and find which annotation processor (KAPT) is causing error - then try to update dependency - if you are lucky new version should be available and supporting your gradle version

message in build output you should lookin for

Try:
Run with --stacktrace option to get the stack trace. Run with --info or 
--debug option to get more log output. Run with --scan to get full insights.

I got same here. I was using dagger:hilt-android:2.33-beta with Kotlin 1.5.10.Please try this

Project gradle

implementation "com.google.dagger:hilt-android:2.33-beta"

Module gradle

plugins {
    ...
    id 'dagger.hilt.android.plugin'
}
dependencies {
    ...
    //dagger-hilt
    implementation "com.google.dagger:hilt-android:2.35.1"
    kapt "com.google.dagger:hilt-android-compiler:2.35.1"
}

If any solution solved your problem. Go to https://dagger.dev/hilt/gradle-setup, in Using Hilt with Kotlin section, copy the version mentioned in dependencies and update your build.gradle accordingly

For Kotlin 1.7.10, you just need to make the hilt versions 2.42.

in my case, the problem was in the different versions that I specified in the dependencies.

  • "2.40" in classpath 'com.google.dagger:hilt-android-gradle-plugin'
    and
  • "2.43.2" in implementation 'com.google.dagger:hilt-android'
Related