Home > database >  Can you use Hilt in a Java-only Android project?
Can you use Hilt in a Java-only Android project?

Time:05-04

According to the official integration guide, you need to add

plugins {
  id 'kotlin-kapt'
  ...
}

and

dependencies {
    implementation "com.google.dagger:hilt-android:{hilt_version}"
    kapt "com.google.dagger:hilt-compiler:{hilt_version}"
}

to your build.grade file. However, when I do a gralde sync, I get the following error:

Plugin [id: 'kotlin-kapt'] was not found in any of the following sources:

is it possible to use Dagger-Hilt in a pure java project? Or do you have to either use plain Dagger or use Kotlin?

CodePudding user response:

Yes, you can use the following instead of kotlin-kapt:

dependencies {
    implementation "com.google.dagger:hilt-android:{hilt_version}"
    annotationProcessor 'com.google.dagger:hilt-compiler:{hilt_version}'
}


plugins {
    id 'dagger.hilt.android.plugin'
}
  • Related