Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 402
Khamidjon Khamidov Avatar asked Jun 28 '20 07:06

Khamidjon Khamidov


9 Answers

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

like image 52
Mr Wil Avatar answered Oct 17 '22 02:10

Mr Wil


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)

like image 28
Khamidjon Khamidov Avatar answered Oct 17 '22 02:10

Khamidjon Khamidov


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

like image 28
Ali Zarei Avatar answered Oct 17 '22 01:10

Ali Zarei


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.

like image 42
goldy1992 Avatar answered Oct 17 '22 01:10

goldy1992


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

like image 21
raditya gumay Avatar answered Oct 17 '22 03:10

raditya gumay


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.

like image 36
Ehsan Khaveh Avatar answered Oct 17 '22 03:10

Ehsan Khaveh


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")
    }
}
like image 28
Vijay Avatar answered Oct 17 '22 01:10

Vijay


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

like image 3
Mohamed Salama Avatar answered Oct 17 '22 02:10

Mohamed Salama


In my case it solved by declaring plugin:

plugins {
    id("dagger.hilt.android.plugin")
}
like image 2
Mohsents Avatar answered Oct 17 '22 03:10

Mohsents