Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin?

Viewed 18619

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?

9 Answers

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)

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")
    }
}

source

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.

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.

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")
    }
}

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

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

In my case it solved by declaring plugin:

plugins {
    id("dagger.hilt.android.plugin")
}
Related