Cannot find symbol class "Generated" for Dagger 2
Solution 1
Read this for more info: https://github.com/google/dagger/issues/95
Basically, the solution is to do what you've already done which is include the glassfish javax annotation library.
Solution 2
TL;DR use Dagger >= 2.1
Alex is right, but it's better to add JSR250 dependency instead of GlassFish
provided 'javax.annotation:jsr250-api:1.0'
or for the latest gradle plugin:
compileOnly 'javax.annotation:jsr250-api:1.0'
Solution 3
This happens if your JAVA_HOME points to JAVA version 9 or 10. Switching JAVA_HOME to Java 8 fixes the problem and you will not need that extra dependency.
Solution 4
I downgraded my JVM to Java 8 and running gradle build
was successful in my Android application using Dagger 2.
Related videos on Youtube
x-treme
Updated on November 13, 2020Comments
-
x-treme over 3 years
I just started doing dependency injection using
Dagger 2
. When I spun up mymodules
,components
and tried to build my application,gradle
threw the errorError:(4, 24) error: cannot find symbol class Generated
I dug into it and found that the error is in one of the classes
Dagger
generates to doDI
. The particular class that's missing wasjavax.annotation.Generated
and the line throwing the error is the line that anntotates aDagger
generated class as@Generated("dagger.internal.codegen.ComponentProcessor")
This question helped in finding the solution which is to add the
javax
package as a dependency by adding the linecompile 'org.glassfish:javax.annotation:10.0-b28'
to my gradle build file. This led to a successful build.My question is, why is that not added as a transitive dependency for
Dagger
or why hasn't anyone else faced this particular issue (I assume so, since I couldn't find any question here regarding this?-
FrozenCow about 9 yearsI had the same problem. I 'solved' it by adding: compile 'javax.annotation:jsr250-api:1.0' I'm not sure why this is still a problem nor whether this is the right solution.
-
Alex Fu about 9 yearsFor more info on this matter, you can read the thread here: github.com/google/dagger/issues/95
-
x-treme about 9 years@AlexFu - Great!! Do you mind posting it as an answer ?
-
-
filthy_wizard over 8 yearsstill cant recognise my generated "Dagger" prefix component?. it was doing it a minute ago! lol
-
IgorGanapolsky over 8 yearsWhy is jsr better than glassfish annotation?
-
tomrozb over 8 years@IgorGanapolsky GlassFish is an application server, so the annotation library is strictly for its purposes. JSR250 is just a standard and contains only some annotations for general purpose use.
-
IgorGanapolsky over 8 yearsThen why are other android developers using Glassfish in their gradle builds? Is there evidence that it is inferior and android devs should stay away from it?
-
tomrozb over 8 years@IgorGanapolsky because this is just an annotation library so you can use it in any project. JSR250 is just a transitive dependency in this library, you can check it here: central.maven.org/maven2/org/glassfish/javax.annotation/3.1.1/… For sure you don't need javaee-api annotations in your Android project, but it's also the dependency of the GlassFish annotation library.
-
IgorGanapolsky over 8 years@tomrozb So I should use both in my gradle build?
-
tomrozb over 8 years@IgorGanapolsky definitely not. Just use one in Android projects.
-
fruqi almost 7 yearsThis solution saves my time.
-
Achmad Naufal Syafiq over 6 yearsgot this issue in Dagger 2.14
-
Amir Ziarati almost 6 yearsConfiguration 'provided' is obsolete and has been replaced with 'compileOnly'
-
Wahib Ul Haq over 5 years@AchmadNaufalSyafiq how did you fix it? I am facing same in Dagger 2.16
-
LiuWenbin_NO. over 2 yearsThis works for me.