Android-runtime: Invalid maximum heap size: -Xmx16384M

Created on 9 May 2017  路  19Comments  路  Source: NativeScript/android-runtime

how do i fix This:

C:\Users\USER\WebstormProjectsngMobile>tns run android

Executing before-prepare hook from C:\Users\USER\WebstormProjects\ngMobile\hooks\before-prepare\nativescript-dev-typescript.js
Found peer TypeScript 2.2.2
Preparing project...
Starting a Gradle Daemon (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/3.3/userguide/gradle_daemon.html
    Please read the following process output to find out more:

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Invalid maximum heap size: -Xmx16384M
The specified size exceeds the maximum representable size.

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

    Starting DaemonProcessing node_modules failed. Error: Command gradlew.bat failed with exit code 1

pakage.json file

{
"description": "NativeScript Application",
"license": "SEE LICENSE IN ",
"readme": "NativeScript Application",
"repository": "",
"nativescript": {
"id": "org.nativescript.AngularMobile",
"tns-android": {
"version": "3.0.0"
}
},
"dependencies": {
"@angular/animations": "~4.1.0",
"@angular/common": "~4.1.0",
"@angular/compiler": "~4.1.0",
"@angular/core": "~4.1.0",
"@angular/forms": "~4.1.0",
"@angular/http": "~4.1.0",
"@angular/platform-browser": "~4.1.0",
"@angular/router": "~4.1.0",
"nativescript-angular": "~3.0.0",
"nativescript-theme-core": "~1.0.2",
"reflect-metadata": "~0.1.8",
"rxjs": "~5.3.0",
"tns-core-modules": "~3.0.0",
"zone.js": "~0.8.2"
},
"devDependencies": {
"babel-traverse": "6.4.5",
"babel-types": "6.4.5",
"babylon": "6.4.5",
"lazy": "1.0.11",
"nativescript-dev-typescript": "~0.4.0",
"typescript": "~2.2.1"
}
}
bug

Most helpful comment

I had the same problem with "gradle" and "tns run" in my Windows machine and it was solved changing JAVA_HOME environment variable to x64 version path.

JAVA_HOME = C:\Program Files\Java\jdk1.8.0_181

Regards

All 19 comments

@alfredobialo it would appear that we've set the maximum heap size for the gradle process too big and didn't foresee the scenario where developers would use a 32bit Java.

If it's possible, please remove the current JDK distribution, then download and install the 64bit 1.8 JDK - http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html. Running your tns project afterwards should be straightforward.

If upgrading to a 64bit distribution of the Java SE Development Kit is not an option however, then you need to open platforms/android/gradle.properties in a text editor and edit the org.gradle.jvmargs property to org.gradle.jvmargs=-Xmx2048M

Please fill out the issue template when logging issues in the future. Thank you!

for 32 bit computers
just change org.gradle.jvmargs=-Xmx2048M to org.gradle.jvmargs=-Xmx256M.
This will let the CLI to create java virtual machine.

Go to
platforms/android/gradle.properties
and them change the org.gradle.jvmargs
Thank you :)

@ShivaniDalmia this works. But is there any permanent solution. I am getting this on an x64 system

@prantikv If this is coming for 64 bit also then its an internal CLI problem.
Please provide more info or screenshot so that the error can be better understood to us
Thank you

Here is the CLI output when I run tns build android

C:\working>tns build android

Found peer TypeScript 2.2.2
Preparing project...
Successfully prepared plugin nativescript-angular for android.
Successfully prepared plugin nativescript-theme-core for android.
Successfully prepared plugin tns-core-modules for android.
Successfully prepared plugin nativescript-intl for android.
Successfully prepared plugin tns-core-modules-widgets for android.
Starting a Gradle Daemon, 2 stopped Daemons could not be reused, use --status for details

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/3.3/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Invalid maximum heap size: -Xmx16384M
The specified size exceeds the maximum representable size.

Thanks

@prantikv although your system may be 64bit, your Java distribution could be a 32bit one, with a JVM memory limit of just 4G. Download the 64bit JDK and try again.

@Pip3r4o
Extremely sorry to ask here but sir I wanted to ask several questions aboit my project from someone but failed as I didn't find anyome
Can u plz tell me..
I am working on cross platform keyboard using tns
How to take permission for keyboard in both ios and Android
I hv chcked the numeric keyboard for ios
But i needed something that ll work for both Android n ios
Thank you

@ShivaniDalmia the forum may be a more suitable place for that kind of questions. - https://discourse.nativescript.org/

@Pip3r4o
Thank you sir :)

Installed 64 bit JDK and JRE.

doing java -XshowSettings:all give all the settings and if I look I see sun.arch.data.model = 64 which means that I have a 64 bit JVM

Sill I have the same issue.

Also having this issue and have changed everything I could think of -- lowercase Ms, lower limit, higher limit, etc.

if anyone needs a fix for this, it is to delete the "javaargs" property in the gradle.properties. this way, the JVM starts with the default heap values.

Hi @prantikv,
the fact you're running the command java -XshowSettings:all doesn't mean that the gradle build uses this java version. To be sure of what version of java version, Gradle is using please add these lines:

def currentJvm = org.gradle.internal.jvm.Jvm.current()
println currentJvm

to <project_name>/app/App_Resources/Android/app.gradle and see the java version. It's possible, you haven't set the JAVA_HOME environment variable to point to the new x64 jdk installation.

Closing due to inactivity. We'll reopen the issue if necessary.

Even if its a 64bit JVM, 16384M is a massive value, Android Studio sets the default at Xmx1536m so if you change it to that it should work

FYI:
I encountered this problem after setting ulimits for virtual memory to discourage runaway processes

ulimit -a
virtual memory          (kbytes, -v) 12000000 (12GB)

It seems like it's set to the size of the machine memory which seems ... a tad bit high?

I had the same problem with "gradle" and "tns run" in my Windows machine and it was solved changing JAVA_HOME environment variable to x64 version path.

JAVA_HOME = C:\Program Files\Java\jdk1.8.0_181

Regards

I was using as previous _JAVA_OPTIONS: -Xmx512M for the Gradle Build process on version 3. But after updating to version 4 the requirement got changed to -Xmx16384M which can be found in the file gradle.properties.

I then modified this file with my previous configuration i.e
from => org.gradle.jvmargs=-Xmx16384M
to => org.gradle.jvmargs=-Xmx512M

and it started executing successfully.

Was this page helpful?
0 / 5 - 0 ratings