VLeonovs VLeonovs - 1 month ago 23
Android Question

Error:java.lang.OutOfMemoryError: GC overhead limit exceeded

Good Day, I can't build my project, there was and error like: "The number of method references in a .dex file cannot exceed 64k"

and I have tried to implement MultiDex enabled, but there is another exception...

Message From 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


My
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'


I have added name tag in manifest:

<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">


And MyApplication extends MultiDexApplication. Why I can't build my project ?

What was wrong ?

Answer

Add this line in your gradle.properties

org.gradle.jvmargs=-Xmx1563M

Then clean and rebuild your project. Good luck :)