错误:java.lang.OutOfMemoryError:超出了GC开销限制

时间:2016-11-07 21:40:34

标签: java android gradle

美好的一天,我无法构建我的项目,有错误,如:“.dex文件中的方法引用数量不能超过64k”

我尝试实现MultiDex,但还有另一个例外......

来自Gradle Build的消息:

Information:Gradle tasks [:app:assembleDebug]
Error:UNEXPECTED TOP-LEVEL ERROR:
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:  at java.util.Arrays.copyOf(Arrays.java:3236)
Error:  at java.io.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:191)
Error:  at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:279)
Error:  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
Error:  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
Error:  at com.android.dx.command.dexer.Main.processOne(Main.java:672)
Error:  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:569)
Error:  at com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)
Error:  at com.android.dx.command.dexer.Main.run(Main.java:275)
Error:  at com.android.dx.command.dexer.Main.main(Main.java:245)
Error:  at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
Information:BUILD FAILED
Information:Total time: 3 mins 45.026 secs

我的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion '23.0.3'

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    /* Android */
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'


    /* Libraries */


}
apply plugin: 'com.google.gms.google-services'

我在清单中添加了名称标签:

<application
    android:name=".application.MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

MyApplication扩展了MultiDexApplication。为什么我无法建立我的项目?

出了什么问题?

2 个答案:

答案 0 :(得分:2)

在gradle.properties中添加以下行:

org.gradle.jvmargs=-Xmx1563M

然后清理并重建您的项目。

答案 1 :(得分:-3)

上述问题的解决方案:

清理并重建您的项目。它的工作正常我