Janusz
Janusz

Reputation: 189484

Release build fails on Room generated classes: javax.annotation does not exist

I have a java project that builds fine in Android Studio and on the CI server.

Building a release version with gradle on the terminal fails though. I get the following output:

Database_Impl.java:42: error: package javax.annotation does not exist

Database_Impl.java:44: error: cannot find symbol
@Generated("androidx.room.RoomProcessor")

Some similar issues with Dagger suggests that this is a problem with the Java version of the build system.

I'm using a Mac and my javac version is: 10.0.2

Upvotes: 5

Views: 1608

Answers (2)

Janusz
Janusz

Reputation: 189484

This seems to be related to the Java version that is active on your machine.

There is a similar bug ticket with Dagger: https://github.com/google/dagger/issues/1449

The result of the discussion is that this is a bug in KAPT: https://youtrack.jetbrains.com/issue/KT-32804

The workaround is to put

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")
        }
    }
}

at the end of the build file of the affected module.

Upvotes: 2

smbdy
smbdy

Reputation: 95

I had the same issue and adding implementation "javax.annotation:jsr250-api:1.0" to build.gradle dependencies helped.

Upvotes: 5

Related Questions