Solve the problem that the new version of Android studio relies on hilt (other dependencies are similar), personally effective, and the hilt dependency version corresponding to the kotlin version is attached at the end of the article

When many friends rely on hilt, they find that their kotlin version (my suggestion is kotlin1.7.0) is too high, and it fails to compile. The expectation is version 1.5.1. I searched a lot on the Internet, but I can't solve this problem, or it is someone else's as Old, the dependency problem is easy to solve, but there is no solution to the version, and I have spent a lot of time thinking about it.

Above: 1. First rely on external libraries in the project's build.gradle, and define a dependent library directly on top of plugins. The location is as shown in the figure below

buildscript {
    dependencies {
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'
    }
}

 2. Add the plugins you want to use in the plugins in the configuration file in the app's build.gradle, as shown in the figure

    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'

 3. Add it to the places where you usually add dependencies (dependencies), and compile it.


    implementation 'com.google.dagger:hilt-android:2.42'
    kapt 'com.google.dagger:hilt-compiler:2.42'

 

, I am also using hilt for the first time. If I can communicate more with my friends, I will share my learning results when I have time.

Kotlin: 1.7.0 corresponds to Hilt: 2.42

Kotlin: 1.6.0 corresponds to Hilt: 2.40.5

Kotlin 1.5.21 corresponds to Hilt:2.38 compatible

Guess you like

Origin blog.csdn.net/weixin_51315931/article/details/130141026