117

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

Lang Minh Nguyên
  • 3,648
  • 4
  • 10
  • 31

17 Answers17

182

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

Lang Minh Nguyên
  • 3,648
  • 4
  • 10
  • 31
  • 4
    Thanks for the answer,upgrading the hilt library is a nightmare at times. – Zaid Zakir Aug 07 '21 at 12:01
  • 2
    Also these versions work for me: kotlin:1.6.0 , hilt:2.40.5 – Nazanin Nasab Jan 16 '22 at 17:01
  • 2
    This worked for me, I used the answer provided by @NazaninNasab since it has more up to date versions. cheers – Doilio Matsinhe Mar 22 '22 at 10:53
  • 2
    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. – MatJB Jun 18 '22 at 16:27
  • for me the gradle plugin was out of date, updating it to match the hilt version resolved my problem. – Eman Jul 07 '22 at 18:49
  • For some reason my project built fine on my normal desktop computer but I was getting this Hilt "unsupported metadata version" error when I cloned the repo onto my Surface tablet. But upgrading my Hilt Gradle plugin from 2.40.1 (I think that's what it was) to 2.42 (Kotlin Gradle plugin was already 1.7.0) fixed it. Appreciate it big dawg, I don't know anything about all this Gradle/dependencies crap. – clamum Sep 10 '22 at 05:58
  • 7
    Man, android development sucks. You spend more than 50% of the time solving dependencies and compatibility problems than actual work. – Talha Nov 01 '22 at 19:42
  • I've been battling with this issue for two days now...your solution finally worked...THANKS! – Onalo Joseph Apr 02 '23 at 21:40
19

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

}
12

If you use kotlin version 1.8.0 then

in Project-level build.gradle change hilt version

id 'com.google.dagger.hilt.android' version '2.44' apply false

In App-level build.gradle

implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
6

Adding this line to build.gradle dependencies helped me:

kapt("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0")

https://youtrack.jetbrains.com/issue/KT-45885

Vladimir Berezkin
  • 3,580
  • 4
  • 27
  • 33
5

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'
Zaid Zakir
  • 543
  • 3
  • 7
4

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

  • 1
    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](/help/how-to-ask). – Community Sep 22 '21 at 14:57
  • This is the Right way of resolving the error on latest SDK – asadullah Oct 22 '21 at 18:22
  • I would suggest this but only to improve the answer to verify the versions used in gradle as a complement to https://stackoverflow.com/a/68319048/1084764 – Raykud Jul 14 '22 at 17:32
4

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

Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50
4

in Project-level build.gradle change hilt version

id 'com.google.dagger.hilt.android' version '2.44' apply false

in App-Level build.gradle

implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
Nikunj Patel
  • 321
  • 4
  • 5
2

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"
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mansi Sharma
  • 965
  • 6
  • 6
2

check the hilt_version_one is same to hilt_version_two

I get the problem , when my two version is different .

id 'com.google.dagger.hilt.android' version "$hilt_version_one" apply false
implementation "com.google.dagger:hilt-android:$hilt_version_two"
kapt "com.google.dagger:hilt-compiler:$hilt_version_two"
Tom
  • 333
  • 2
  • 8
1

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.
Filipkowicz
  • 639
  • 6
  • 17
1

You can use

kotlin_version = "1.8.10"
hilt_version = "2.45"

That are the newest versions

0

In my case, the problem was caused by different versions specified in the dependencies:

  • 2.40 in classpath 'com.google.dagger:hilt-android-gradle-plugin'
  • 2.43.2 in implementation 'com.google.dagger:hilt-android'
Younes Charfaoui
  • 1,059
  • 3
  • 10
  • 20
Falchio
  • 174
  • 1
  • 14
0

I have an issue when upgrading kotlin-gradle-plugin:1.7.x for fulfill requirement of compose. I revert them to org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21 and kotlinCompilerExtensionVersion value

composeOptions {
    kotlinCompilerExtensionVersion compose_version
}

kotlinCompilerExtensionVersion compose_version

Kishan Viramgama
  • 893
  • 1
  • 11
  • 23
fahrizal89
  • 598
  • 5
  • 13
0
Firstly check helt dependency versions with below url

https://dagger.dev/hilt/gradle-setup

Check you kotlin versions

Kotlin version 1.6.0

Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.40"

App level gradle
def hilt_version="2.40"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"


Kotlin version 1.7.0

Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"

App level gradle
def hilt_version="2.42"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
Sumit Kumawat
  • 127
  • 10
0

In my case it turned out that the Hilt version in the implementation and the classpath were different, making them the same solved the issue. A good practice should be using a version variable.

They were like this: In the build.gradle file of the app module

implementation "com.google.dagger:hilt-android:2.39.1" In the build.gradle file of the project

classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.1'

Ray
  • 16,025
  • 5
  • 31
  • 51
0

Here how i solved the error:

If you are using Kotlin 1.9.0 then use hilt 2.48

Make these Updates in Hilt version:

in Project-level build.gradle

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

in App-level build.gradle

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

dependencies{
     implementation("com.google.dagger:hilt-android:2.48")
        kapt("com.google.dagger:hilt-android-compiler:2.48")
    }