Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 242
iClaude Avatar asked Jul 10 '20 11:07

iClaude


4 Answers

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"
like image 130
Laufwunder Avatar answered Oct 26 '22 06:10

Laufwunder


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.

like image 34
Ali Rezaiyan Avatar answered Oct 26 '22 06:10

Ali Rezaiyan


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.

like image 28
Andrew Avatar answered Oct 26 '22 06:10

Andrew


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

like image 21
Mohammed Fathi Avatar answered Oct 26 '22 06:10

Mohammed Fathi