26

When I build multi module java project using gradle 6.0,when I add >30 modules.Throw this error:

Gradle Daemon started in 2 s 267 ms

> Configure project :soa-misc
"/opt/dabai/tools/jdk1.8.0_211/jre/lib/ext/"
null
Expiring Daemon because JVM heap space is exhausted
Daemon will be stopped at the end of the build after running out of JVM memory
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Daemon is stopping immediately JVM garbage collector thrashing and after running out of JVM memory

What I am tried to add parameter in my $HOME/.gradle/gradle.properties:

org.gradle.jvmargs=-Xmx8096m -XX:MaxPermSize=8096m -XX:+HeapDumpOnOutOfMemoryError

But the problem not solved,what should I do to fix?

Dolphin
  • 29,069
  • 61
  • 260
  • 539

3 Answers3

62

I add gradle.properties file in my root project dir,and add this config:

org.gradle.jvmargs=-Xmx4096M

works. From the error message we can know the Daemon JVM spcace exhausted. This is the Gradle official docuemnt about this config:

Specifies the JVM arguments used for the Gradle Daemon. The setting is particularly useful for configuring JVM memory settings for build performance. This does not affect the JVM settings for the Gradle client VM. The default is -Xmx512m "-XX:MaxMetaspaceSize=256m".

Dolphin
  • 29,069
  • 61
  • 260
  • 539
  • 3
    If it doesn't work, also try adding `android:largeHeap="true"` in ` – Hamza Waleed Mar 16 '20 at 06:08
  • 1
    this was great when upgrading Gradle while going for Android Studio 4.0, thanks a bunch! –  Jun 02 '20 at 21:39
  • 1
    I have added the official document link so that you can know why change the config like this. @JCraine – Dolphin May 05 '22 at 02:07
  • @dolphin Thank you Dolphin! I deleted my comment to edit/resubmit right when you replied. I appreciate the follow up :) – JCraine May 05 '22 at 02:09
0

Note that if you can't modify the gradle.properties file for whatever reason (e.g. I modified a gitlab-ci.yml file's script for a CICD pipeline issue that couldn't be reproduced locally), you can use a command line flag (with a -D prefix) as referenced in the "official document" above by @Dolphin.

-Dorg.gradle.jvmargs=-Xmx4096M
entpnerd
  • 10,049
  • 8
  • 47
  • 68
-2

Maybe it will help other users as well.

I received, somewhat, this error when I did a gradlew clean on the android directory and forgot to go back with cd .. and I run the command of starting the app inside android directory when it shouldn't.

The solution is to go back from android directory and run the start command in the root directory of your app.

Gabriel Arghire
  • 1,992
  • 1
  • 21
  • 34