Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • 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?

like image 503
Bogdan Zurac Avatar asked Nov 12 '19 16:11

Bogdan Zurac


3 Answers

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.

like image 175
Doni Avatar answered Nov 17 '22 11:11

Doni


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.

like image 4
CoolMind Avatar answered Nov 17 '22 12:11

CoolMind


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

Set gradle jdk

like image 2
Coffe Milk Avatar answered Nov 17 '22 12:11

Coffe Milk