堆空间大小?

时间:2017-04-06 09:40:28

标签: android gradle heap-size

我的资源文件夹中有一个db文件(300mb)。当我运行代码时,它会给我以下错误

Error:Execution failed for task ':app:packageDebug'.
> Java heap space
ect's gradle.properties file.
For example, 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>

下面是gradle.properties

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.


# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true


org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

我尝试过很多改变环境变量中 _JAVA_OPTIONS ,更改 studio.exe.vmoptions gradle.properties 中的值的内容给了我同样的错误。

请帮忙

1 个答案:

答案 0 :(得分:2)

尝试增加java堆大小。以下是步骤:

查找Android Studio右下角的内存指示器

enter image description here

如果您没有看到此选项,请从Android Studio偏好设置&gt;启用它。 <外观和行为>外观&gt;显示记忆指示器

enter image description here

增加Java堆大小:选择“帮助”&gt;编辑自定义VM选项

enter image description here

更新当您选择上述选项时打开的studio.vmoptions文件中的Xmx值。对于8GB RAM,我添加了这些值,您可能需要根据系统配置进行调整:

-Xmx4096m
-XX:MaxPermSize=1024m

您也可以在〜/ Library / Preferences / AndroidStudio

中找到此文件

重新启动Android Studio并查看您的内存指示器是否显示更新的值。