Android Studio gradle 编译错误 内存溢出mergeDexDebug OutOfMemoryError

Android Studio 3.X以上用R8编译,速度快,但是吃内存, 编译出现类似以下错误:

android studio  

What went wrong: Execution failed for task 'Module:app:mergeDexDebug'.

> java.lang.OutOfMemoryError (no error message)

或者其他类似错误,merge dex等等错误

解决办法:

修改gradle文件: .gradle/gradle.properties照片那个配置:

## 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.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# 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
#Sun May 05 21:04:32 CST 2019
systemProp.http.proxyHost=proxy.xxx.xxxx.net
systemProp.https.proxyPort=8080
systemProp.https.proxyHost=proxy.xxx.xxxx.net
systemProp.http.proxyPort=8080
org.gradle.jvmargs=-Xmx4g -XX\:MaxMetaspaceSize\=2g -XX\:+HeapDumpOnOutOfMemoryError -Dfile.encoding\=UTF-8

 

你可能感兴趣的:(Android)