0

When I add R8 to shrink the android dex size it is not working. I've added this following line:

gradle.properties:

android.enableR8=true

When tried to analyse my code I could not find any difference in my apk size. Is it something else I am missing?

Should I add any proguard rules and enable progaurd by adding these lines:

build.gradle

minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Community
  • 1
  • 1
srisindhu saride
  • 391
  • 6
  • 25

1 Answers1

3

As sgjesse suggested in his comment, you need to enable minification on all build types on which you want R8 to run.

E.g., if you want R8 to run on all release builds, use minifyEnabled like this in your app-level build.gradle:

android {
  buildTypes {
    release {
      minifyEnabled true
    }
  }
}

If you want R8 to also run on your debug builds, then you will need to use minifyEnabled for debug as well.

You posted this line as part of your question:

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

Using proguardFiles in this manner is only necessary if you have your own rules that you would like to apply in addition to those in the default proguard-android.txt file.

(You still need to use android.enableR8=true in your gradle.properties file to enable R8 instead of ProGuard if you are using a version of the Android Gradle Plugin/Android Studio before 3.4)

Peter Tefft
  • 126
  • 1