Android 在 Intellij IDEA 中不断出现 Gradle 错误“无法为对象堆保留足够的空间”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26143740/
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
Getting Gradle error "Could not reserve enough space for object heap" constantly in Intellij IDEA
提问by Nilzor
So I have a problem with memory allocation. Sometimes it works, and sometimes it doesn't. I've read this threadand tried the advice there multiple times. Sometimes -Xms512m -Xmx768m
works, sometimes -Xms256m -Xmx512m
. I'm sick and tired of having to tweak this setting in IntelliJ under the Build, Execution, Deployment > Build Tools > Gradle > Gradle VM
options setting. Is there no setting that solves this once and for all?
所以我有内存分配问题。有时它有效,有时它不起作用。我已经阅读了这个线程并多次尝试了那里的建议。有时-Xms512m -Xmx768m
有效,有时-Xms256m -Xmx512m
。我厌倦了不得不在Build, Execution, Deployment > Build Tools > Gradle > Gradle VM
选项设置下在 IntelliJ 中调整此设置。没有设置可以一劳永逸地解决这个问题吗?
I have 16GB of RAM on my Windows 7 computer, I'm running IntelliJ IDEA EAP 14 build 138.2210.3, 64 bit version. Android Gradle build plugin v0.12.
我的 Windows 7 计算机上有 16GB 的 RAM,我正在运行 IntelliJ IDEA EAP 14 build 138.2210.3,64 位版本。Android Gradle 构建插件 v0.12。
I'm suspecting gradle is not running in 64 bit mode, or else it would have ~7 GB of free memory to eat from. Why is it not utilizing this?
我怀疑 gradle 没有在 64 位模式下运行,否则它会有大约 7 GB 的可用内存可供使用。为什么不利用这个?
EDIT:
编辑:
I got the same error in Visual Studio 2015with cordova 5.1.1under Windows 10. See my solution below.
我在Windows 10下使用cordova 5.1.1在Visual Studio 2015 中遇到了同样的错误。请参阅下面的我的解决方案。
采纳答案by Nilzor
Installing 64 bit Java solved it for me
安装 64 位 Java 为我解决了这个问题
回答by Bjoerg
I got the same error in Visual Studio 2015with cordova 5.1.1under Windows 10.
我在Windows 10下使用cordova 5.1.1在Visual Studio 2015 中遇到了同样的错误。
To solve the issue, set this environment variable:
要解决此问题,请设置此环境变量:
_JAVA_OPTIONS=-Xmx512M
- Right click on start-button and open "System"
- Search for "Advanced system settings" and open it
- Click the button "Environment Variables ..."
- In System Variables, click "New..."
- New Variable Name: _JAVA_OPTIONS
- New Variable Value: -Xmx512M
- Click OK
- Restart Visual Studio, so the variable is picked up
- 右键单击开始按钮并打开“系统”
- 搜索“高级系统设置”并打开
- 单击“环境变量...”按钮
- 在系统变量中,单击“新建...”
- 新变量名:_JAVA_OPTIONS
- 新变量值:-Xmx512M
- 单击确定
- 重新启动 Visual Studio,以便选择变量
ThisArticle point me in the right direction. I did change the instructions a littel bit, so they fits to Windows 10.
这篇文章为我指明了正确的方向。我确实稍微更改了说明,因此它们适合 Windows 10。
Hope it helps someone!
希望它可以帮助某人!
回答by deR_Ed
Although this question is a bit older I would like to come up with the (possible) rootcause of the problem: the JVM requests a whole block of memory on startup. If it couldn't find it, the "Could not reserve..." error occurs. John Pape wrote an enlighting article in IBM's devblog about this issue: https://www.ibm.com/developerworks/community/blogs/aimsupport/entry/why_wont_my_jvm_start_with_this_heap_size?lang=en
虽然这个问题有点老了,但我想提出问题的(可能的)根本原因:JVM 在启动时请求整个内存块。如果找不到,则会出现“无法保留...”错误。John Pape 在 IBM 的 devblog 中写了一篇关于这个问题的启发性文章:https://www.ibm.com/developerworks/community/blogs/aimsupport/entry/why_wont_my_jvm_start_with_this_heap_size?lang =en
This is solving the problem for me:
这为我解决了问题:
- variant a: using a 64 bit version of Java, so to give Java a bigger area of possible connected free memory
- variant b: With 32 bit Java using smaller XMX amount. In the gradle.properties file I just use
org.gradle.jvmargs=-Xmx150m
and Gradle has no problems.
- 变体 a:使用 64 位版本的 Java,以便为 Java 提供更大的可能连接的空闲内存区域
- 变体 b:在 32 位 Java 中使用较小的 XMX 量。在我刚刚使用的 gradle.properties 文件中
org.gradle.jvmargs=-Xmx150m
,Gradle 没有问题。
回答by Pierre
This happens to me too and it drives me nuts. It could be that the memory (ram) available is fragmented. Although you have enough free memory, there is no contiguous 512MB blocks available, it's all fragmented into smaller blocks! This is why you only see it "sometimes".
这也发生在我身上,它让我发疯。可能是可用内存(ram)碎片化。尽管您有足够的空闲内存,但没有可用的连续 512MB 块,它全部被分割成更小的块!这就是为什么你只能“有时”看到它。
Some things worth trying:
一些值得尝试的事情:
check if you're low on memory, try to close other apps. This happens to me sometimes even if I still have a good 3GB free out of my 8GB! That 3GB can be fragmented in blocks which are all smaller than 512MB [ex: if you have -Xmx512m]... Rebooting is a way to defrag your memory. Or close firefox, that'll free up a gig ;-)
also, surprisingly, check your swap space [free disk space]! Depends of machine/JVM/etc implementation. But if you're low on swap space and your memory is fragmented, that could be another cause.
lower your -Xmx to maybe -Xms128m -Xmx512m to make it easier to find a contiguous block of free memory [128m]. This might not be a good idea if gradle truly needs 512m minimum. Given that we're talking about gradle, ignore this bullet point (could be a useful tip for other cases/worth noting).
double check your Xms/Xmx in ~/.gradle/gradle.properties attribute: org.gradle.jvmargs
use idea64.exe [64bit] and if you think IDEA is using the wrong JDK [32bit], in latest Intellij IDEA [14.1.3 as of this writting], go to "Settings"->"Build,Execution,Deployment" -> "Gradle": "use the default wrapper" and select the Gradle JVM you'd like (if you think it uses the wrong one, you'll see it here".
finally, this is just a guess but: in the previous bullet, I wonder if you select "use project JDK", if that makes it easier to find contiguous memory. I'm not sure if that means that Gradle will use intellij IDEA's already reserved memory block. So, instead of having two processes, you only have one and you could reserve a bigger memory block when IDEA starts up. But I'm not sure if that's accurate of if that's an option to suggest to Intellij...
检查您的内存是否不足,尝试关闭其他应用程序。这种情况有时会发生在我身上,即使我的 8GB 中还有 3GB 可用!这 3GB 可以分成小于 512MB 的块 [例如:如果您有 -Xmx512m]...重新启动是对内存进行碎片整理的一种方式。或者关闭 Firefox,这将释放一个演出 ;-)
此外,令人惊讶的是,请检查您的交换空间 [可用磁盘空间]!取决于机器/JVM/等实现。但是,如果您的交换空间不足并且您的内存碎片化,那可能是另一个原因。
将 -Xmx 降低到可能 -Xms128m -Xmx512m 以便更容易找到连续的空闲内存块 [128m]。如果 gradle 确实需要最少 512m,这可能不是一个好主意。鉴于我们正在谈论 gradle,请忽略此要点(对于其他情况可能是有用的提示/值得注意)。
在 ~/.gradle/gradle.properties 属性中仔细检查您的 Xms/Xmx:org.gradle.jvmargs
使用idea64.exe [64bit],如果您认为IDEA 使用了错误的JDK [32bit],请在最新的Intellij IDEA [14.1.3 as this witting] 中,转到“设置”->“构建、执行、部署”- > "Gradle": "use the default wrapper" 并选择你喜欢的 Gradle JVM(如果你认为它使用了错误的,你会在这里看到它)。
最后,这只是一个猜测,但是:在上一个项目符号中,我想知道您是否选择了“使用项目 JDK”,这样是否可以更轻松地找到连续内存。我不确定这是否意味着 Gradle 将使用 Intellij IDEA 已经保留的内存块。因此,不是有两个进程,而是只有一个进程,并且可以在 IDEA 启动时保留更大的内存块。但我不确定这是否准确,如果这是否是向 Intellij 建议的选项......
I agree with you, I've never had any memory issues with IDEA [well no issues AT ALL] until gradle integration came along.
我同意你的看法,在 gradle 集成出现之前,我从来没有遇到过任何关于 IDEA 的内存问题 [完全没有问题]。
回答by Ekhtiar
In your android folder there is a gradel.properties file and add the following lines:
在您的 android 文件夹中有一个 gradel.properties 文件并添加以下几行:
org.gradle.jvmargs=-XX\:MaxHeapSize\=256m -Xmx256m
I ran into this while using Intellij and Flutter. Also another property you may find useful to add is declaring where the JDK is.
我在使用 Intellij 和 Flutter 时遇到了这个问题。您可能会发现添加的另一个有用的属性是声明 JDK 的位置。
org.gradle.java.home=C:\Your\JDK\path
回答by Michael Laffargue
In my case I had too much things opened. Freeing memory made it work.
就我而言,我打开的东西太多了。释放内存使它起作用。