Reputation: 5465
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
Upvotes: 177
Views: 153715
Reputation: 548
I fixed it by updating my Hilt version
id 'com.google.dagger.hilt.android' version '2.48' apply false
implementation "com.google.dagger:hilt-android:2.48"
kapt "com.google.dagger:hilt-android-compiler:2.48"
I use Gradle version 8.10.2 and Kotlin 1.9.24
Upvotes: 0
Reputation: 41
Even I have this error, I suggest a way put the exact version they are giving the documentation.
For kotlin 1.9.22:
plugins {
...
id("com.google.dagger.hilt.android") version "2.51.1" apply false
}
//in app.gradle
plugins {
id("kotlin-kapt")
id("com.google.dagger.hilt.android")
}
android {
...
}
dependencies {
implementation("com.google.dagger:hilt-android:2.51.1")
kapt("com.google.dagger:hilt-android-compiler:2.51.1")
}
// Allow references to generated code
// I think this line is the GameChanger. I didn't see this in above response. suggestion and explanation are welcome..
kapt {
correctErrorTypes = true
}
Hence the Error will be solved
Upvotes: 0
Reputation: 3444
I also got the similar error due incompatible versions of Kotlin and Hilt,
Following combination worked for me:
kotlin_version = '2.0.0'
hilt_version = '2.51.1'
Upvotes: 2
Reputation: 5465
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
- Hilt:2.48
Kotlin:2.0.0
- Hilt:2.51.1
For Gradle version catalogs: You can use either ksp or kapt; for now, I use ksp.
Project-level build.gradle
plugins {
/.../
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.dagger.hilt) apply false
}
App-level build.gradle
plugins {
/.../
alias(libs.plugins.compose.compiler)
alias(libs.plugins.ksp)
alias(libs.plugins.dagger.hilt)
}
libs.versions.toml
[libraries]
/.../
hilt = { group = 'com.google.dagger', name = 'hilt-android', version = '2.51.1'}
androidx-hilt = { group = 'androidx.hilt', name = 'hilt-navigation-compose', version = '1.2.0'}
hilt-android-compiler = { group = 'com.google.dagger', name = 'hilt-compiler', version = '2.51.1' }
[plugins]
/.../
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version = "2.0.0-1.0.23" }
dagger-hilt = { id = "com.google.dagger.hilt.android", version = "2.51.1" }
Upvotes: 297
Reputation: 1147
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.50" apply false
}
app level:
plugins {
...
id("kotlin-android")
id("kotlin-kapt")
id("com.google.dagger.hilt.android")
}
kotlinOptions {
jvmTarget = "17"
}
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.50")
kapt("com.google.dagger:hilt-android-compiler:2.50")
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!
ps- update version from 2.48.1
to 2.50
Upvotes: 37
Reputation: 1791
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.
Upvotes: 0
Reputation: 26
in project level gradle add -
buildscript {
dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:2.48.1"
}
}
Upvotes: 0
Reputation: 209
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")
Upvotes: 1
Reputation: 21
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'
Upvotes: 1
Reputation: 305
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"
Upvotes: 1
Reputation: 1461
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")
}
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
}
Upvotes: 10
Reputation: 1001
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")
}
Upvotes: 88
Reputation: 16235
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'
Upvotes: 0
Reputation: 413
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"
Upvotes: 2
Reputation: 606
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'
Upvotes: 0
Reputation: 454
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"
Upvotes: 19
Reputation: 31
You can use
kotlin_version = "1.8.10"
hilt_version = "2.45"
That are the newest versions
Upvotes: 2
Reputation: 825
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
Upvotes: 0
Reputation: 125
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"
Upvotes: 0
Reputation: 381
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"
Upvotes: 4
Reputation: 221
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")
}
Upvotes: 21
Reputation: 3599
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
Upvotes: 6
Reputation: 61
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
Upvotes: 6
Reputation: 995
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"
}
Upvotes: 2
Reputation: 563
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'
Upvotes: 6
Reputation: 669
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.
Upvotes: 1