I get the following warning when I want to use @AndroidEntryPoint which is a property of hilt in my project.
Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin)
When I try to add id 'dagger.hilt.android.plugin' to the module level build.gradle file of my project, I get the following error.
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'dagger.hilt.android.plugin'] was not found in any of the following sources:
I tried to add it to the build.gradle file at the Module level of the project as follows. They all give an error.
I tried to add it as a classpath to the project level build.gradle file, in this case I still get an error.
When I created the default project, a settings.gradle structure was created as follows. This is my first time using this build. My version of Android Studio Android Studio - Bumblebee | 2021.1.1 Canary 13
CodePudding user response:
For adding dagger hilt
to your project. Follow these steps
Add hilt
dependencies to your module's build.gradle
. I assume you are using Kotlin
, otherwise you have to use annotationProcessor
insted of kapt
plugin.
dependencies {
//..
implementation 'com.google.dagger:hilt-android:2.39.1'
kapt 'com.google.dagger:hilt-compiler:2.39.1'
//..
}
Add hilt gradle plugin
to project's build.gradle
.
dependencies {
//..
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.39.1'
}
Apply kotlin-kapt
and hilt
plugins to module build.gradle
plugins {
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
CodePudding user response:
After a long struggle, I solved the problem as follows;
I added a resolutionStrategy to settings.gradle as below.
pluginManagement {
repositories {...}
plugins { ...}
resolutionStrategy {
eachPlugin {
if( requested.id.id == 'dagger.hilt.android.plugin') {
useModule("com.google.dagger:hilt-android-gradle-plugin:2.39.1")
}
}
}
}
Then, when I added the hilt plugin as below to the module level build.gradle file, it was updated correctly.
plugins{
...
id 'dagger.hilt.android.plugin'
}