如何在Android Studio 1.3中设置Gradle JVM参数

10

从版本1.3开始,Android Studio将不再支持特定于IDE的Gradle JVM参数设置。Gradle JVM设置需要在gradle.properties文件中设置。这个更改是为了保持构建输出的一致性,无论构建在哪里执行(IDE、命令行或CI服务器)。

如果您的项目正在使用特定于IDE的Gradle JVM参数,Android Studio将在项目同步时帮助您将这些设置复制到项目的gradle.properties文件中。

"Gradle"设置页面中的"Gradle VM选项"文本字段也已被删除。

我遇到了错误:

Error: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     http://gradle.org/docs/2.4/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 object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.  

我的 gradle.properties 文件

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

org.gradle.parallel=true
2个回答

1
尝试将您的jvmargs更改为以下内容。
org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

如果您的系统没有足够的内存来创建对象堆,因此无法使用jvm,则可以将-Xmx512m或更小的值用作参数。

您还可以添加以下选项:

 org.gradle.daemon=true

对于MacOSX用户,我喜欢添加以下内容。
-Djava.awt.headless=true

0

将以下代码添加到您的 build.gradle 文件中的 Android 部分:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

你能再解释一下为什么这会有帮助吗? - Daniel Gomez Rico

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接