Hilt Unsupported metadata version in Kotlin
Asked Answered
R

24

152

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

Research answered 28/5, 2021 at 18:35 Comment(4)
Try to update all hilt libraries to the latest versionsDonetta
I was tried, but it has the same issueMountford
Update your Hilt version to the latest (2.36 at the moment)Giguere
it's not working for meMountford
R
237

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

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

Kotlin:1.9.0 with Hilt:2.48

Research answered 9/7, 2021 at 15:12 Comment(10)
Thanks for the answer,upgrading the hilt library is a nightmare at times.Frediafredie
Also these versions work for me: kotlin:1.6.0 , hilt:2.40.5Numskull
This worked for me, I used the answer provided by @NazaninNasab since it has more up to date versions. cheersCorallite
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.Ignoramus
for me the gradle plugin was out of date, updating it to match the hilt version resolved my problem.Osteology
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.Failing
Man, android development sucks. You spend more than 50% of the time solving dependencies and compatibility problems than actual work.Germann
I've been battling with this issue for two days now...your solution finally worked...THANKS!Machinate
Worked for me id("org.jetbrains.kotlin.android") version "1.9.0" apply false to id("org.jetbrains.kotlin.android") version "1.7.0" apply falseInterlaminate
Thanks for me Kotlin:1.7.0 with Hilt:2.42 this combination works perfectlyExhibitionism
R
80

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")
    }
Rigger answered 2/9, 2023 at 7:4 Comment(3)
Great! The best answer!Uhhuh
Thanks mate, It worked for me for the latest version.Oman
Thank you so much! it worked! I had some time struggling with thisNeumark
W
23

If anyone still facing this issue related to not matching version of kotlin and hilt here is the latest version of hilt vs kotlin that is working for me

project level:

plugins {
    id("com.android.application") version "8.1.2" apply false
    id("org.jetbrains.kotlin.android") version "1.9.0" apply false
    id("com.google.dagger.hilt.android") version "2.48.1" apply false
}

app level:

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

kotlinOptions {
        jvmTarget = "1.8"
    }

dependencies {

    implementation("androidx.core:core-ktx:1.12.0")

    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
    implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.2")

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

}

I wasted around 30 hr just to figure out proper latest version and compatibility where I was stuck with the same reported error. hope this will help someone!

Winterfeed answered 11/10, 2023 at 20:50 Comment(4)
This was the fix! Good work! kapt annotation was the trick.Superaltar
Thanks alot... Shubham for solution i was facing same issue since 3 days after update android studio. now got resolvedBudd
Happy for you broWinterfeed
2 days of looking and searching came to an end thanks a lotRigsdaler
U
20

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

}
Upu answered 2/7, 2022 at 18:37 Comment(2)
The error is related to compatibility issues between hilt and kotlin. Updating Hilt might work but you will also have to look at Kotlin compatibility whether it needs to be upgraded or not.Barrington
Your solution worked with me, thanks <3Oxidize
C
17

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"
Convulse answered 11/3, 2023 at 6:25 Comment(0)
E
8

Updated: Kotlin DSL

Using dagger version 2.48 with ksp also resolved this issue. Using Java version 17.

build.gradle.kts (project)

plugins {
    ...

    id("com.google.devtools.ksp") version "1.9.10-1.0.13" apply false
    id("com.google.dagger.hilt.android") version "2.48" apply false
}

build.gradle.kts (app)

plugins {
   ...   

   id("com.google.dagger.hilt.android")
   id("com.google.devtools.ksp")
}

...

dependencies {
   ...

   implementation("com.google.dagger:hilt-android:2.48")
   ksp("com.google.dagger:hilt-compiler:2.48")
}

Old Solution

I resolved the error by updating the dependency version to the latest version and adding this additional dependency. I am using java version 17.

kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0"

build.gradle (Project Level)

plugins {
   ...

   id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
   id 'com.google.dagger.hilt.android' version '2.48' apply false
}

build.gradle (App Level)

plugins {
   ...   
   
   id 'kotlin-kapt'
   id 'com.google.dagger.hilt.android'
}

...

dependencies {
   ...

   implementation "com.google.dagger:hilt-android:2.48"
   kapt "com.google.dagger:hilt-compiler:2.48"
   kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0"
}

kapt {
    correctErrorTypes true
}
Ebbie answered 5/9, 2023 at 15:9 Comment(0)
F
6

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'
Frediafredie answered 7/8, 2021 at 11:59 Comment(0)
L
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

Lakeesha answered 21/4, 2022 at 16:42 Comment(0)
A
5

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

Anarchy answered 22/9, 2021 at 12:57 Comment(3)
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.Platitudinous
This is the Right way of resolving the error on latest SDKParfitt
I would suggest this but only to improve the answer to verify the versions used in gradle as a complement to https://mcmap.net/q/156676/-hilt-unsupported-metadata-version-in-kotlinAlvaroalveolar
B
4

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

Barris answered 10/8, 2022 at 13:10 Comment(1)
What if I am not using hilt in my android app?Headspring
P
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"
Peekaboo answered 25/10, 2022 at 7:25 Comment(0)
S
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"
}
Scarcely answered 31/7, 2021 at 10:39 Comment(0)
M
2

You can use

kotlin_version = "1.8.10"
hilt_version = "2.45"

That are the newest versions

Mitten answered 25/2, 2023 at 8:59 Comment(0)
I
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"
Inconvertible answered 19/7, 2023 at 11:31 Comment(0)
N
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.
Napiform answered 13/7, 2021 at 10:22 Comment(1)
That's the correct answer. It's for dependency/library version error and debug option shows the actual reason.Brancusi
P
1

I have face this issue twice,

So two possible solution for this problem:

Case 1: If you are using new version of Android such as 1.8 or 1.9

Simply update the version of dagger.hilt into the new one 2.48

Classpath:

plugins {
     id "com.google.dagger.hilt.android" version "2.42" apply false
}

and dependency :

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

Case 2: If you are using previous version of Android such as 1.7 or less than you have to make sure that the classpath and dependency version match, in my case the error was because of different version.

Mismatch:

Classpath:

plugins {
    id "com.google.dagger.hilt.android" version "2.42" apply false
}

and dependency :

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

Correct:

Classpath:

plugins {
    id "com.google.dagger.hilt.android" version "2.42" apply false
}

and dependency :

 implementation "com.google.dagger:hilt-android:2.42"
   kapt "com.google.dagger:hilt-compiler:2.42"
Phosphaturia answered 18/9, 2023 at 13:34 Comment(0)
G
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'
Goldman answered 25/8, 2022 at 15:4 Comment(0)
W
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

Whoop answered 17/10, 2022 at 23:33 Comment(0)
T
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"
Teresetereshkova answered 19/1, 2023 at 12:3 Comment(0)
S
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'

Saavedra answered 23/8, 2023 at 20:37 Comment(0)
R
0

My solution: if you use dagger 2 and hilt in one project, you should keep versions the same

hiltVersion = '2.48.1'
daggerVersion = '2.48.1'
Reremouse answered 28/11, 2023 at 18:43 Comment(0)
B
0

So i am getting the same issue and after a lot of time spend i got to knew it's only version issue. If you are using kotlin version

id("org.jetbrains.kotlin.android") version "1.9.0" apply false

You can find it in your project level gardle.

The hilt version should be in project level gradle

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

and in app level gradle it should be

 implementation("com.google.dagger:hilt-android:2.48")
 kapt("com.google.dagger:hilt-android-compiler:2.48")
Bennie answered 14/3 at 11:43 Comment(0)
R
0

in project level gradle add -

    buildscript {
    dependencies {
    classpath "com.google.dagger:hilt-android-gradle-plugin:2.48.1"
    }
}
Roentgenograph answered 14/4 at 20:8 Comment(0)
A
0

Solution for Kotlin Gradle: (for Groovy just use same versions)

This problem is arised basically when your Kotlin version is incompatible with the Kotlin version used in Hilt. So it's not a big deal. Just adjust the versions and that's it 👏👏👏

In your root level Gradle file match the following versions:

plugins {
    id("com.android.application") version "8.2.0" apply false
    id("org.jetbrains.kotlin.android") version "1.9.23" apply false
    id("com.google.dagger.hilt.android") version "2.51.1" apply false
    id("com.google.devtools.ksp") version "1.9.23-1.0.20" apply false
}

and in your app level Gradle file match the following versions for all of those dependencies.

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    kotlin("kapt")
    id("com.google.devtools.ksp")
    id("com.google.dagger.hilt.android")
}

dependencies {
    // Hilt
    implementation("com.google.dagger:hilt-android:2.51.1")
    kapt("com.google.dagger:hilt-android-compiler:2.51.1")
    implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
}

I also mentioned ksp versions along with Hilt and Kotlin because someone may need to use also use ksp in their project which also related to the Kotlin version.

Akanke answered 15/4 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.