Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hilt incompatible with Kotlin to 1.9 #4035

Closed
santiwanti opened this issue Aug 25, 2023 · 16 comments
Closed

Hilt incompatible with Kotlin to 1.9 #4035

santiwanti opened this issue Aug 25, 2023 · 16 comments

Comments

@santiwanti
Copy link

santiwanti commented Aug 25, 2023

Updating Kotlin to 1.9 causes a build error when using Hilt 2.44

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

@danysantiago
Copy link
Member

danysantiago commented Aug 25, 2023

You'll need to update Hilt to 2.46 or higher where the kotlinx-metadata-jvm is updated to support newer Kotlin versions.

@aDarkRider
Copy link

I have increased the version from 2.44 to 2.46 but it is not syncing with this version.

@jens-muenker
Copy link

I have the same problem with the newest version.

@Chang-Eric
Copy link
Member

@Frosch2010 do you have more details you can share? E.g. stacktrace and versions

@jens-muenker
Copy link

@Chang-Eric thanks for your response. I fixed it now. I figured out that I used different versions. I used 2.44 for the Gradle plugin and the newest version in the dependencies. Now are both the same and it works.

@EmmxReach
Copy link

EmmxReach commented Jan 17, 2024

Thank you so much!! I had the same problem, but now Its working!

@khalidpro1997
Copy link

thanks

@tapark
Copy link

tapark commented Feb 5, 2024

very good 👍

@AmeerHamza112
Copy link

if your kotlin version is 1.9.22 set your hilt version to 2.46 and it will work fine .

@maulik22995
Copy link

This also worked for me if you set everything to latest :

composeOptions { kotlinCompilerExtensionVersion = "1.5.9" }

check out kotlin compatibility with kotlin compiler : https://developer.android.com/jetpack/androidx/releases/compose-kotlin#pre-release_kotlin_compatibility

kotlin is 1.9.0 set hilt version to 2.46 and it is working.

@Shamteshi
Copy link

Gradle plugin:

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

Dependency:

implementation("com.google.dagger:hilt-android:2.50")
kapt("com.google.dagger:hilt-android-compiler:2.50")

Notice that the versions are the same for both the plugin and dependencies.

@brianBk
Copy link

brianBk commented Jun 8, 2024

Just update everything to latest for hilt and Kotlin (1.9 and above) and it will work fine.
hilt = "2.51.1"
hiltCompiler = "2.51.1"
kotlin = "1.9.23"

@shivvrat12
Copy link

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

composeOptions {
    kotlinCompilerExtensionVersion = "1.5.13"
}

[versions]
agp = "8.4.2"
hiltAndroidCompiler = "2.51.1"
hiltAndroid = "2.51.1"
kotlin = "1.9.23"

Still facing the same issue damn hilt setup sometime is so irritating

@k1zlt
Copy link

k1zlt commented Aug 14, 2024

Thank you)

@CesarYupa
Copy link

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)

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

}

android {
namespace = "com.yupa"
compileSdk = 34

defaultConfig {
    applicationId = "com.yupa"
    minSdk = 24
    targetSdk = 34
    versionCode = 1
    versionName = "1.0"

    testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    vectorDrawables {
        useSupportLibrary = true
    }
}

buildTypes {
    release {
        isMinifyEnabled = false
        proguardFiles(
            getDefaultProguardFile("proguard-android-optimize.txt"),
            "proguard-rules.pro"
        )
    }
}
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
    jvmTarget = "17"
}
buildFeatures {
    compose = true
}
composeOptions {
    kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
    resources {
        excludes += "/META-INF/{AL2.0,LGPL2.1}"
    }
}

}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.runtime.livedata)

implementation("com.squareup.retrofit2:retrofit:2.11.0")
implementation("com.squareup.retrofit2:converter-gson:2.11.0")

implementation("com.google.dagger:hilt-android:2.52")
kapt("com.google.dagger:hilt-android-compiler:2.52")

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)

}

kapt {
correctErrorTypes = true
}

@CesarYupa
Copy link

plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false

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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests