Do I need to apply Proguard plug-in into my project on AGP 7.+?

Hi!
My current project mobile application use Gradle compile with AGP < 7.+.
I have to change the AGP version to 7.+

code before changed:

buildTypes.release {
            ...
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

when I build an app after migrating to AGP version 7.+, it crashes itself.
I have to change minifyEnabled and shrinkResources to false for an app to work normally.

I think the problem is obfuscation on my project and I follow this guide:

as I understand, I need to set minifyEnabled to false on AGP version 7.+ and implement the Proguard plug-in into my project.

  1. If I want to obfuscate/minify my app. Should I set minifyEnabled to true or false?
    (In my current project, if I set it to true app still crashes.)

  2. My gradle.properties have enableR8. Should I remove it?

# Disables R8 for Android Library modules only.
android.enableR8.libraries = true
# Disables R8 for all modules.
android.enableR8 = true
  1. Should I implement the Proguard plug-in into my project?
    Shrink, obfuscate, and optimize your app  |  Android Developers

Hi @Warunee_Khammak ,

Name obfuscation applied by R8 can break the app where it relies on reflection. On top of that, it sometimes happens that resources or parts of code are incorrectly removed from the app.

Typically this results in a ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, etc. Adding a -keep rule for the corresponding class, method, field, etc. will tackle the issue as it instructs R8 not to shrink, optimize, or obfuscate that part.

We have a troubleshooting guide for ProGuard which documents the most common issues and how to tackle them. Most of this document also applies to R8, please have a look at it here.

Best regards,

Jonas

fixed by set proguard.rule with

-repackageclasses

1 Like