Search code examples
androidkotlindependency-injectionandroid-gradle-plugindagger-hilt

Hilt implement issue - Expected @HiltAndroidApp to have a value


I'm having a issue implement Hilt on android app...

The error is:

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

Project gradle file

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        //Hilt
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'

        classpath "com.android.tools.build:gradle:7.0.4"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
    }
}

Model gradle file

id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'

dependencies {

    def dagger_hilt_android = "2.38.1"

    implementation("com.google.dagger:hilt-android:$dagger_hilt_android")
    kapt("com.google.dagger:hilt-android-compiler:$dagger_hilt_android")
}

Solution

  • It is an issue with Kotlin-gradle-plugin: 1.5.20 as mentioned here https://github.com/google/dagger/issues/2684. Try upgrading your plugin to 1.5.21, and it will work.