20

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?

iClaude
  • 707
  • 8
  • 14
  • Make sure that you added Gradle plugin as a dependency and that your Application is annotated with @HiltAndroidApp. If this doesn't solve your problem, post more of your source code. – Vasiliy Jul 10 '20 at 11:42
  • 6
    Thanks. The problem was that I used the 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). – iClaude Jul 10 '20 at 12:05
  • and you didn't get anything more meaningful in the error message than what's stated in the question? If that's the case, sounds like a valid reason to file an issue on GitHub. – Vasiliy Jul 10 '20 at 12:08
  • Another problem. What if I want to get a shared ViewModel (same instance of the ViewModel for Activity and Fragments). I tried to annotate the ViewModel with @ActivityRetainedScope, but if I use by viewModels() I get different instances of the ViewModel. – iClaude Jul 10 '20 at 16:08
  • I don't know the answer. Conceptually, to get a shared ViewModel, you need to make sure to call `provide` method with the same instance of Activity. I don't think that just moving ViewModel into retained component achieves that. Maybe that byViewModels() can receive "parent" parameter? – Vasiliy Jul 11 '20 at 04:48
  • Please check your JDK version, it should be latest(11.0.10) by going to "Settings" > "Build, Execute, Depolyment" > "Build Tools" > "Gradle" – Zeeshan Shahid Oct 20 '21 at 10:12

5 Answers5

35

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"
Laufwunder
  • 773
  • 10
  • 21
11

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.

Ali Rezaiyan
  • 3,011
  • 3
  • 16
  • 27
  • Hey. My app is a single module but I'm facing this issue. This is an intermittent and very frustrating. Do you know any way to fix? – Syed Zeeshan May 24 '21 at 12:49
  • 1
    @SyedZeeshan this error occurs when the provider methods do not have access to the object that is going to be provided. if you could have a sample code I'll help better. – Ali Rezaiyan May 24 '21 at 14:09
  • This is correct answer for me. My `app` module does not implement `retrofit` dependency and could not find Retrofit instance during build. – Hoa Nguyen Sep 21 '21 at 16:32
2

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.

Andrew
  • 4,264
  • 1
  • 21
  • 65
  • 1
    What class? And, by "@Inject constructor", do you mean you annotated a constructor with @Inject? If so, the use of quotes is confusing. – steve Jun 24 '23 at 18:16
1

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

Mohammed Fathi
  • 1,237
  • 1
  • 14
  • 12
0

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

Dessy
  • 1