Reputation: 3372
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?
Upvotes: 6
Views: 6661
Reputation: 1516
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("androidx.hilt:hilt-compiler::2.40")
Using 2.40
for both fixed it.
Upvotes: 2
Reputation: 809
For me the issue was that the .kt
file I was in was missing its package
block at the top.
After adding package <my app package>
and then clean/rebuild the problem resolved itself.
Upvotes: 15
Reputation: 31
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'
Upvotes: 3
Reputation: 3372
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.
Upvotes: 8