Android Studio編譯報錯「java.lang.OutOfMemoryError: GC overhead limit exceeded

1.在build.gradle添加腳本指定編譯堆內存html

  • 若是在整個工程中生效,則在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
相關文章
相關標籤/搜索