GC overhead limit exceeded when enable R8 Shrinker in Android Studio
Asked Answered
R

2

31

I'm using Android Studio 3.4 (Canary 9), when I build my app, it failed with the following error

Task :app:transformClassesAndResourcesWithR8ForDebug

R8 is an experimental feature. If you experience any issues, please file a bug at https://issuetracker.google.com, using 'Shrinker (R8)' as component name. You can disable R8 by updating gradle.properties with 'android.enableR8=false'.

AGPBI: {"kind":"warning","text":"Missing class: java.lang.instrument.ClassFileTransformer","sources":[{}],"tool":"D8"}

Task :app:transformClassesAndResourcesWithR8ForDebug FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:transformClassesAndResourcesWithR8ForDebug'.

GC overhead limit exceeded

When I disable R8 by putting android.enableR8=false into gradle.properties. Everything is working fine.

So how can I fix this error without disable R8 Shrinker? Because I'm really want to test functionality of R8.

Rowlett answered 12/1, 2019 at 17:18 Comment(5)
Do you have a particular setting for org.gradle.jvmargs or do you use defaults?Gunas
In my AS 3.3 R8 works fine.Gunas
@Gunas yes it worked on AS 3.3, but when I upgrade, it no longer working. Btw I'm not using any custom jvm argsRowlett
So, try tweaking memory settings like that org.gradle.jvmargs=-XX\:MaxHeapSize\=1024m -Xmx4608M for example, or more. Let's see if it solves. Let me know.Gunas
@Rowlett im getting the same gc overhead error. have you found a fix for this?Noaccount
G
49

As you said you are not using any custom JVM args, try it out.

In your gradle.properties file try several values for memory settings. For example try to set

org.gradle.jvmargs=-Xmx4096m

As suggested by the commented section:

Specifies the JVM arguments used for the daemon process.

The setting is particularly useful for tweaking memory settings.

org.gradle.jvmargs=-Xmx1536m

I've used R8 in my project and all worked fine.

Gunas answered 17/1, 2019 at 16:52 Comment(5)
With gradle version 5.1.1 (in gradle-wrapper.properties) this not working (nor with set heap size and Xmx to 4 GB), but with actual 5.4.1 version do working (also with only sets Xmx to 2 GB).Repetition
Make sure to use gradle.properties not gradle-wrapper.propertiesTomika
Working for me with Android Studio 3.5.2. This also increased the speed of my builds in general.Lifeguard
Doesn't work for when building on Jenkins with com.android.tools.build:gradle:4.2.1Metaphosphate
the only thing that worked for me, finally... Thanks a lot for saving my dayCoastguardsman
M
2

Sometimes adding JVM heap memory does not solve the problem especially on systems that have limited memory, it will cause other problems. my recommendation is to try replacing the Garbage Collector.

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC

GC overhead limit exceeded is an exception throw by default java 8 garbage collector (Parallel). In my case, it solved the problems.

Metaphysical answered 3/8, 2021 at 7:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.