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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41216921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:14:27  来源:igfitidea点击:

Cordova Could not reserve enough space for 2097152KB object heap

javaandroidcordova

提问by Mr_Yang

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

回答by Kemal Yalcinkaya

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
Variable value: -Xmx512M

转到开始 -> 控制面板 -> 系统 -> 高级(选项卡) -> 环境变量 -> 系统变量 -> 新建:
变量名称:_JAVA_OPTIONS
变量值:-Xmx512M

Don't ignore the score and underscore characters.

不要忽略分数和下划线字符。

回答by Hamed

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

我有同样的问题。我按照此处的建议改用 64 位 JDK ,它运行良好。我在 Windows 10 上使用 Ionic 3.5.0。

回答by Anand

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');

回答by Kernel

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

  1. 项目文件夹\平台\android\cordova\lib\builders\GradleBuilder.js

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

回答by Abd Abughazaleh

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

回答by Manohar Reddy Poreddy

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_HOMEvalue from C:\Program Files (x86)\Java\jdk1.8.0_192 to C:\Program Files\Java\jdk1.8.0_192

添加/更改JAVA_HOMEfrom 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 Filespath.

也就是说,从一个Program Files (x86)路径到Program Files另一个路径。

回答by Zaid Bin Khalid

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.

将此更改为您的适当路径。

回答by Ghadeer Ismael

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': '-Xmx1024m',

回答by fnu dudes

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

谢谢