Example about how to setup and implement Dagger Hilt in order to understand the basic concepts
-
You can check up the last plugin version on Maven
buildscript { ... ext.hilt_version = "2.31.2-alpha" ... repositories { // other repositories... mavenCentral() } dependencies { // other plugins... classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" } }
-
plugins { ... id "org.jetbrains.kotlin.kapt" id "dagger.hilt.android.plugin" } ... dependencies { ... implementation "com.google.dagger:hilt-android:$hilt_version" kapt "com.google.dagger:hilt-android-compiler:$hilt_version" // For instrumentation tests androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version" kaptAndroidTest "com.google.dagger:hilt-android-compiler:$hilt_version" // For local unit tests testImplementation "com.google.dagger:hilt-android-testing:$hilt_version" kaptTest "com.google.dagger:hilt-android-compiler:$hilt_version" // Activity KTX for viewModels() implementation "androidx.activity:activity-ktx:1.2.0" ... } kapt { correctErrorTypes true }
-
@HiltAndroidApp class MyApplication : Application()