proguard-android-optimize.txt vs proguard-android.txt in Android build.gradle
Asked Answered
A

1

40

I was reading the docs about shrinking, obfuscating and optimising for a release build using build.gradle for an Android app. In one section of the docs, proguard-android.txt is used as the defauly ProGuard file:

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

and in another section, proguard-android-optimize.txt is used:

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

There doesn't seem to be an explanation of what the difference between these are, and I can't find any information. Can someone explain what the differences are and when you would use proguard-android-optimize.txt vs proguard-android.txt?

Thanks :)

Autarky answered 5/7, 2019 at 11:38 Comment(0)
S
30

Take a look at the Android source code over here.

Optimizations: If you don't want to optimize, use the proguard-android.txt configuration file instead of this one, which turns off the optimization flags. Adding optimization introduces certain risks, since for example not all optimizations performed by ProGuard works on all versions of Dalvik. The following flags turn off various optimizations known to have issues, but the list may not be complete or up to date. (The "arithmetic" optimization can be used if you are only targeting Android 2.0 or later.) Make sure you test thoroughly if you go this route.

Also, this answer is a pretty good read as well.

Sherrard answered 5/7, 2019 at 11:46 Comment(3)
If you use R8, I think the optimisation file has no effect right? Reading developer.android.com/studio/build/shrink-code#optimization R8 ignores any ProGuard rules that attempt to modify default optimizations, such as -optimizations and - optimizationpassesAfra
@ErsenOsman Correct, although there are different manners to optimize for R8. For example: developer.android.com/studio/build/shrink-code#full-mode and jakewharton.com/blog has some posts on R8 Optimization.Sherrard
Where is the "proguard-android-optimize" file anyway?Hurling

© 2022 - 2024 — McMap. All rights reserved.