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

2022-09-01 04:03:27

我得到一个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;
    }

如何解决这个问题?


答案 1

将此添加到您的安卓关闭(构建级别):

 dexOptions {
        javaMaxHeapSize "4g"
 }

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

超出 GC 开销限制错误


答案 2

这就是我的建议:

将其添加到您的“gradle.properties”文件中:

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError

另外,请阅读本文。您可以通过添加以下组合来使建筑物更快一些:

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true