Bogdan Zurac
Bogdan Zurac

Reputation: 6451

Current JDK version 1.8 has a bug that prevents Room from being incremental

We're trying to improve the build times of our multi-module Android app and we've reached the point where we tried to enable incremental KAPT annotation processing compilation.

gradle.properties:

org.gradle.daemon=true
org.gradle.caching=true
org.gradle.parallel=true

kapt.incremental.apt=true
kapt.use.worker.api=true
kapt.include.compile.classpath=false

android.databinding.incremental=true

build.gradle (inside each module that uses Room):

kapt {
    arguments {
        arg("room.incremental", "true")
    }
}

However, while trying to benchmark the build times using gradlew assemble -scan command, Gradle throws the following error:

warning: Current JDK version 1.8.0_201-b09 has a bug (https://bugs.openjdk.java.net/browse/JDK-8007720) that prevents Room from being incremental. Consider using JDK 11+ or the embedded JDK shipped with Android Studio 3.5+.
ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1
[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).

I've tried to set Open JDK 11 as the default JDK for the project in the Project Structure window, but it didn't work, it complained about it not being JDK 8. Any ideas what's wrong with this setup?

Upvotes: 24

Views: 12069

Answers (5)

javakam
javakam

Reputation: 120

Use Room 2.2.5 not 2.2.6

kapt "androidx.room:room-compiler:2.2.5"
implementation "androidx.room:room-runtime:2.2.5"
implementation "androidx.room:room-ktx:2.2.5"

Upvotes: 1

Coffe Milk
Coffe Milk

Reputation: 31

Go to Project Structure > SDK Location, then Gradle settings.

Set gradle jdk

Upvotes: 2

CoolMind
CoolMind

Reputation: 28809

When compiling, it showed me a warning:

Current JDK version has a bug (https://bugs.openjdk.java.net/browse/JDK-8007720) that prevents Room from being incremental. Consider using JDK 11+ or the embedded JDK shipped with Android Studio 3.5+.Note: 1 Wrote GeneratedAppGlideModule with: [][WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).

Then I downloaded JDK 8 (8u261) from the Oracle site (it requies registration, so look for a direct link).

Installed it, changed JAVA_HOME system variable to a new path:

enter image description here

Then recompiled the app. Even restart wasn't required.

UPDATE

After a month I again saw the same warning. Then read the accepted answer and found Java embedded with Android Studio: C:\Program Files\Android\Android Studio\jre.

File > Project Structure..., then SDK Location, and in the field JDK location wrote that path. Restarted AS.

Upvotes: 4

kollesnica power
kollesnica power

Reputation: 246

Setting $JAVA_HOME to /Applications/AndroidStudio.app/Contents/jre/jdk/Contents/Home for my shell helped me.

Upvotes: 0

Doni
Doni

Reputation: 616

you will need to using JDK embedded with AS to solve this. make sure to use AS 3.5 above. On project structure -> SDK location make sure jdk is pointed to jdk shipped with AS. /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home Then you will need to restart your AS.

If you running from terminal make sure $JAVA_HOME contains correct path.

I guess Android studio not supporting JDK 11 yet. I also tried to use latest JDK 8 (231, which AS 3.5 using 202) but it causing this issue.

Upvotes: 15

Related Questions