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

I just hit this problem this morning. Do you have anything in your build.gradle that adds arguments to the annotationProcessOptions? For example:

  android {
        ...
        defaultConfig {
            ...
            javaCompileOptions {
                annotationProcessorOptions {
                    arguments = ["room.schemaLocation":
                                 "$projectDir/schemas".toString()]
                }
            }
        }
    }

If so, try changing from "arguments =" to "arguments +=", as just using equals overwrites anything set previously.


Just don't forget to add Hilt classpath dependency to your project level gradle file:

classpath "com.google.dagger:hilt-android-gradle-plugin:$versions.daggerHiltCoreVersion"

Define the specific version number instead of $versions.daggerHiltCoreVersion above.

And add plugin to your app level gradle:

apply plugin : 'dagger.hilt.android.plugin'

For later Gradle versions, add the plugin as follows

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

To backup @SteveC answer, when using Kotlin Gradle DSL is a bit different

We can't use either += or arguments = mapOf(). As stated in the official Dagger-Hilt documentation here & the github issue here regarding the docs as well

See below image for explanations:

arguments = mapOf()

  1. arguments = mapOf() will call setArguments with this.arguments.clear(), thus will overwrite previous argument (in this case Hilt)

Workaround approach:

        javaCompileOptions {
            annotationProcessorOptions {
                arguments(
                    mapOf(
                        "dagger.gradle.incremental" to "true",
                        "room.incremental" to "true"
                    )
                )
            }
        }

Wrapping the arguments() as a functions instead of calling setter, it'll retain the previous arguments as well.