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?

Bogdan Zurac
  • 6,348
  • 11
  • 48
  • 96
  • Have you tried using the JDK embedded with Android Studio? – EpicPandaForce Nov 12 '19 at 16:49
  • 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. – DanyBoricua Nov 12 '19 at 18:15
  • @EpicPandaForce 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. – Bogdan Zurac Nov 13 '19 at 06:54

5 Answers5

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.

Doni
  • 576
  • 6
  • 9
  • 2
    I'm already using the embedded SDK, but that's Java 8. So it doesn't help. – Bogdan Zurac Nov 13 '19 at 08:12
  • i think yours `1.8.0_201-b0` , it should not beta version there, mine are 202 – Doni Nov 14 '19 at 08:51
  • So I don't understand, are you encountering the error I mentioned in the question or not? – Bogdan Zurac Nov 14 '19 at 15:41
  • 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-5587405 – Doni Nov 15 '19 at 16:20
  • This one is working: https://scans.gradle.com/s/qhvdmbsh5b2h6#infrastructure But using this one not working: https://scans.gradle.com/s/uqatyhc5f7lpu#infrastructure – Doni Nov 15 '19 at 16:28
  • 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... – Bogdan Zurac Nov 19 '19 at 13:11
  • 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. – Doni Nov 19 '19 at 14:38
  • 2
    See https://stackoverflow.com/questions/47728646/how-to-find-out-the-embedded-jdk-version-of-android-studio/47728957 for Embedded JDK path. (C:\Program Files\Android\Android Studio\jre) – CoolMind Sep 08 '20 at 08:43
  • 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 (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+.[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC). ``` – Akbolat SSS Jun 07 '21 at 10:20
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.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
  • Hmmm I'm getting this error too and I can't figure out how to fix. The path is the same as yours https://stackoverflow.com/q/67408778/11110509 – DIRTY DAVE May 05 '21 at 21:16
  • 1
    @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. – CoolMind May 06 '21 at 08:01
  • The path should be included in the answer above. – Lance Jun 24 '21 at 16:26
  • @Lance, sorry, what path? You can edit any answer if you wish. – CoolMind Jun 24 '21 at 16:38
  • @CoolMind - The path you mentioned in your answer should be mentioned to the accepted answer. – Lance Jun 24 '21 at 16:48
  • @Lance, agree with you, thanks! But in this case his solution will get points, and my won't :). – CoolMind Jun 24 '21 at 18:53
2

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

Set gradle jdk

gurkan
  • 884
  • 4
  • 16
  • 25
Coffe Milk
  • 21
  • 3
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"
javakam
  • 127
  • 1
  • 5
0

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