8

I upgraded my Android Studio to 3.4 earlier today, and I am using the default shrinker R8 for the first time. I copied the contents of proguard-project.txt of a library project to its proguard-rules.pro. proguard-project.txt worked flawlessly for this project that generates an aar file for use by other app projects.

File proguard-rules.pro does not seem to be used. The project has the following in its build.gradle:

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
                    'proguard-rules.pro'
            signingConfig signingConfigs.Release
        }
        debug {
            signingConfig signingConfigs.Debug
        }
    }

proguard-rules.pro has the following:

# Preserve all public classes, and their public and protected fields and methods.
-keep public class * {
    public protected *;
}

The public methods' names are not preserved at all: enter image description here

Could anyone offer a tip on how to fix this?

Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
Hong
  • 16,621
  • 15
  • 73
  • 126

1 Answers1

7

Add this line to gradle.properties

android.enableR8 = true

And try below code inside your proguard-rules.pro

-keep public class ** {
    public *;
    protected *;

}

Edit #1

Check here for how to migrate Proguard to R8: Android/java: Transition / Migration from ProGuard to R8?

shizhen
  • 11,455
  • 9
  • 49
  • 81
  • 2
    Thanks a lot. public *; protected *; did it. The others seem to be unnecessary. – Hong Apr 23 '19 at 04:04
  • Do we need the first line to enable R8? I thought it was enabled by default in the new version of android studio. – Nikos Hidalgo Apr 23 '19 at 11:10
  • @NikosHidalgo No. I do not have the first line, and it is working fine now. I believe you are right - it is enabled by default starting from Android Studio 3.4. – Hong Apr 23 '19 at 14:46
  • This was a bug, see http://issuetracker.google.com/131712625. The issue is fixed and will be part of Android Studio 3.4.1. – sgjesse May 09 '19 at 04:40