【问题标题】:Building project: outOfMemory (Android studio 3.4)构建项目:outOfMemory (Android studio 3.4)
【发布时间】:2019-04-22 13:23:37
【问题描述】:

我已经将 Android Studio 3.x 升级到 3.4(带有 Grade 插件),现在,我的项目的构建非常非常长,并且最终出现错误(构建 4-5 分钟后):

> Task :app:compileDevelopmentDebugJavaWithJavac
Gradle may disable incremental compilation as the following annotation processors are not incremental: butterknife-compiler-10.1.0.jar (com.jakewharton:butterknife-compiler:10.1.0), esperandro-2.6.0.jar (de.devland.esperandro:esperandro:2.6.0).
Consider setting the experimental feature flag android.enableSeparateAnnotationProcessing=true in the gradle.properties file to run annotation processing in a separate task and make compilation incremental.
Note: [1] Wrote GeneratedAppGlideModule with: [com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule]
warning: No SupportedSourceVersion annotation found on de.devland.esperandro.processor.EsperandroAnnotationProcessor, returning RELEASE_6.
warning: Supported source version 'RELEASE_6' from annotation processor 'org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor' less than -source '1.8'


The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: GC overhead limit exceeded
    at java.lang.StringCoding$StringEncoder.encode(StringCoding.java:300)
    at java.lang.StringCoding.encode(StringCoding.java:344)

在此升级之前(今天早上完成),一切正常。请问有什么调查方法吗?

build.gradle:

buildscript {
    repositories {
        google()

        jcenter()
    }

    dependencies {
        // https://developer.android.com/studio/releases/gradle-plugin.html
        classpath 'com.android.tools.build:gradle:3.4.0'

        // https://developers.google.com/android/guides/google-services-plugin
        classpath 'com.google.gms:google-services:4.2.0'

        classpath 'com.google.firebase:firebase-plugins:1.2.0'

        // https://github.com/JakeWharton/butterknife
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
    }
}

gradle-wrappers.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

【问题讨论】:

标签: android android-studio gradle


【解决方案1】:

增加可供 Gradle 构建系统使用的内存。

把它放在你的gradle.properties 文件中:

org.gradle.jvmargs=-Xmx2g

mx 表示最大内存,2g 表示 2 GB。

如果已经有org.gradle.jvmargs,则在末尾添加-Xmx2g。删除旧的-Xmx(如果有)。

您的应用程序需要的容量不应超过 3 GB。添加更多 GB 不一定会带来更好的性能。

【讨论】:

    【解决方案2】:

    如果您也在使用options.fork,请尝试options.forkOptions.setMemoryMaximumSize("2g")

    对我来说,org.gradle.jvmargsjavaMaxHeapSize 不起作用。 所以我注释掉了很多 gradle 脚本命令来诊断导致问题的原因,并找到了options.fork

    ps。删除 options.fork 也可以。

    【讨论】:

      猜你喜欢
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 2019-01-06
      相关资源
      最近更新 更多