Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 953
Janusz Avatar asked Dec 18 '19 13:12

Janusz


2 Answers

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

like image 106
smbdy Avatar answered Oct 16 '22 17:10

smbdy


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.

like image 39
Janusz Avatar answered Oct 16 '22 18:10

Janusz