'Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin?
When I am using Hilt in android with Room
I got this kinda error.
The full log is here:
home/someone/Desktop/Calculator/app/build/tmp/kapt3/stubs/debug/com/hamidjonhamidov/calculator/MyApplication.java:7: error: [Hilt]
public class MyApplication extends android.app.Application {
^
Expected @HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin?
[Hilt] Processing did not complete. See error above for details./home/someone/Desktop/Calculator/app/build/tmp/kapt3/stubs/debug/com/hamidjonhamidov/calculator/ui/main/MainActivity.java:7: error: [Hilt]
Anyone knows solution for this?
Solution 1:[1]
Fortunately, there is simple solution.
In build.gradle
in database scheme, we should use arguments +=
instead of arguments =
.
defaultConfig{
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
Or/And in buld.gradle
You should apply plugin like:
apply plugin 'dagger.hilt.android.plugin'
This solved the problem)
Solution 2:[2]
I had this issue after upgrading Kotlin to 1.5.20.
Adding kapt.use.worker.api=false
in gradle.properties worked for me the problem
Checkout dagger issue Support for Kotlin 1.5.20
Solution 3:[3]
UPDATE
Upgrade Hilt to v28.1.0 and Kotlin to v1.5.21 should fix this issue
OLD ANSWER
If you are on kotlin 1.5.20, answer of Mr-wil
will decrease build speed as said in official doc:
To improve the speed of builds that use kapt, you can enable the Gradle worker API for kapt tasks. Using the worker API lets Gradle run independent annotation processing tasks from a single project in parallel, which in some cases significantly decreases the execution time.
Instead, set:
kapt {
javacOptions {
// These options are normally set automatically via the Hilt Gradle plugin, but we
// set them manually to workaround a bug in the Kotlin 1.5.20
option("-Adagger.fastInit=ENABLED")
option("-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true")
}
}
Solution 4:[4]
This generic error message can also appear in many circumstances. As a more generic check, ensure that your module's build.gradle
file, ensure that you has:
apply plugin: 'dagger.hilt.android.plugin'
at the top.
Solution 5:[5]
This was due to a bug in Kotlin 1.5.20. It is fixed in Kotlin 1.5.21.
So all you need to do is to upgrade to the latest version of Kotlin.
Solution 6:[6]
I had the same problem and it seems like there is a problem in kotlin-kapt plugin. If you guys have tried out all the above answers and didn't get resolved, please try the below code in your build.gradle(module-level) outside the dependencies{} block
kapt {
javacOptions {
option("-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true")
}
}
Solution 7:[7]
in the build.gradle of your Android Gradle modules apply the plugin:
apply plugin: 'com.android.application'
apply plugin: 'dagger.hilt.android.plugin'
android {
// ...
}
see detail here
Solution 8:[8]
I'm still facing the same issue in 2022
I have solved the problem by adding
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
to build.gradle
project and adding
id 'dagger.hilt.android.plugin'
to plugins in build.gradle
app
Solution 9:[9]
In my case it solved by declaring plugin:
plugins {
id("dagger.hilt.android.plugin")
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | greybeard |
Solution 3 | |
Solution 4 | goldy1992 |
Solution 5 | Ehsan Khaveh |
Solution 6 | Vijay |
Solution 7 | raditya gumay |
Solution 8 | Mohamed Salama |
Solution 9 | Mohsents |