Android Hilt DI - error: package {ApplicationClassName}_HiltComponents does not exist

Viewed 2271

I am using the new Hilt library for Dependency Injection version 2.28-alpha. I have followed the Hilt documentation and annotated the Application class with the @HiltAndroidApp annotation. But when I am trying to build my project, its throwing a huge list of errors all similar to:

error: package {ApplicationClassName}_HiltComponents does not exist

public final class Dagger{ApplicationClassName}_HiltComponents_ApplicationC extends 
{ApplicationClassName}_HiltComponents.ApplicationC {

I have searched for it but since its a new library, there is not much QnA available for it. Why is it throwing that error and how do I resolve it?

3 Answers

Just Build -> Rebuild Project worked for me.

If someone else has the same problem and rebuilding the project doesn't work, feel free to comment your problem. If someone knows why it happens, please enlighten us with your answer.

For me none of the above worked. What fixed the issue was updating build tools and gradle wrapper to most recent versions.

Gradle wrapper from

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

to

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

And Build tools from

   buildToolsVersion '29.0.1'

to

   buildToolsVersion '29.0.3'

For me, i had a similar error because the Hilt gradle plugin was defined with different version than Hilt dependency.

classpath("com.google.dagger:hilt-android-gradle-plugin:2.38.1")

And Hilt dependency was:

implementation("com.squareup.retrofit2:retrofit:2.40")

Using 2.40 for both fixed it.

Related