java.lang.OutOfMemoryError:Android 1.4上超出了GC开销限制

Ama*_*iam 25 java android garbage-collection

我得到一个java.lang.OutOfMemoryError:在Android 1.4上运行gradle时超出了GC开销限制 ...这些是我的依赖:

dependencies {
    compile project(':android-crop')
    compile project(':RTEditor-Toolbar')

        compile files('libs/apache-mime4j-0.6.jar')
        compile files('libs/httpmime-4.1.3.jar')
    /*    compile files('libs/httpcore-4.4.1.jar')*/
    compile files('libs/jetbrains-annotations.jar')
    compile files('libs/pinchzoom.jar')
    compile files('libs/gcm.jar')
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
    //three party library
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.18'
    compile 'com.vinaysshenoy:mugen:1.0.1'
    compile 'com.github.clans:fab:1.5.5'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.curioustechizen.android-ago:library:1.3.0'
    compile 'com.squareup.okio:okio:1.5.0'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
        transitive = true;
    }
Run Code Online (Sandbox Code Playgroud)

怎么解决这个问题?

Kin*_*ses 65

将此添加到您的android闭包(构建gradle):

 dexOptions {
        javaMaxHeapSize "4g"
 }
Run Code Online (Sandbox Code Playgroud)

这将解决您的问题.不过,如果您遇到问题,请参阅以下链接

GC开销限制超出错误

  • `incremental true`现在已弃用,对构建过程没有影响.所以,可以忽略. (2认同)
  • 只是为了澄清起见,将其添加到android {}对象内部的app / build.gradle中。 (2认同)

and*_*per 36

这就是我的建议:

将其添加到"gradle.properties"文件中:

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError
Run Code Online (Sandbox Code Playgroud)

另外,请阅读这篇文章.您可以通过添加以下组合使建筑物更快一些:

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true
Run Code Online (Sandbox Code Playgroud)

  • 在最新的 gradle 版本中,守护进程默认处于开启状态。 (2认同)

Kyo*_*agi 6

就我而言, OutOfMemoryError 来自此错误。启动 Gradle 守护进程,1 个忙碌和 6 个停止的守护进程无法重用,使用 --status 了解详细信息

为了解决这个问题。我使用./gradlew --stop./gradle --stop。如果仍然没有解决,这意味着 gradle 进程被锁定(这发生在 OutOfMemoryError 之后)。

转到/users/[username]/.gradle/daemon(隐藏)文件夹。

您将看到每个构建的 gradle 版本文件夹,例如 3.2 3.3 4.0.1 4.1 4.10.1 4.10.2 4.4 4.6 5.4.1 5.5

进入这些文件夹并删除名为

注册表.bin

注册表.bin.lock

对我来说,我删除了所有这些文件夹。

然后重建你的应用程序。现在应该上班了。


abh*_*bhi 5

这对我有用!只需将以下行添加到“ gradle.properties”文件中

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true
Run Code Online (Sandbox Code Playgroud)