12

When trying to create an android apk file using ionic and gradle, i get an 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 guide chapter on the daemon at http://gradle.org/docs/2
.2.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

D:\test\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                          ^
Error code 1 for command: cmd with args: /s /c "D:\test\platforms\android\gradle
w cdvBuildDebug -b D:\test\platforms\android\build.gradle -Dorg.gradle.daemon=tr
ue"
ERROR building one of the platforms: Error: D:\test\platforms\android\cordova\bu
ild.bat: Command failed with exit code 1
You may not have the required environment or OS to build this project
Error: D:\test\platforms\android\cordova\build.bat: Command failed with exit cod
e 1
    at ChildProcess.whenDone (C:\Users\9923\AppData\Roaming\npm\node_modules\cor
dova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

I am trying to do this on a Windows 7 Desktop. My Java memory settings is as below.

D:\test>java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize Threa
dStackSize"
     intx CompilerThreadStackSize                   = 0               {pd produc
t}
    uintx ErgoHeapSizeLimit                         = 0               {product}
    uintx HeapSizePerGCThread                       = 87241520        {product}
    uintx InitialHeapSize                          := 67108864        {product}
    uintx LargePageHeapSizeThreshold                = 134217728       {product}
    uintx MaxHeapSize                              := 1044381696      {product}
     intx ThreadStackSize                           = 0               {pd produc
t}
     intx VMThreadStackSize                         = 0               {pd produc
t}
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

I tried setting -Xms and -Xmx at numerous places, but the system is just not able to start it. How do i solve this problem?

I changed the

Added JAVA_OPTS in My Computer > Properties > Environment Variables
Added JAVA_OPTS in dx.bat in android SDK
Added JAVA_OPTS in build.bat inside application folder
Changed JAVA_OPTS in gradle.properties

Please help

2

6 Answers 6

20

Barlrog30's solution did not work for me, but inspired me.

Here is what works for me:

Set an environment vairable GRADLE_OPTS to the value of -Dorg.gradle.jvmargs=-Xmx512m

I am using:

Windows 7 64bit + Jdk 32bit + cordova 5.3.1
2
  • Did you mean "Barlrog30's solution did not work for you"?
    – aksappy
    Sep 28, 2015 at 6:46
  • 5
    Just to clarify, on the windows command prompt: set GRADLE_OPTS=-Dorg.gradle.jvmargs=-Xmx512m Jan 19, 2016 at 2:33
4

This issue was found to be environment specific. Posting the answer only to help those who might have this unfortunate problem.

The problem was solved by installing a 32 bit JDK on the 64 bit Windows 7.

Before installing

  1. Remove all the JRE and JDK installation by going to Application Manager
  2. Remove all environment variables pertaining to your old Java installation
  3. Update / Remove all the Java related entries from the Path variable. (Do not remove the path variable)
  4. Restart the system
  5. Install the downloaded JDK
  6. Go to Environment Variables and add the required keys
  7. Update the Path variable to include the JDK bin folder

I do not have a clue why this has happened, but the issue has been resolved.

2
  • 1
    I had to install the 64-bit JDK in my case (previously had the 32-bit). But this answer led me to the right solution!
    – lordjeb
    May 29, 2015 at 18:58
  • So, what is the real problem here? The default RAM of gradle is bigger than 3GB? Sep 24, 2015 at 0:43
1

I had the same problem. I read your answer and thought, "That seems like way too much work." So, I kept digging.

I found this answer: https://stackoverflow.com/a/9813900/3771976

It says to set an environment variable: GRADLE_OPTS=-Xmx512m

I had to increase the memory limit further to 1024, but it solved the problem.

Oracle Documentation for JVM Option

3
  • Let me try this once, what is the default do you know?
    – aksappy
    May 26, 2015 at 7:06
  • I added a link to the Oracle JVM Docs for this option. It appears the default depends on your environment. Further reading also shows that GRADLE_OPTS is exactly the same as JAVE_OPTS except that it is specific to the Gradle build system.
    – nbering
    May 26, 2015 at 10:51
  • I think it's also worth noting that I had no trouble until I added another Cordova plugin, and then all of a sudden this issue came up. So the memory required seems to be related to what you're building.
    – nbering
    May 26, 2015 at 11:18
0

Try uninstalling Intel® Hardware Accelerated Execution Manager and then try again.

1
  • 1
    you should comment it , or edit and improve your question Nov 18, 2015 at 6:11
0

In my case I just had to put all my environment variables for the Java Runtime Environment (JRE) and the Java Development Kit (JDK) to the 64 bit version.

To do so, I went to oracle's website, and simply downloaded the 64 bit JRE and JDKs.

During the installation I checked it was well installed in C:\Program Files\Java and not in C:\Program Files (x86)\Java,

Then I set the environnment variable:

 - JAVA_HOME: C:\Program Files\Java\jdk1.8.0_121
 - Path: "C:\Program Files\Java\jre1.8.0_121\bin" and "C:\Program Files\Java\jdk1.8.0_121\bin"

Hope it helps!

0

Change argument -Xmx2048m to 1024 or 512 at line:args.push('-Dorg.gradle.jvmargs=-Xmx1024m'); in your project file

platforms\android\cordova\lib\builders\GradleBuilder.js

It's work for me!!

Not the answer you're looking for? Browse other questions tagged or ask your own question.