Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException

Viewed 3061

I changed my Kotlin version from 1.6.10 to 1.7.0.

from this

 implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10'

upgrated to

 implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.0'

But Hilt throws an error. My Hilt version is 2.42. Is there a way to fix this without downgrading again? It works fine in Kotlin 1.6.10 and Hilt 2.42. But I want to use it by upgrading my kotlin version.

enter image description here

5 Answers

You can add kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.4.2" and the problem will go away, however if you are using Jetpack Compose then you will have to downgrade your Kotlin version to 1.6.10 as Compose compiler is not compatible with Kotlin 1.7.0 as of yet.

plugins {
    id 'com.android.application' version '7.2.1' apply false
    id 'com.android.library' version '7.2.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.6.10' apply false
    id 'com.google.dagger.hilt.android' version '2.42' apply false
}

You may change your kotlin gradle plugin to the same version:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"

Here's my components version and it works:

hilt/hilt gradle plugin:2.42
dagger2:2.35.1
kotlin/kotlin gradle plugin:1.6.21

it is saying that u have different verisons of plugin and dependencies

In your project level build.gradle file or Settings.gradle file check for kotlin version you haven't updated it while u have updated your dependency, just change the kotlin version to 1.7.0

In my case that build error was happening after adding any new module to the project.

For some reason Android Studio (2021.2.1) is changing the org.jetbrains.kotlin:kotlin-gradle-plugin version in the main build.gradle file after the module is added, upgrading its version to the latest one. This brings up the mentioned issue. Just revert this change, if that is the case.

Related