Hilt Unsupported metadata version in Kotlin

10,992

Solution 1

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

Currently Kotlin 1.5.21 is compatible with Hilt 2.38.

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

Solution 2

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'

Solution 3

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

Share:
10,992
Minh Nguyên
Author by

Minh Nguyên

Backend Developer

Updated on June 06, 2022

Comments

  • Minh Nguyên
    Minh Nguyên about 2 years

    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

  • Zaid Zakir
    Zaid Zakir almost 3 years
    Thanks for the answer,upgrading the hilt library is a nightmare at times.
  • Admin
    Admin almost 3 years
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
  • asadullah
    asadullah over 2 years
    This is the Right way of resolving the error on latest SDK
  • Nazanin Nasab
    Nazanin Nasab over 2 years
    Also these versions work for me: kotlin:1.6.0 , hilt:2.40.5
  • Doilio Matsinhe
    Doilio Matsinhe over 2 years
    This worked for me, I used the answer provided by @NazaninNasab since it has more up to date versions. cheers
  • MD. Shafiul Alam Biplob
    MD. Shafiul Alam Biplob about 2 years
    That's the correct answer. It's for dependency/library version error and debug option shows the actual reason.
  • MatJB
    MatJB about 2 years
    I would add: Visit the Gradle Build Setup page and verify EVERYTHING is up to date in your build.gradle files. Android Studio with it's suggestions helped me update only a part, but the Hilt Gradle Plugin was not, so I ended up having new and old version numbers that were causing the error.