简体   繁体   English

Cordova 无法为 2097152KB 对象堆保留足够的空间

[英]Cordova Could not reserve enough space for 2097152KB object heap

I am new to cordova and am trying to create an android HelloWold project.我是cordova 的新手,正在尝试创建一个android HelloWold 项目。

When I use cordova platforms add android , it throws some exception:当我使用cordova platforms add android ,它会抛出一些异常:

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 cordova-android@6.0.0
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

Try again after increasing your Java VM(?) memory size.增加 Java VM(?) 内存大小后重试。

Here is how to fix it on a Windows platform:以下是在 Windows 平台上修复它的方法:

Go to Start -> Control Panel -> System -> Advanced(tab) -> Environment Variables -> System Variables -> New:转到开始 -> 控制面板 -> 系统 -> 高级(选项卡) -> 环境变量 -> 系统变量 -> 新建:
Variable name: _JAVA_OPTIONS变量名: _JAVA_OPTIONS
Variable value: -Xmx512M变量值: -Xmx512M

Don't ignore the score and underscore characters.不要忽略分数和下划线字符。

I had the exact same problem.我有同样的问题。 I switched to use 64-bit JDK as suggested in here and it worked fine.我按照此处的建议改用 64 位 JDK,它运行良好。 I was using Ionic 3.5.0 on Windows 10.我在 Windows 10 上使用 Ionic 3.5.0。

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项目文件夹\\平台\\android\\cordova\\lib\\builders\\GradleBuilder.js

  2. project-folder\\platforms\\android\\cordova\\lib\\builders\\StudioBuilder.js项目文件夹\\平台\\android\\cordova\\lib\\builders\\StudioBuilder.js

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谢谢

Go to : \\platforms\\android\\cordova\\lib\\config\\GradlePropertiesParser.js转到:\\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',并将'org.gradle.jvmargs': '-Xmx2048m',更改为'org.gradle.jvmargs': '-Xmx2048m', 'org.gradle.jvmargs': '-Xmx1024m',

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项目文件夹\\平台\\android\\cordova\\lib\\builders\\builders.js
  2. project-folder\\platforms\\android\\cordova\\lib\\builders\\GradleBuilder.js项目文件夹\\平台\\android\\cordova\\lib\\builders\\GradleBuilder.js
  3. project-folder\\platforms\\android\\cordova\\lib\\builders\\StudioBuilder.js项目文件夹\\平台\\android\\cordova\\lib\\builders\\StudioBuilder.js

Go to Start -> Control Panel -> System -> Advanced(tab) -> Environment Variables -> System Variables转到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_192JAVA_HOMEfrom C:\\Program Files (x86)\\Java\\jdk1.8.0_192 to C:\\Program Files\\Java\\jdk1.8.0_192添加/更改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.即,从Program Files (x86)路径更改为Program Files路径。

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无论如何,这里是如何修复它:转到开始->控制面板->系统->高级(选项卡)->环境变量->系统变量->新建:变量名称:_JAVA_OPTIONS

Variable value: -Xmx512M变量值:-Xmx512M

if 512 not work then change it to.如果 512 不起作用,则将其更改为。

Variable value: -Xmx1024M变量值:-Xmx1024M

And also change the path.并且还改变了路径。

Variable name: Path变量名称:路径

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

Change this to your appropriate path.将此更改为您的适当路径。

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.在@kemal 的解决方案中设置系统级别的环境变量将为系统中的所有 JVM 应用程序设置内存大小,这不是大多数人想要做的。

Instead, set the heap size in your cordova gradlebuilder property file.相反,请在您的cordova gradlebuilder 属性文件中设置堆大小。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM