0

We had explicitly disabled R8 using directive

android.enableR8=false.

But when I take that directive out of my gradle.properties I am finding that R8 is removing lot of application specific classes.

Only way I am able to compile and run the app successfully is by including following statement in my config/proguard/proguard-project.txt

-keep class com.myapppackage.** { *; }

My gradle.properties looks like this:

kotlin.incremental.usePreciseJavaTracking=true
android.useAndroidX=true
android.enableJetifier=true
android.uniquePackageNames=true

In google's document ( https://developer.android.com/studio/build/shrink-code ) there is no mention that I need to explicitly have keep directive.

Subodh Nijsure
  • 3,305
  • 5
  • 26
  • 45

1 Answers1

1

Whenever you use a shrinker (R8 or ProGuard) it will use the provided keep rules to determine the possible entry points into the program. These entry points include any reflection used in the app. Android Studio has a set default keep rules (generated by getDefaultProguardFile('proguard-android-optimize.txt')) which, together with the rules generated by aapt2, will work for many apps. However if an app uses reflection beyond what these rules cover additional rules will be required. The conservative rule that you are using (keeping everything in the app pacakge and sub-packages) sould work for most apps, but you will end up keeping more than required.

You can add -printconfiguration <some file> to your proguard-rules.pro to see all the rules which are actually passed to R8.

sgjesse
  • 3,793
  • 14
  • 17