iClaude
iClaude

Reputation: 737

Hilt (Android): cannot find symbol return DaggerApp_HiltComponents_ApplicationC.builder()

I tried to replace Koin with Hilt (bad idea) for DI and now I'm stuck with this error: Hilt_App.java:21: error: cannot find symbol return DaggerApp_HiltComponents_ApplicationC.builder() ^ symbol: variable DaggerApp_HiltComponents_ApplicationC

What is it? How to fix it?

Upvotes: 20

Views: 12418

Answers (7)

404nnotfoundd
404nnotfoundd

Reputation: 34

In my case, I forgot to complete binding abstraction.

like this:

import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
abstract class useCaseModule

Upvotes: 0

user3381409
user3381409

Reputation: 126

In my case I forgot to add package com.xxx.xxx.. at the top of the class!!

I lost 2 days trying to figure this out :(

Upvotes: 11

Dessy
Dessy

Reputation: 1

I've met the issue and work with these dependencies:

implementation "com.google.dagger:hilt-android:$hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$hiltVersion"
kapt "androidx.hilt:hilt-compiler:$hiltAndroidXVersion"

https://medium.com/gradeup/dependency-injection-dagger-hilt-vs-koin-ab2f7f85e6c6

Upvotes: 0

Laufwunder
Laufwunder

Reputation: 837

I got the same error message. My problem was that I had an old/deprecated gradle dependency. Make sure to remove following dpenedency from your gradle file:

/* DELETE this dependency */
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"

Upvotes: 35

Andrew
Andrew

Reputation: 4742

For those who had the same error but did not miss any dependencies. I had this problem, because I forgot to annotate one class with "@Inject constructor". After I did that, everything worked again.

Upvotes: 2

Ali Rezaiyan
Ali Rezaiyan

Reputation: 3309

If you are working on a modular project, take care of dependencies!

For example, if you have a retrofit dependency in your data module, even your data module implemented in the app module, you must add retrofit dependency as well or make them transactive with the api to be accessible to the app module.

Upvotes: 11

Mohammed Fathi
Mohammed Fathi

Reputation: 1475

as answered in the guestion comments. The problem was that when using Jetpack integrations as explained here for the ViewModels https://developer.android.com/training/dependency-injection/hilt-jetpack and you have to add those dependencies also in the main app module (not only in the modules where you actually use ViewModels).

for example , if you have the following in the feature module's build.gradle file:

    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_lifecycle"
    kapt "androidx.hilt:hilt-compiler:1.0.0-alpha02"

make sure you add them to the app's build.gradle file as well

Upvotes: 1

Related Questions