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

5

24

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.

  • Android Studio version: v3.5.2
  • Room version: v2.2.1
  • Gradle version: v5.4.6
  • Android Gradle Plugin version: v3.5.2
  • Kotlin version: v1.3.50

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?

Landman answered 12/11, 2019 at 16:10 Comment(3)
Have you tried using the JDK embedded with Android Studio?Triform
If you are running gradlew assemble -scan from the command line make sure your JAVA_HOME environment variable also points to the same JDK11 you setup in Android Studio.Interpret
@Triform yes, same problem. Dany, I couldn't even set up JDK 11 in AS, it didn't let me choose the JDK 11 folder location in the Project Structure window.Landman
O
15

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.

Outtalk answered 13/11, 2019 at 7:32 Comment(9)
I'm already using the embedded SDK, but that's Java 8. So it doesn't help.Landman
i think yours 1.8.0_201-b0 , it should not beta version there, mine are 202Outtalk
So I don't understand, are you encountering the error I mentioned in the question or not?Landman
yes i was got this when using JDK 231 downloaded from oracle web. Then able to solve this by switching back to JDK from android studio. Are you running this from terminal or press play on Android Studio ? Mine looks like this JetBrains s.r.o OpenJDK Runtime Environment 1.8.0_202-release-1483-b49-5587405Outtalk
This one is working: scans.gradle.com/s/qhvdmbsh5b2h6#infrastructure But using this one not working: scans.gradle.com/s/uqatyhc5f7lpu#infrastructureOuttalk
The embedded JDK from AS seems to work indeed, even when specifying it as $JAVA_HOME in any terminal. Reset it to default in AS and now it seems to work. Guess something was messed up in AS for whatever reason.. Good. But we still have a problem in case we want to build our app from the CI. We would need to have the embedded SDK from AS up on the CI in order to fix this, which is really bad. This should work with any JDK version, not a IDE specific one...Landman
Yes something wrong there :/ . In most cases CI build won't have any benefit from incremental build. We disable incremental compilation and daemon on CI because in general CI will wipe out everything on each build. We only utilise remote cache for faster CI build.Outtalk
See #47729146 for Embedded JDK path. (C:\Program Files\Android\Android Studio\jre)Explant
Starting 4.2 Android Studio uses JDK 11 and brings it as embedded, but the warning still exists, here is what I get in the logs ``` > Task :app:kaptQaDebugKotlin warning: Current JDK version 11.0.8+10-b944.6916264 has a bug (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+.[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC). ```Diet
E
4

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.

Explant answered 17/8, 2020 at 15:39 Comment(6)
Hmmm I'm getting this error too and I can't figure out how to fix. The path is the same as yours https://mcmap.net/q/583541/-roomlibrary-current-jdk-version-1-8-0_221-b11-has-a-bug-https-bugs-openjdk-java-net-browse-jdk-8007720-that-prevents-room-from-being-incremental/11110509Otoplasty
@DIRTYDAVE, yes, JRE path works. I don't remember why I then changed to JDK again. Probably some small compiltation issues appeared. But you can retain JRE path, of course.Explant
The path should be included in the answer above.Vernal
@Lance, sorry, what path? You can edit any answer if you wish.Explant
@Explant - The path you mentioned in your answer should be mentioned to the accepted answer.Vernal
@Lance, agree with you, thanks! But in this case his solution will get points, and my won't :).Explant
P
2

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

Set gradle jdk

Polytrophic answered 9/8, 2021 at 8:49 Comment(0)
P
1

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"
Porter answered 19/8, 2021 at 2:51 Comment(0)
A
0

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

Aerodynamics answered 8/9, 2020 at 19:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.