问题
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:

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
回答1:
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.
回答2:
Close Visual Studio
-- at least this was the problem in my case.
and/or any other memory intensive program.
回答3:
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
回答4:
I had the same problem too. Try to run command line with administrative privileges.
回答5:
just solved this problem in windows 8.1 and windows 7. Here is what I did:
- Uninstall everything that is java related in your Programs and Features in control panel
- 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
- Download and install the latest Java SDK from here
- 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.
回答6:
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+).
回答7:
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
回答8:
In Environment variables, add a system variable _JAVA_OPTIONS
having the value -Xmx512M
.
回答9:
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.
回答10:
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.
回答11:
This error happens to me from time to time. I fix this by running the program "SDK Manager" in ANDROID_HOME folder.
回答12:
I got this error because I didn't have a 32-bit JDK installed. Installed that, restarted and that fixed it.
回答13:
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
回答14:
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.
回答15:
Install 64bit version of Java JDK and point JAVA_HOME to the install dictionary.
回答16:
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
回答17:
You need to allocate memory by setting two environment variables:
_JAVA_OPTIONS
with value-Xmx2048M
, to set up how much memory Java usesGRADLE_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.
来源:https://stackoverflow.com/questions/30384375/vm-error-while-build-cordova-phonegap