dagger: error: cannot find symbol @Generated( ^

Building via Android Studio works fine, but if I call

./gradlew build

I get

error: cannot find symbol
@Generated(
 ^

all over the place. I’m using the latest version of dagger. My android project is set to Java 8 source. Calling java --version in my terminal tells me I have java 9 (which I’m not sure how, but I that’s besides the point). Any ideas what I should be doing? I’ve seen a bunch of mixed answers on stackoverflow, but adding a dependency feels weird. My system being on java 9 doesn’t make sense to me because I though Android Studio bundles it’s own version of the JDK.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 23
  • Comments: 32

Commits related to this issue

Most upvoted comments

I managed to work around this on a JDK 11 install by adding the following to the bottom of my affected modules’ build.gradle files. I imagine it would work in a subprojects.afterEvaluate block in the top-level build.gradle too.

    if (project.hasProperty('kapt')) {
        // Reference for 'kapt' DSL: https://kotlinlang.org/docs/reference/kapt.html#java-compiler-options
        kapt {
            // we expect this closure to run over a org.jetbrains.kotlin.gradle.plugin.KaptExtension
            javacOptions {
                option("-source", "8")
                option("-target", "8")
            }
        }
    }

In Kotlin 1.3.70 it’s fixed

Yes, that is the workaround for now. I have filed https://youtrack.jetbrains.com/issue/KT-32804 (FINALLY).

I’ll link the bug here once I file it.

On Fri, Mar 22, 2019 at 11:15 AM ColtonIdle notifications@github.com wrote:

Got it. I’ll keep my eyes out for a kotlin plugin update. Thank you

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/google/dagger/issues/1449#issuecomment-475660211, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEERcs15GnBlMjo852h7eLEUX85jzkks5vZPOqgaJpZM4cDs3Z .

You’ll need to use JDK 8 to build until the kapt bug is fixed. I’ll work on creating a sample and reporting it today.

On Fri, Mar 22, 2019 at 10:46 AM ColtonIdle notifications@github.com wrote:

I am indeed. Let me know what you think I should do, since I’m still a little confused. I’m assuming that I should just install the latest version of JDK 8 (or do I just need java8 runtime and not JDK) and set it as my system default.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/google/dagger/issues/1449#issuecomment-475648705, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEe5JVbF45rejJiu1IJGMiinfVgHiks5vZOy8gaJpZM4cDs3Z .

@pdecat No, it is not. I still see the problem on a project with 1.3.61 🤷‍♂

but I that’s besides the point

It isn’t. This is the cause. Dagger uses https://github.com/google/auto/blob/master/common/src/main/java/com/google/auto/common/GeneratedAnnotations.java#L54-L61 to pick which annotation to use which picks the wrong one for Android.

Android Studio bundles it’s own version of the JDK

To run itself as it’s a Java application. Not to run your code.

The same issue with Oracle JDK 13 and 1.3.61. I can confirm that adding: compileOnly "javax.annotation:javax.annotation-api:1.3.2" and

kapt { javacOptions { option("--source", "8")
    option("--target", "8") } }

fixed the issue. Btw the issue doesn’t exist with OpenJdk 11