Cordova Could not reserve enough space for 2097152KB object heap
Asked Answered
N

10

47

I am new to cordova and am trying to create an android HelloWold project.

When I use cordova platforms add android, it throws some exception:

D:\CordovaSpace\helloWorld>cordova platforms add android
Adding android project...
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: com.example.helloworld
        Name: HelloWorld
        Activity: MainActivity
        Android target: android-24
Subproject Path: CordovaLib
Android project created with [email protected]
Installing "cordova-plugin-whitelist" for android
ANDROID_HOME=D:\Java_Android_SDK\android_sdk
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_73
Subproject Path: CordovaLib
Starting a new Gradle Daemon for this build (subsequent builds will be faster).

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 https://docs.gradle.org/2.14.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 2097152KB object heap


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Failed to install 'cordova-plugin-whitelist':Error: cmd: Command failed with exit code 1
    at ChildProcess.whenDone (D:\CordovaSpace\helloWorld\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:850:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
Error: cmd: Command failed with exit code 1
Needlepoint answered 19/12, 2016 at 6:32 Comment(8)
shall we send you some more RAM?Insensate
you lack of 2 GB ram I thinkDeegan
So what should I do ? (Please forgive me that I can not speak English very well)Needlepoint
buy more RAM? How much do you have at the moment?Deegan
I check my Computer Ram hava about 3.84 GNeedlepoint
looks like it is not enoughDeegan
@ScaryWombat So easy to be sarcastic! My system has 9Gb of free memory and I still get the same problem.Phoebephoebus
@Phoebephoebus Yes, sorry humour does not scale well on the internet.Insensate
H
111

Try again after increasing your Java VM(?) memory size.

Here is how to fix it on a Windows platform:

Go to Start -> Control Panel -> System -> Advanced(tab) -> Environment Variables -> System Variables -> New:
Variable name: _JAVA_OPTIONS
Variable value: -Xmx512M

Don't ignore the score and underscore characters.

Harmonic answered 20/12, 2016 at 0:0 Comment(7)
Add a local or user environment variable _JAVA_OPTIONS works just as well.Rettarettig
source ?Pharmacopsychosis
This worked like a charm for me, but after restarting the cli.Zoila
Works like charm!Francinefrancis
It Works, Thank youCoppery
This works for me, but after that, I can't open eclipse anymore.Sharma
@Sharma IntelliJ also inherits from these settings. It even ignores its own settings to use this one. Dealbreaker for me.Blunt
M
13

I had the exact same problem. I switched to use 64-bit JDK as suggested in here and it worked fine. I was using Ionic 3.5.0 on Windows 10.

Maxi answered 14/7, 2017 at 22:17 Comment(0)
L
8

this worked for my ionic app.

Change line on

// to allow dex in process
'org.gradle.jvmargs': '-Xmx1024m',

from

// to allow dex in process
'org.gradle.jvmargs': '-Xmx2048m',

in your

<app path>\platforms\android\cordova\lib\config

thanks

Lapse answered 26/12, 2019 at 14:23 Comment(1)
Thanks, your answer solved my problem, I was stuck for 3 days. I applied many different things. but ignoring your answer as score is less. Thank youDerr
D
6
args.push('-Dorg.gradle.jvmargs=-Xmx2048m') 
into 
args.push('-Dorg.gradle.jvmargs=-Xmx1024m');

on the following location files.

  1. project-folder\platforms\android\cordova\lib\builders\GradleBuilder.js

  2. project-folder\platforms\android\cordova\lib\builders\StudioBuilder.js

Devisable answered 24/12, 2018 at 18:24 Comment(0)
M
3

Go to : \platforms\android\cordova\lib\config\GradlePropertiesParser.js

constructor (platformDir) {
        this._defaults = {
            // 10 seconds -> 6 seconds
            'org.gradle.daemon': 'true',

            // to allow dex in process
            'org.gradle.jvmargs': '-Xmx2048m',

            // allow NDK to be used - required by Gradle 1.5 plugin
            'android.useDeprecatedNdk': 'true'

            // Shaves another 100ms, but produces a "try at own risk" warning. Not worth it (yet):
            // 'org.gradle.parallel': 'true'
        };

And change the 'org.gradle.jvmargs': '-Xmx2048m', to 'org.gradle.jvmargs': '-Xmx1024m',

Monochord answered 22/12, 2019 at 5:13 Comment(0)
D
2
args.push('-Dorg.gradle.jvmargs=-Xmx2048m') 
 to  
args.push('-Dorg.gradle.jvmargs=-Xmx1024m');

on the following location files.

  1. project-folder\platforms\android\cordova\lib\builders\builders.js
  2. project-folder\platforms\android\cordova\lib\builders\GradleBuilder.js
  3. project-folder\platforms\android\cordova\lib\builders\StudioBuilder.js
Dominate answered 9/1, 2019 at 8:13 Comment(0)
A
2

Go to Start -> Control Panel -> System -> Advanced(tab) -> Environment Variables -> System Variables

Add/change JAVA_HOME value from C:\Program Files (x86)\Java\jdk1.8.0_192 to C:\Program Files\Java\jdk1.8.0_192

That is, change from Program Files (x86) path to Program Files path.

Allx answered 26/2, 2019 at 15:2 Comment(3)
And install the 64bit version if you don't have it.Heronry
The above comment solved my issue. Java_Home was pointing to a 32 bit version.Melesa
Happy to know it helped.Allx
B
1

I had a same problem.

Anyway, here is how to fix it: Go to Start->Control Panel->System->Advanced(tab)->Environment Variables->System Variables->New: Variable name: _JAVA_OPTIONS

Variable value: -Xmx512M

if 512 not work then change it to.

Variable value: -Xmx1024M

And also change the path.

Variable name: Path

Variable value: ;C:\Program Files\Java\jre6\bin;F:\JDK\bin;

Change this to your appropriate path.

Beechnut answered 17/9, 2019 at 4:33 Comment(0)
A
0

Setting the environment variable at system level as in the @kemal's solution will set the memory size for all the JVM applications in the system, which is not a what most would want to do.

Instead, set the heap size in your cordova gradlebuilder property file.

args.push('-Dorg.gradle.jvmargs=-Xmx2048m');
Apian answered 10/7, 2018 at 14:42 Comment(1)
Do you mean project/platforms/android/build.gradle?Aversion
B
0

The precetents did not work for me. This worked. I changed the row

org.gradle.jvmargs=-Xmx2048m

to

org.gradle.jvmargs=-Xmx1024m

in the file /platforms/android/gradle.properties

Bedlamite answered 26/6 at 11:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.