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.

5
  • Do you have a particular setting for org.gradle.jvmargs or do you use defaults? Jan 17, 2019 at 16:50
  • In my AS 3.3 R8 works fine. Jan 17, 2019 at 17:25
  • @shadowsheep yes it worked on AS 3.3, but when I upgrade, it no longer working. Btw I'm not using any custom jvm args
    – nhoxbypass
    Jan 18, 2019 at 2:46
  • 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. Jan 18, 2019 at 7:59
  • 1
    @nhoxbypass im getting the same gc overhead error. have you found a fix for this?
    – chathura
    Apr 28, 2019 at 10:11

2 Answers 2

48

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.

5
  • 2
    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).
    – Petr Daňa
    May 2, 2019 at 8:47
  • 1
    Make sure to use gradle.properties not gradle-wrapper.properties
    – pumnao
    Jul 8, 2019 at 9:01
  • 1
    Working for me with Android Studio 3.5.2. This also increased the speed of my builds in general.
    – Nicholas
    Nov 8, 2019 at 22:35
  • 1
    Doesn't work for when building on Jenkins with com.android.tools.build:gradle:4.2.1
    – sinek
    May 31, 2021 at 11:36
  • 1
    the only thing that worked for me, finally... Thanks a lot for saving my day Mar 15 at 9:57
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.