build: Unable to start the daemon process. Could not reserve enough space for 1500000KB object heap
To Reproduce
- npm install -g @bubblewrap/cli
- bubblewrap init --manifest ....
- ? Do you want Bubblewrap to install JDK? Y
- ? Do you want Bubblewrap to install Android SDK? Y
- (complete setup)
- bubblewrap build
(this is using VS Code's PowerShell terminal, but the same happens if I use CMD separately)
Error
FAILURE: Build failed with an exception.
- What went wrong: Unable to start the daemon process. This problem might be caused by incorrect configuration of the daemon. For example, an unrecognized jvm option is used. Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.5/userguide/gradle_daemon.html Process command line: C:\Users\...\.bubblewrap\jdk\jdk8u265-b01\bin\java.exe -Xmx1536m -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\...\.gradle\wrapper\dists\gradle-6.5-bin\6nifqtx7604sqp1q6g8wikw7p\gradle-6.5\lib\gradle-launcher-6.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.5 Please read the following process output to find out more:
Error occurred during initialization of VM Could not reserve enough space for 1500000KB object heap
I also tried increasing org.gradle.jvmargs=-Xmx1536m
I have enough available RAM
Desktop:
- OS: Windows 10
- Using: VS Code or CMD
Seems that commenting out:
#org.gradle.jvmargs=-Xmx1536m
in gradle.properties
resolves the issue...
Unfortunately, this is an issue with the JVM on Windows, and there isn't much that can be done in Bubblewrap.
It seems the JVM requires contiguous memory addresses when allocating memory. Even though the machine may have enough memory, and enough memory free, the JVM can fail to allocate if the memory is fragmented. There are more details in this StackOverflow question: https://stackoverflow.com/questions/171205/java-maximum-memory-on-windows-xp/497757#497757
The -Xmx1536 parameter is the default used by Android Studio when creating Android projects. Removing -Xmx1536 worked in this case, but is unlikely to work in all cases for 2 reasons:
- If Gradle actually needs that amount of memory, it will still be unable to allocate it and the build will fail (at a later time).
- It may still be impossible to allocate smaller chunks of memory.
Rebooting Windows is a solution known to help in these cases too.
I was getting this error when trying to run bubblewrap build after a previous failed build attempt
I noticed that sometimes the jdk process stays opened and you have to manually end it in windows task manager before trying again.
in gradle.properties
commented this line:
# org.gradle.jvmargs=-Xmx1536m
and added this line:
org.gradle.jvmargs=-XX\:MaxHeapSize\=256m -Xmx256m
after that bubblewrap build works for me