I downloaded several sample projects from github that use dagger, e. g. Moxy sample project (trying to run github-sample) but everywhere there is the same error - «cannot find symbol class DaggerAppComponent». I did not make any changes in the projects just downloaded and tried to run them.
Gradle version - 3.1.2
AndroidStudio – 3.3
def dagger = '2.7'
implementation "com.google.dagger:dagger:$dagger"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger"
Does anybody has an idea how to fix it?
Adding the below dependency.
implementation 'com.google.dagger:dagger:2.x'
annotationProcessor 'com.google.dagger:dagger-compiler:2.x'
OR try this
annotationProcessor 'com.google.dagger:dagger-compiler:2.12'
This may not be directly related to what the original poster was looking for but posting this answer for anyone looking to solve a similar error. If you have converted some of your classes to Kotlin then use kapt instead of annotationProcessor in your build.gradle. It is kind of obvious looking back but took me a while to figure out why I'm getting the sysmbol not found error with DaggerAppComponenent without any other details.
Related
I have facing the following error while building the project. And unable to solve the same after trying it for whole day.
error: To use RxJava2 features, you must add `rxjava2` artifact from Room as a dependency. androidx.room:room-rxjava2:<version>
public abstract java.lang.Object clearAllBillers(#org.jetbrains.annotations.NotNull()
^
below are my dependancies inside the build.gradle
implementation("androidx.room:room-rxjava2:2.3.0")
implementation "androidx.room:room-runtime:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
kapt "androidx.room:room-compiler:2.3.0"
I have done trying already existing solutions such as upgrading
classpath 'com.android.tools.build:gradle:7.3.1'
Also tried to do invalidate cache and clean project.
Still not able to solve the issue.
Please help me if you have any idea to get it resolve.
Thanks in advance!!!❤️
Not sure why haven't you received an answer quicker (because this question has an easy solution)
you just need to add
implementation("androidx.room:room-rxjava2:2.4.3")
to your build.gradle (for your app or module)
(source)
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?
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"
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.
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.
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
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
I am having a problem where my build cannot find one of the androidx classes, specifically:
androidx.lifecycle.DefaultLifecycleObserver
Here are my gradle deps:
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
I don't have any other problems getting androidx classes, just this one.
I have tried to invalidate caches in android studio and restart with no luck. Also a build clean as well as a gradle sync.
I verified here:
https://developer.android.com/jetpack/androidx/migrate
The mapping of that class from the support library to androidx:
android.arch.lifecycle.DefaultLifecycleObserver ->
androidx.lifecycle.DefaultLifecycleObserver
Any ideas on why this is happening?
I think that's because you're missing one dependency:
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
Get the latest version of lifecycle-common-java8 here
See the documentation:
If you use Java 8 Language, then observe events with
DefaultLifecycleObserver. To include it you should add
"androidx.lifecycle:lifecycle-common-java8:" to your
build.gradle file.
I'm getting the next crash when I launch my Android app after adding the first Dagger module.
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/collect/ImmutableMap;
at com.sofaking.moonworshipper.DaggerAppComponent.getMapOfClassOfAndProviderOfFactoryOf(DaggerAppComponent.java:35)
at com.sofaking.moonworshipper.DaggerAppComponent.getDispatchingAndroidInjectorOfActivity(DaggerAppComponent.java:41)
at com.sofaking.moonworshipper.DaggerAppComponent.injectApp(DaggerAppComponent.java:64)
at com.sofaking.moonworshipper.DaggerAppComponent.inject(DaggerAppComponent.java:59)
at com.sofaking.moonworshipper.DaggerAppComponent.inject(DaggerAppComponent.java:16)
The issue seems to be identical to this one on GitHub:
https://github.com/google/dagger/issues/897
I understand that Dagger is trying to use Guava, although it shouldn't - But I'm not sure what to do to fix this. It's not a proguard issue.
I tried to include guava in my dependencies - which presented the next error while compiling:
Error: Program type already present: com.google.common.util.concurrent.internal.InternalFutures
which makes sense, as there are other libraries in my code which depend on guava.
implementation 'com.google.dagger:dagger:2.15'
kapt 'com.google.dagger:dagger-compiler:2.15'
compile 'com.google.dagger:dagger-android:2.15'
compile 'com.google.dagger:dagger-android-support:2.15'
kapt 'com.google.dagger:dagger-android-processor:2.15'
// tried adding this as well, didn't work
api 'com.google.guava:guava:27.0-android'
Edit: Here's tree of resolved dependecies: https://pastebin.com/RsPPjD6H
After seeing that Dagger depends on com.google.guava:guava:23.3-jre, I tried adding the next line in my Gradle build file:
api 'com.google.guava:guava:23.3-android'
And it works!
The word "compile" is not used anymore. Use "implementation" instead in your dependencies. I don't know if that is causing the issue but maybe.
I'm getting the following error while trying to use Work Manager. I've migrated my project to AndroidX and all other architecture components are working.
def work_version = "1.0.0-alpha02"
/* Work Manager for Background Tasks */
implementation "android.arch.work:work-runtime:$work_version"
implementation "android.arch.work:work-firebase:$work_version"
I'm quite sure I need some dependencies from the Support Library. But I have no clue which one's they are.
I've tried adding the annotations package since the error says it can't find a class file for RestrictTo$Scope. Still doesn't work.
implementation "com.android.support:support-annotations:28.0.0-alpha1"
You are including a reference to the wrong support library, you want the androidx one.
androidx.annotation
Look in
AndroidX refactoring
you will find
androidx.annotation:annotation:1.0.0-alpha1
to correspond with
com.android.support:support-annotations
Make sure that you have only libraries for one or the other kind in your dependencies (project wide).