dagger: @Generated not found *javax.annotation.processing.Generated*
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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 37
- Comments: 40
Commits related to this issue
- Android updates: Switching from File to FileDescriptor due to permission issues. Updates in typings. — committed to AlexMiniApps/cordova-plugin-video-editor by AlexMiniApps 4 years ago
- Pass Java source version for KAPT. This is required such that annotation processors generate source that matches the target version. For example see: https://github.com/google/dagger/issues/1339 — committed to jongerrish/rules_kotlin by jongerrish 4 years ago
- Java builder flow fixes (#408) * Fix breakages in experimental_use_java_builder flow. Make examples/android use custom toolchain with both experimental_use_abi_jars and experimental_use_java_builder... — committed to bazelbuild/rules_kotlin by jongerrish 4 years ago
- Java builder flow fixes (#408) * Fix breakages in experimental_use_java_builder flow. Make examples/android use custom toolchain with both experimental_use_abi_jars and experimental_use_java_builder... — committed to richmowd411/Rules-Kotlin by richmowd411 4 years ago
Manually create
Generated
interface in your project. There could bepackage 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 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'
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
Note setting JAVA_HOME did not work for me
Had this issue with Android Studio 4.2. Tried solutions from above and what finally worked was to update Kotlin from 1.3.50 to 1.4.31.
I am using (for Android)
I have also manually tried setting JAVA_HOME to jdk1.8 and jdk9 - same result.
This
And this, did it for me on Android Studio 4.2.1. Thank you very very very much.
Having same issue with Canary 14
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.I recently had this issue on a project when migrating to java 11. I figured out the issue was caused by me using an outdated version of assisted-inject. I made it work by updating dagger to
2.35.1
and both of my assisted-inject dependencies to0.8.1
:Also, make sure to update gradle plugin to 4.2.0 according to this https://developer.android.com/studio/releases/gradle-plugin#4-2-0
@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.with the stable Android Studio 4.2, I have the same problem with Dagger 2.25, after I updated dagger to latest version, the problem solved
this add in dependency.
// implementation ‘javax.annotation:javax.annotation-api:1.3.2’
4.2 preview same issue. if i use 4.0 works…whats the issue?
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):From 2.15 onward (using auto-common 0.10), Dagger will also respect
-source 8 -target 8
, i.e. Gradle’ssourceCompatibility
andtargetCompatibility
.I fixed the issue with
Just add this dependency
implementation ‘javax.annotation:javax.annotation-api:1.3.2’
I have this issue this morning and after spent hours on trying different things and Java versions, this fixed my problem. So, add
compileOnly 'com.github.pengrad:jdk9-deps:1.0'
to my build.gradle files fix the issue.I get this on a very under-developed project, fix was to update Dagger from 2.14.1 to 2.25.4 (before Android X as my project is not upgraded yet). About time to do that methinks.
If you are updating your android studio and using arctic fox (2020.3.1) don’t forget to update the gradle plugin.
classpath "com.android.tools.build:gradle:7.0.0-alpha14"
Thank you. I checked my environment and found jdk11 and jdk8. Uninstall and reinstall only jdk8 removed this error.