Recently, the handicap has been upgraded Android Studio
to a new version Android Studio Chipmunk
, and I found that gradle
the version has been upgraded 7.4.2
, gradle 插件
and the version has been upgraded 7.2.0-alpha05
. There was no problem at first, but today I want to join Hilt
this third-party library, and a problem arises.
Everyone knows that Hilt
the third-party library of this kind of giant bull fork is generally built with ASM
+ APT
+ 注解
+ 反射
+ 动态代理
these underlying basic knowledge. Therefore, when using it APT
, you need to use related gradle
plug-ins.
Usually we use Hilt
only two steps:
- add
hilt-android-gradle-plugin
plugin; - Add
hilt-android
dependencies.
build.gradle
Usually we can add Hilt-android-gradle-plugin
plugin dependencies in the root directory of the project :
But now in the new version there build.gradle
is no longer classpath
the position:
The writing method here is completely different from the old version, and it is Kotlin DSL
written in grammar.
At this time, I need to add it Hilt
to the project, but I can’t find classpath
the place to add it, which is more difficult. Through the search gradle
documentation:
https://docs.gradle.org/current/userguide/userguide.pdf
Then tell me that you only need to build.gradle
add the corresponding dependencies in the project root directory:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'
}
}
Add it to the following places as shown in the figure:
Done.