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
9
Answers
After a long struggle, I solved the problem as follows;
I added a resolutionStrategy to settings.gradle as below.
Then, when I added the hilt plugin as below to the module level build.gradle file, it was updated correctly.
For adding
dagger hilt
to your project. Follow these stepsAdd
hilt
dependencies to your module’sbuild.gradle
. I assume you are usingKotlin
, otherwise you have to useannotationProcessor
insted ofkapt
plugin.Add
hilt gradle plugin
to project’sbuild.gradle
.Apply
kotlin-kapt
andhilt
plugins to modulebuild.gradle
Just you need to add this to project’s root build.gradle file.
plugin{}
block in the rootbuild.gradle
is used to define the Gradle plugins that can be applied to rootbuild.gradle
and all(or some) the Gradle sub-projects.The one caveat of using plugin block is that it only resolves plugin that is present in the Gradle plugin portal(see doc) or custom Maven and Ivy plugin repositories must contain plugin marker artefacts in addition to the artefacts which actually implement the plugin(see doc).
In the case of the Android Gradle plugin and Hilt plugin, they have not published those plugins to Gradle plugin portal and they have also not published their Plugin Marker Artifacts
Due to the above missing Plugin Marker Artifacts you need to manually resolve the plugin using Plugin Resolution Rules at
settings.gradle
by adding the below code(this is specific to Hilt Gradle plugin for other you have to check different againstrequested.id.id
)I am late for the answer.
I was also facing the same problem in Android Studio Bumblebee because of the new Gradle syntax for adding dependencies at the project level.
For adding Dagger Hilt in project-level you can use the following syntax:
At the time of writing this, the latest version is 2.41. It is in mavenCentral repository.
First, add the
hilt-android-gradle-plugin
plugin to your project’s rootbuild.gradle
file:
Then, apply the Gradle plugin and add these dependencies in your app/build.gradle file:
enable Java 8 in your project, add the following to the app/build.gradle
All I need to add was this class path:
use this configration in gradle root
and in 2nd gradle file
I faced the same problem, I solved the problem as follows:
First, add the
com.google.dagger.hilt.android
plugin to your project’s root build.gradle file:Then, apply the Gradle plugin and add these dependencies in your app/build.gradle file: