Switching to Hilt
When we use Dagger in an Android application, there is a bit of boilerplate code we are forced to write. Some of it is around dealing with the life cycles of objects linked with activities and fragments, which leads us to create subcomponents; other parts are around the usage of ViewModel objects.
An attempt to simplify Dagger for Android was made with the Dagger-Android library, but later, a new library was developed on top of Dagger called Hilt. This library simplifies much of the Dagger usage through the use of new annotations, which leads to more boilerplate code that can be generated.
To use Hilt in a project, we will need the following plugins:
plugins {
…
alias("com.google.devtools.ksp:1.9.20-1.0.14")
alias("com.google.dagger.hilt.android:2.49")
}
To add the Hilt library to your project, you need the following:
dependencies {
...