I am seeing this issue when trying to compile an Android project with Dagger2 (Google I/O 2018 sample app).
package javax.annotation.processing does not exist
import javax.annotation.processing.Generated;
I have tried the several solutions mentioned in the issues and stack overflow for resolving javax.annoation.Generated but not having any luck. Note the annotation is in the javax.annotation.processing package.
Are you using -source 9 in your compilation (perhaps implicitly)? What do you get if you run javac -version?
Are you using
-source 9in your compilation (perhaps implicitly)? What do you get if you runjavac -version?
Same issue on my teamcity CI server (clean assembleDebug).
javac -version
javac 1.8.0_181
But on local PC works fine
$ javac -version
javac 1.8.0_162
Dependencies:
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"
where
dagger_version = '2.16'
Error
[Step 1/2] :app:compileDebugJavaWithJavac
package javax.annotation.processing does not exist
[19:54:12][:app:compileDebugJavaWithJavac] import javax.annotation.processing.Generated;
...
error: cannot find symbol
[19:54:12][:app:compileDebugJavaWithJavac] @Generated
I am using (for Android)
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
I have also manually tried setting JAVA_HOME to jdk1.8 and jdk9 - same result.
My issue turned out to be related to JDK9 - explicitly using JDK 1.8 resolved the issue for me. ¯\_(ツ)_/¯
Add the following to gradle.properties
org.gradle.java.home={PATH TO JAVA 8}
Note setting JAVA_HOME did not work for me
My issue turned out to be related to JDK9 - explicitly using JDK 1.8 resolved the issue for me. ¯_(ツ)_/¯
_Add the following to gradle.properties_
org.gradle.java.home={PATH TO JAVA 8}Note setting JAVA_HOME did not work for me
Thank you. I checked my environment and found jdk11 and jdk8. Uninstall and reinstall only jdk8 removed this error.
I am seeing the same issue when trying to compile with JDK10:
package javax.annotation.processing does not exist
import javax.annotation.processing.Generated;
Fwiw, with 2.14 (using auto-common 0.9), Dagger will use @javax.annotation.processing.Generated unless --release 8 is used (in which case @javax.annotation.Generated will be used instead):
tasks.withType(JavaCompile) {
options.compilerArgs += [ "--release", "8" ]
}
From 2.15 onward (using auto-common 0.10), Dagger will also respect -source 8 -target 8, i.e. Gradle's sourceCompatibility and targetCompatibility.
I have created a simple android application written in kotlin with an empty dagger component:
@Component
interface AppComponent { }
apply plugin: 'kotlin-kapt'
dependencies {
implementation 'com.google.dagger:dagger:2.19'
kapt 'com.google.dagger:dagger-compiler:2.19'
}
When trying to compile with dagger 2.19 and JDK10 dagger adds javax.annotation.processing.Generated annotation to DaggerAppComponent class and compilation fails with:
```
error: package javax.annotation.processing does not exist
error: cannot find symbol @Generated
````
Compiling with JDK8 works fine. There is no @Generated annotation added. When I switch to dagger 2.13 it does not add @Generated for both JDK10 and JDK8.
there is no way to make it work with Java 11?
My issue turned out to be related to JDK9 - explicitly using JDK 1.8 resolved the issue for me. ¯_(ツ)_/¯
_Add the following to gradle.properties_
org.gradle.java.home={PATH TO JAVA 8}Note setting JAVA_HOME did not work for me
just in case, if you don't want to put it to gradle.properties, you can use gradlew TASK_NAME -Dorg.gradle.java.home="C:\Program Files\Android\Android Studio\jre"
. This is useful for CI or if several people work on the same project.
From 2.15 onward (using auto-common 0.10), Dagger will also respect -source 8 -target 8, i.e. Gradle's sourceCompatibility and targetCompatibility.
Unfortunately, it doesn't work for android projects. Any tip how we can compile android, jdk9+ and dagger?
Unfortunately, it doesn't work for android projects. Any tip how we can compile android, jdk9+ and dagger?
Manually create Generated interface in your project. There could be package exists in another module: java.compiler error if adding in android app module, but creating in android-library module (and then adding it to main via implementation project(':module-generated')) works fine.
I've uploaded package with such class to JCenter https://github.com/pengrad/jdk9-deps
Now it's possible to just add this gradle dependency and it compiles with JDK11:
compileOnly 'com.github.pengrad:jdk9-deps:1.0'
Let's converge on #1449 which seems to be the same, and advanced pretty quickly. In particular it seems like there's a kapt bug that will be linked there.
Unfortunately, it doesn't work for android projects. Any tip how we can compile android, jdk9+ and dagger?
Manually create
Generatedinterface in your project. There could bepackage exists in another module: java.compilererror if adding in android app module, but creating in android-library module (and then adding it to main viaimplementation project(':module-generated')) works fine.I've uploaded package with such class to JCenter https://github.com/pengrad/jdk9-deps
Now it's possible to just add this gradle dependency and it compiles with JDK11:
compileOnly 'com.github.pengrad:jdk9-deps:1.0'
It work for me. Thank you so much!
Thanks a lot @pengrad , I think I'm very close.
Having the same issue with Intellij 2020.* and Android Studio 4.2 Preview and Dagger 2.22
My team doesn't approve the external dependency of com.github.pengrad:jdk9-deps:1.0 so I went ahead and create a "Android Library" project called "javax-generated" with 1 single class like the one in your repo:
package javax.annotation.processing;
public @interface Generated {
String[] value();
String date() default "";
String comments() default "";
}
It's all well and good in my library modules, however, it's not working for my :app module:
implementation(project(':javax-generated')) givese: /Users/ericn/AndroidStudioProjects/Folder/Project/app/build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r/javax/annotation/processing/R.java:7: error: package exists in another module: java.compiler
package javax.annotation.processing;
compileOnly(project(':javax-generated')) givesAndroid dependency 'project :javax-generated' is set to compileOnly/provided which is not supported
Any idea what I'm missing?
@ericntd I am facing the same problems on Android Studio 4.2 Preview and Dagger 2.22.
I was not able to use this com.github.pengrad:jdk9-deps:1.0 external dependency inside my project - gradle complained that javax annotation is still missing.
I was trying with: compileOnly("javax.annotation:jsr250-api:1.0") dependency, which provide official JSR250 annotations, but with no luck.
The issue seems to have gone away with Android Studio 4.2 Canary 14 @MichalDanielDobrzanski
The issue seems to have gone away with Android Studio 4.2 Canary 14 @MichalDanielDobrzanski
Having same issue with Canary 14
Most helpful comment
Manually create
Generatedinterface in your project. There could bepackage exists in another module: java.compilererror if adding in android app module, but creating in android-library module (and then adding it to main viaimplementation project(':module-generated')) works fine.I've uploaded package with such class to JCenter https://github.com/pengrad/jdk9-deps
Now it's possible to just add this gradle dependency and it compiles with JDK11:
compileOnly 'com.github.pengrad:jdk9-deps:1.0'