Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 438
Hong Avatar asked Apr 23 '19 02:04

Hong


People also ask

Does R8 use ProGuard?

January 11, 2022. R8 is a tool that is used to shrink, secure, and optimize Android applications. It uses proguard rules to change the behavior of application.

How do I enable R8 on my Android?

To enable R8 shrinking in your application, set the minifyEnabled to true in your app's main build. gradle file.

Where do I put ProGuard rules pro?

You can add it yourself: put the proguard-rules. txt file into the app directory. It's already added to your build. gradle file so no further actions required.


1 Answers

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?

like image 79
shizhen Avatar answered Nov 09 '22 18:11

shizhen