关于android:如何增加Gradle守护程序的最大堆大小?

How to increase maximum heap size for the Gradle daemon?

登录apk时,收到以下消息:

1
2
3
4
5
To run dex in process, the Gradle daemon needs a larger heap.
It currently has 1024 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to at least 4608 MB (based on the dexOptions.javaMaxHeapSize = 4g).
To do this set org.gradle.jvmargs=-Xmx4608M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html

在我的项目中,没有gradle.properties文件,但是有一个名为gradle-wrapper.properties的文件。

我打开了该文件,并添加了org.gradle.jvmargs=-Xmx4608M行。

在那之后,我尝试再次对apk进行签名,但是我仍然收到增加Gradle堆大小的消息。

如何实现?


如果没有gradle.properties,则转到项目文件夹,您将在其中找到gradle文件,创建一个文本文件并将其命名为gradle.properties,删除.txt,然后将以下代码添加到该文件中。铅>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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.
org.gradle.jvmargs=-Xmx4096m

# 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

并保存它,然后在Android Studio中打开您的项目,然后单击立即同步。

我希望它能解决您的问题,否则请告诉我们。


我知道您说您的项目没有gradle.properties,但是您可以在C:\\Users\\user\\.gradle中创建一个全局项目并添加:

1
 org.gradle.jvmargs=-Xmx4096M

并记住运行gradle --stop杀死以前的所有守护程序。


尝试此链接答案

1
2
3
4
5
6
7
dexOptions
   {
       javaMaxHeapSize"4g"
   }
....
....
....

您可以尝试以下任一种

1)根据您的要求更改gradle.properties文件并更改堆大小。

如果org.gradle.jvmargs = -Xmx2048M不足,则根据给定更改为4096

org.gradle.jvmargs = -Xmx4096M
enter

它将打开studio.vmoptions / studio64.exe.vmoptions文件
enter

-XX:MaxPermSize = 1024m

-XX:ReservedCodeCacheSize = 200m

-XX:UseCompressedOops

保存文件并重新启动Android Studio。


将以下代码添加到您的build.gradle文件中。

1
2
3
4
5
6
 android {
     dexOptions {
     incremental true      
     javaMaxHeapSize"4g"
      }
    }

参考:来源