当android项目比较大的时候,打包时可能会出现Out of memory的错误,错误信息如下:
Out of memory: Java heap space.
Please assign more memory to Gradle in the project'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>
可以通过gradle.properties增大gradle的jvm堆内存来解决:
gradle.properties默认的jvm内存是512m,不过现在的开发电脑内存都比较大,所以调大一点没有关系,而且gradle编译速度还会提高,引用一段官网的原话:
org.gradle.jvmargs=(JVM arguments)
Specifies the JVM arguments used for the Gradle Daemon. The setting is particularly useful for configuring JVM memory settings for build performance. This does not affect the JVM settings for the Gradle client VM.
Changing JVM settings for the build VM
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
OK,重新打包,问题解决