17
votes

I got this error while i tried to create a Cordova PhoneGap application, and in the final step while I use the build command

cordova build android

I got this error:

enter image description here

Error

    
D:\rmapp>cordova run android
Running command: D:\rmapp\platforms\android\cordova\run.bat
ANDROID_HOME=D:\Android\sdk
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_71
WARNING : No target specified, deploying to device '192.168.56.100:5555'.
Running: D:\rmapp\platforms\android\gradlew cdvBuildDebug -b D:\rmapp\platform
s\android\build.gradle -PcdvBuildArch=x86 -Dorg.gradle.daemon=true

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:\rmapp\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                          ^
Error code 1 for command: cmd with args: /s /c "D:\rmapp\platforms\android\grad
lew cdvBuildDebug -b D:\rmapp\platforms\android\build.gradle -PcdvBuildArch=x86
 -Dorg.gradle.daemon=true"
ERROR running one or more of the platforms: Error: D:\rmapp\platforms\android\c
ordova\run.bat: Command failed with exit code 1
You may not have the required environment or OS to run this project

17
Please paste your error codes, not screenshots of code. That way in the future people who look up their error codes can find relevant threads.Charles Clayton
facing this same error with generator-m projectIsmailS
worked somehow 3rd time. Might be I wasn't connected to internet. 3rd time it downloaded loads of files from repo1.maven.org/maven2/com/android/tools and then installed app on device successfully.IsmailS
or may be device screen wasn't active. Not sure if that would affectIsmailS

17 Answers

20
votes

Your system can not provide enough continuous memory space for the jvm and causes the problem.

Here is what works for me:

Add an environment variable GRADLE_OPTS with the value of -Dorg.gradle.jvmargs=-Xmx512m

You can use -Xmx1g if you have more memory space available.

8
votes

Close Visual Studio -- at least this was the problem in my case.

and/or any other memory intensive program.

5
votes

My JAVA_HOME was defaulting to the x86 version. Adding a new JAVA_HOME variable in the System env variable and pointing it to the x64 version worked for me. This was the path I ended up with:

C:\Program Files\Java\jdk1.8.0_162

3
votes

I had the same problem too. Try to run command line with administrative privileges.

3
votes

just solved this problem in windows 8.1 and windows 7. Here is what I did:

  1. Uninstall everything that is java related in your Programs and Features in control panel
  2. check the following directory and delete the java folders: a. c:\users\\AppData\Local\Oracle b. c:\users\\AppData\LocalLow\Oracle c. c:\Program Files\Java d. C:\Program Files (x86)\Java e. C:\ProgramData\Oracle **IMPORTANT: only delete this folders after successfully uninstalling all java entries in control panel > Programs and Features
  3. Download and install the latest Java SDK from here
  4. After all you are done go to cmd(run as admin) and try to build again

conclusion: from what I understand, I do not have java properly configured/installed in my machine. so a clean install of everything is what solved my problem.

3
votes

I got this error even if I used 2 gigs (-Dorg.gradle.jvmargs=-Xmx2048m), but it started to work when I changed JAVA_HOME to a 64-bit JDK directory. Using a higher version of Java might help also (1.8+).

3
votes

Change argument -Xmx20484m to 1024 at line:

args.push('-Dorg.gradle.jvmargs=-Xmx1024m'); 

in your project file

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

. It's work for me

https://forum.ionicframework.com/t/build-failed-unable-start-the-daemon-process/72171

It work for me in eclipce phonegap plugin

2
votes

In Environment variables, add a system variable _JAVA_OPTIONS having the value -Xmx512M.

2
votes

Run the following command in CLI with admin right.

>export _JAVA_OPTIONS="-Xmx256M"

This happens to me on machines with a lot of ram, but with lower memory ulimits. Java decides to allocate a big heap because it detects the ram in the machine, but it's not allowed to allocate it because of ulimits.

1
votes

I had the same problem while I was working on Cordova.

As mentioned in this post, it looks like the heap is not allocated and so the JVM isn't initialized.

Try to free your system cache and then try building the project.

1
votes

This error happens to me from time to time. I fix this by running the program "SDK Manager" in ANDROID_HOME folder.

1
votes

I got this error because I didn't have a 32-bit JDK installed. Installed that, restarted and that fixed it.

1
votes

My solution was to just install the new Java SDK. I also had to change my JAVA_HOME Path to point to that new SDK

1
votes

I had had the same problem with my cordova project when I have installed the last version of JDK 1.8.0.121.

To solve the problem, I have uninstalled all my JDK versions (1.6, 1.7, 1.8..) and just installed the last version.

1
votes

Install 64bit version of Java JDK and point JAVA_HOME to the install dictionary.

0
votes

I had a very similar problem that sometimes logged this JAVAC error and other times logged device connection problems or plugin not correctly installed. Ex:

Failed to run "javac -version"

Execute program failed with exit code 3221225794.

I successfully fixed it by running the following command that fixes all DLL problems on Windows, and then restarting the computer. From powershell, admin may be required:

sfc /scannow
-1
votes

You need to allocate memory by setting two environment variables:

  • _JAVA_OPTIONS with value -Xmx2048M, to set up how much memory Java uses
  • GRADLE_OPTS with value -Dorg.gradle.jvmargs=-Xmx2048m, to set up how much memory Gradle uses (this can be specified by per project basis through [PROJECT PATH]\platforms\android\cordova\lib\builders\GradleBuilder.js path, although by default it's setup to be 2GB atm)

If cordova complains with Failed to run "javac -version" change the memory in _JAVA_OPTIONS for something lower.