22

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

Hasan Kucuk
  • 2,433
  • 6
  • 19
  • 41

7 Answers7

19

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

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

yincrash
  • 6,394
  • 1
  • 39
  • 41
8

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
}
Rodrigo Queiroz
  • 2,674
  • 24
  • 30
1

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
ruby6221
  • 228
  • 1
  • 7
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

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.

Kurovsky
  • 1,081
  • 10
  • 25
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")
                }
            }
        }
Hasan Kucuk
  • 2,433
  • 6
  • 19
  • 41
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'
Ray
  • 16,025
  • 5
  • 31
  • 51