4

Error while generating release bundle with minifyEnabled true option. Here are the Gradle settings which give me the error:

buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

I also see that task transformClassesAndResourcesWithR8For... takes too much time (up to 10-20 mins)

The error: java.lang.OutOfMemoryError: GC overhead limit exceeded in Gradle task transformClassesAndResourcesWithR8ForCommonRelease

Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69

2 Answers2

5

Instead of turning of R8 a solution will be to raise the JVM heap size for the gradle daemon by adding/changing the value of org.gradle.jvmargs in gradle.properties (in the root of the Adroid Studio project):

  org.gradle.jvmargs=-Xmx2G

If that is not enough try going to 4G. The memory use of R8 have been growing, and for 3.4 there has been OOM issues on some apps.

sgjesse
  • 3,793
  • 14
  • 17
-1

R8 is the new code shrinker from Google. If you are using Gradle plugin version 3.4.0 and above, R8 is on by default.

The issue occurs because R8 and Proguard don't work together properly. Adding line to gradle.properties fixed it.

android.enableR8=false

Also, you may find this info useful https://www.reddit.com/r/androiddev/comments/bae6ny/r8_and_proguard/ekb4m7d/

Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69
  • 2
    As mentioned in the other answer raising the JVM heap size for the gradle daemon. R8 and Proguard are not working together - either one or the other is used, and R8 can use more memory. – sgjesse Aug 14 '19 at 09:35
  • 1
    Increasing memory limits imposed on R8 seems a better solution than disabling it completely. There are reasons why R8 is used. – JCutting8 Jul 14 '21 at 02:15