Hong
Hong

Reputation: 18511

proguard-rules.pro does not seem to work with R8

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?

Upvotes: 9

Views: 6216

Answers (1)

shizhen
shizhen

Reputation: 12583

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?

Upvotes: 8

Related Questions