For Kotlin With XML
First, add the hilt-android-gradle-plugin plugin to your project's
root build.gradle file:
buildscript { repositories { google() } dependencies { val nav_version = "2.7.7" classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version") } } plugins { ... // 2.47 works with kotlin 1.8 id("com.google.dagger.hilt.android") version "2.47" apply false }
Â
Then, apply the Gradle plugin and add these dependencies in your app/build.gradle file:
plugins { id ("kotlin-kapt") id("com.google.dagger.hilt.android") id("androidx.navigation.safeargs.kotlin") // for kotlin-only modules // or id("androidx.navigation.safeargs") } android { ... buildFeatures{ viewBinding = true } } dependencies { // for hilt // please choose version based on kotlin version // ex: for 1.8 --> 2.47 etc.. implementation("com.google.dagger:hilt-android:2.44") // latest 2.49 kapt("com.google.dagger:hilt-android-compiler:2.44") // latest 2.48 // lifecycle val lifecycle_version = "2.8.0" val arch_version = "2.2.0" // ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version") // LiveData implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version") // for retrofit implementation ("com.squareup.retrofit2:retrofit:2.9.0") // new 2.11.0 implementation ("com.squareup.retrofit2:converter-gson:2.9.0") // for room val room_version = "2.6.1" implementation("androidx.room:room-runtime:$room_version") annotationProcessor("androidx.room:room-compiler:$room_version") kapt("androidx.room:room-compiler:$room_version") // optional - Paging 3 Integration implementation("androidx.room:room-paging:$room_version") // for coroutine val coroutine_version = "1.8.0" implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version") // for paging 3 val paging_version = "3.3.0" implementation("androidx.paging:paging-runtime-ktx:$paging_version") // for navigation val nav_version = "2.7.7" implementation("androidx.navigation:navigation-fragment-ktx:$nav_version") implementation("androidx.navigation:navigation-ui-ktx:$nav_version") } // Allow references to generated code kapt { correctErrorTypes = true }
Â