Android Studio编译报错“java.lang.OutOfMemoryError: GC overhead limit exceeded

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Studio编译报错“java.lang.OutOfMemoryError: GC overhead limit exceeded相关的知识,希望对你有一定的参考价值。

1.在build.gradle添加脚本指定编译堆内存

  • 如果在整个工程中生效,则在build.gradle中增加如下配置:
android {

..............

      dexOptions {

            incremental true

            javaMaxHeapSize "4g"

        }

...............

}
  • 如果只在单元测试的时候生效,则在build.gradle中增加如下配置:
    android {
    
    ..............
    
        testOptions {
    
            android.dexOptions {
    
                incremental true
    
                javaMaxHeapSize "4g"
    
            }
    
        }
    
    ...............
    
    }
    2.添加gradle的配置文件指定堆内存
    也可以在gradle.properties中修改build环境中的jvmargs参数大小:
    在项目根目录新建gradle.properties文件内容为:
  • ## Project-wide Gradle settings.
    #
    # 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: -Xmx10248m -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
    #Mon Jun 13 14:58:46 CST 2016
    org.gradle.daemon=true
    org.gradle.parallel=true
    org.gradle.jvmargs=-Xmx5120m

     

以上是关于Android Studio编译报错“java.lang.OutOfMemoryError: GC overhead limit exceeded的主要内容,如果未能解决你的问题,请参考以下文章

错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段

错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段

Android Studio添加依赖编译报错

Android studio 软件报错

错误记录Android Studio 编译报错 ( SDK location not found )

android studio kotlin 编译的报错提示::app:stripDebugDebugSymbols