Android Studio - Gradle 构建失败 - Java 堆空间 [英] Android Studio - Gradle build failing - Java Heap Space

查看:48
本文介绍了Android Studio - Gradle 构建失败 - Java 堆空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Studio 2.2.3.直到最近,我一直在用我当前的项目成功地为 android 构建 APK.据我所知,除了数据文件之外没有任何更改,并且我的构建 APK"步骤神秘地开始失败,并在 gradle 控制台中显示此消息:

Android Studio 2.2.3. I've been building an APK for android with my current project with success until very recently. As far as I know, nothing was changed except a data file, and my "Build APK" step mysteriously started failing with this message in the gradle console:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':VrSamples:Native:myproject:Projects:Android:packageDebug'.
> Java heap space

在我的消息"窗口中,我看到了这个错误:

and in my "messages" window I see this error:

Error:Execution failed for task ':VrSamples:Native:myproject:Projects:Android:packageDebug'.
> Java heap space
mple, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB:
<em>org.gradle.jvmargs=-Xmx1024m</em>
<a href="http://www.gradle.org/docs/current/userguide/build_environment.html">Read Gradle's configuration guide</a><br><a href="http://docs.oracle.com/javase/7/docs/technotes/guides/vm/gc-ergonomics.html">Read about Java's heap size</a>

我尝试了很多东西:

  • 将版本控制重置为以前的版本,我知道生成 APK 的效果很好
  • 在新位置重新克隆整个项目,以排除和中间化可能与 .gitignore 一起拉入的文件,以确保它是全新构建
  • 重新启动了我的电脑
  • 重新安装了 android studio
  • 运行清理步骤,重建,手动删除中间文件
  • 将 org.gradle.jvmargs=-Xmx1024m 添加到我的 gradle.properties 文件
  • 将 1024m 增加到 4096m
  • 在 Android Studio\bin\studio.exe.vmoptions 和 64 位等效项中手动增加 -Xmx 值

我很困惑为什么我现在突然遇到这个问题,以及为什么我似乎无法重新创建直到最近我一直在构建的 APK 没有问题.据我所知,我也没有更新任何库.

I'm puzzled as to why I'm suddenly hitting this issue now, and why I can't seem to be able to re-create the APK's I've been building without problems until recently. As far as I'm aware, I also haven't updated any libraries either.

如果您有任何解决此问题的建议、有关如何调试此类问题的提示等,我们将不胜感激.

Would appreciate any suggestions to resolve this issue, tips on how to debug this kind of thing down the road, etc.

推荐答案

我注意到,当我打开 Android Studios 项目中的 gradle.properties 文件夹并将鼠标悬停在任何一行时,它给出了关于未使用的属性"的警告.这让我走上了另一条谷歌搜索Android Studio gradle.properties 未使用的属性"的道路,我发现了这个:

I noticed that when I open the gradle.properties folder in my Android Studios project, and hovered over any line, it gave a warning about "unused property". That put me on the path to do another google search for "Android Studio gradle.properties unused property" and I found this:

gradle.properties.未使用的财产

还有这个:

JVM 参数 gradle无法在 Android Studio 2.1.1 的 gradle.properties 文件中设置

问题是,至少对我来说,Windows+Android Studio 似乎忽略了我项目中的 gradle.properties 文件.您需要在此处创建一个:C:\Users\<用户名>\.gradle\gradle.properties

The issue is that, at least for me, Windows+Android Studio seems to ignore the gradle.properties file in my project. You need to create one here: C:\Users\<username>\.gradle\gradle.properties

然后,按照其他线程(例如上面@Kevin Tan 链接的线程)中的建议,我能够通过添加如下一行来增加内存:

Then, as suggested in other threads such as the one linked to by @Kevin Tan above, I was able to increase the memory by adding a line such as this:

org.gradle.jvmargs=-XX:MaxHeapSize=256m -Xmx256m

现在我不再遇到这个问题

Now I no longer hit the issue

这篇关于Android Studio - Gradle 构建失败 - Java 堆空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆