3

Hi we have a project with 30 productFlavors which I try to build with jenkins. Since we update (for Android Studio3) to : - gradle 3.0.0 - Build Tools 26.0.2

We get an out of memory exception in Lint :

   :app:lintUnexpected failure during lint analysis of null (this is a bug in lint or one of the libraries it depends on)
    `OutOfMemoryError:ByteStreams.toByteArray(ByteStreams.java:176)
Files.readFile(Files.java:182)←Files$FileByteSource.read(Files.java:153)
Files.toByteArray(Files.java:252)←LintClient.readBytes(LintClient.kt:249)
ClassEntry.addEntries(ClassEntry.java:216)
ClassEntry.fromClassPath(ClassEntry.java:120)
LintClient.createSuperClassMap(LintClient.kt:997)`

    You can set environment variable `LINT_PRINT_STACKTRACE=true` to dump a full stacktrace to stdout. java.lang.OutOfMemoryError: Java heap space  at 
    com.google.common.io.ByteStreams.toByteArray(ByteStreams.java:176)  at 
    com.google.common.io.Files.readFile(Files.java:182)     at 
    com.google.common.io.Files$FileByteSource.read(Files.java:153)  at 
    com.google.common.io.Files.toByteArray(Files.java:252)  at 
    com.android.tools.lint.client.api.LintClient.readBytes(LintClient.kt:249)

I increased the Gradle Memory (gradle.properties org.gradle.jvmargs=-Xmx3098M) with out success.

All productFlavors have the same java code. The result apk has different Images, Package Name, Languages and configuration.

The build run for 25 productFlavors until we get out of memory. With the ps command I see JVM options for client processes of Gradle Daemon like : java -Djava.awt.headless=true -Xmx64M com.google.devtools.build.android.desugar.Desugar I have no idea how to set JVM options this child processes (Android Tools)

Maybe it is al memory leak in the gradle daemon. I observe in the first 20 build of my productFlavors the head is about 2G and than it increase to 3G and the gradle deamon jvm is doing GC all the time...

Any idea or suggestions ?

Regards

Gugelhupf
  • 943
  • 12
  • 16

1 Answers1

2

I was in same situation as you. After upgrade android gradle (to 3.0.0) & build tool (to 26.0.2), I faced out of memory error while gradle build on my slave ubuntu machine in Jenkins (but while task transformClassesWithDexBuilderForRelease). Meanwhile, I upgraded version of gradle from 3.5 to 4.3.0. Since my code has not changed, I'm thinking that there is a problem which can cause memory leak in one of these updates.

Here is workaround solution:

export _JAVA_OPTIONS="-Xms2048m -XX:-UseGCOverheadLimit -XX:+UseConcMarkSweepGC" 
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"

(referred: https://stackoverflow.com/a/18900271/5663292 & https://stackoverflow.com/a/35964827/5663292)

EDIT

After a couple of build, I've seem same error even if I increased the memory until 14gb :) But I resolved the problem by adding a line to my gradle.properties file:

org.gradle.jvmargs=-Xmx4096m
Sercan özen
  • 161
  • 12
  • I also increase the JAVA VM memor and I am able to build my application again. My observation is an increase of loaded classes for every product flavor . Also I create an Issue at google https://issuetracker.google.com/issues/68364312 – Gugelhupf Nov 17 '17 at 08:07
  • @Gugelhupf Yes, you're right. You can see same error after a couple of build even if you increased the memory of JVM (I seen it :). But If you add this block (org.gradle.jvmargs=-Xmx4096m) to your gradle.properties , everything will work as before update. And you can also remove _JAVA_OPTIONS & JACK_SERVER_VM_ARGUMENTS...etc properties. – Sercan özen Nov 17 '17 at 14:11