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

9

29

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

Chenay answered 26/6, 2022 at 22:5 Comment(3)
I'm getting the issue on my project. Did you get any solution?Etra
me too! none of the below solutions worked in my caseMorphogenesis
@MohitLakhanpal It was fixed when I did compileSdk and targetSdk 32.Chenay
C
0

problem solved when i added it like this

plugins {
            id 'androidx.navigation.safeargs' version '2.4.1'
            id 'dagger.hilt.android.plugin'
            id "org.jetbrains.kotlin.plugin.parcelize" version "1.6.0-M1"
            id 'com.android.library'
            id 'org.jetbrains.kotlin.android' version '1.7.0'
        }
    
      resolutionStrategy {
            eachPlugin {
                if (requested.id.id == 'dagger.hilt.android.plugin') {
                    useModule("com.google.dagger:hilt-android-gradle-plugin:2.42")
                }
                if (requested.id.id == 'com.google.gms.google-services') {
                    useModule("com.google.gms:google-services:4.3.10")
                }
            }
        }
Chenay answered 12/10, 2022 at 22:29 Comment(0)
V
23

Dagger/Hilt version 2.43.2 appears to have fixed this issue.

See https://github.com/google/dagger/releases/tag/dagger-2.43.2

Vagrom answered 24/8, 2022 at 17:14 Comment(1)
Be sure to change both project and module level build.gradle files.Kirschner
I
13

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
}
Infante answered 28/6, 2022 at 15:6 Comment(3)
It works by adding kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.4.2"Benedetta
You, sir, are a heroRuppert
why does it work though?Osis
S
4

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'
Spire answered 23/8, 2023 at 20:35 Comment(0)
S
2

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
Sarre answered 27/6, 2022 at 3:13 Comment(1)
what will be the plugins for kotlin version 1.6.10??@SarreAftermost
S
1

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

Spinach answered 27/6, 2022 at 4:24 Comment(0)
C
1

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.

Chamfer answered 21/9, 2022 at 19:48 Comment(0)
T
1

Just i upgrade Hilt to latest version (v2.50).

Threadbare answered 15/2 at 16:20 Comment(0)
U
1

You must upgrade Hilt to latest version (actually v2.50)

Follow steps for install Dagger:

  1. Add dagger.hilt in your build.gradle.kts (Project:NameProject):

     plugins {
     id("com.android.application") version "8.2.2" apply false
     id("org.jetbrains.kotlin.android") version "1.9.22" apply false
     id("com.google.dagger.hilt.android") version "2.50" apply false
    

    }

  2. Add dagger.hilt in your build.gradle.kts (Module:App):

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

    }

    dependencies {

     implementation("androidx.core:core-ktx:1.12.0")
     implementation("androidx.appcompat:appcompat:1.6.1")
     implementation("com.google.android.material:material:1.11.0")
     implementation("androidx.constraintlayout:constraintlayout:2.1.4")
     testImplementation("junit:junit:4.13.2")
     androidTestImplementation("androidx.test.ext:junit:1.1.5")
     androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
     implementation("com.google.dagger:hilt-android:2.50")
     kapt("com.google.dagger:hilt-android-compiler:2.50")
    

    }

    kapt {
     correctErrorTypes = true
    

    }

  3. Create Application in your MainActivity package:

    package com.example.kotlinfundamentals
    import android.app.Application
    import dagger.hilt.android.HiltAndroidApp
    
    @HiltAndroidApp
    class MyApplication : Application() {
    

    }

  4. Add Application name in Manifest file:

    <application
       android:name=".MyApplication">
    </application>
    
  5. Create class for example User class:

    package com.example.kotlinfundamentals
    
    data class User(
     val id: Int,
     val lastname: String,
     val firstname: String,
     val email: String
    )
    
  6. Create Hilt modules to provide instances of concrete types:

    package com.example.kotlinfundamentals
    import dagger.Module
    import dagger.Provides
    import dagger.hilt.InstallIn
    import dagger.hilt.components.SingletonComponent
    
    @Module
    @InstallIn(SingletonComponent::class)
    object UserModule {
    
     @Provides
     fun provideUser(): User {
         // Implémentez la logique pour créer et retourner un User
         // Vous pouvez utiliser des injections de dépendances ici
         return User(1, "John", "Doe", "[email protected]")
     }
    

    }

  7. Inject dependency in your Activity:

    package com.example.kotlinfundamentals
    import android.os.Bundle
    import android.widget.TextView
    import androidx.appcompat.app.AppCompatActivity
    import dagger.hilt.android.AndroidEntryPoint
    import javax.inject.Inject
    
    @AndroidEntryPoint
    class MainActivity : AppCompatActivity() {
    
    
    @Inject
    lateinit var user: User
    
    override fun onCreate(savedInstanceState: Bundle?) {
     super.onCreate(savedInstanceState)
     setContentView(R.layout.activity_main)
    
    
     val userTxtview: TextView = findViewById(R.id.txtview);
    
    
     // Accéder aux attributs de User
     val userId = user.id
     val userFirstName = user.firstname
     val userLastName = user.lastname
     val email = user.email
    
    
     userTxtview.text = userFirstName
    

    } }

I hope, I helped someone

Best Regards

Undue answered 18/2 at 20:28 Comment(0)
C
0

problem solved when i added it like this

plugins {
            id 'androidx.navigation.safeargs' version '2.4.1'
            id 'dagger.hilt.android.plugin'
            id "org.jetbrains.kotlin.plugin.parcelize" version "1.6.0-M1"
            id 'com.android.library'
            id 'org.jetbrains.kotlin.android' version '1.7.0'
        }
    
      resolutionStrategy {
            eachPlugin {
                if (requested.id.id == 'dagger.hilt.android.plugin') {
                    useModule("com.google.dagger:hilt-android-gradle-plugin:2.42")
                }
                if (requested.id.id == 'com.google.gms.google-services') {
                    useModule("com.google.gms:google-services:4.3.10")
                }
            }
        }
Chenay answered 12/10, 2022 at 22:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.