Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

What's the difference between "minifyEnabled" and "useProguard" in the Android Plugin for Gradle?

Ask Question

I see that the Android Plugin for Gradle has a minifyEnabled property as well as a useProguard property, as follows:

android {
    buildTypes {
        debug {
            minifyEnabled true
            useProguard false
        release {
            minifyEnabled true
            useProguard true

What's the difference between these two properties? Or, rather, what's the meaning of each?

You could read about it here tools.android.com/tech-docs/new-build-system/resource-shrinking – OneCricketeer May 3, 2016 at 15:02 That document (at the time of writing this comment) contains nothing about the useProguard property @cricket_007. Unless useProguard is a rename of the shrinkResources property in recent releases of the Android Plugin for Gradle? – Adil Hussain May 3, 2016 at 15:09

Version 2.0 of Android Plugin for Gradle ships with an experimental built-in code shrinker, which can be used instead of ProGuard. The built-in shrinker supports fast incremental runs and is meant to speed up iteration cycles. It can be enabled using the following code snippet:

android {
    buildTypes {
        debug {
            minifyEnabled true
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt')
  

The built-in shrinker can only remove dead code, it does not obfuscate or optimize. It can be configured using the same files as ProGuard, but will ignore all flags related to obfuscation or optimization.

Unlike ProGuard, we support using the built-in shrinker together with Instant Run: depending on the project, it may significantly decrease the initial build and install time. Any methods that become reachable after a code change will appear as newly added to the program and prevent an Instant Run hotswap.

Thanks so much @Mattia. This explains it. So minifyEnabled removes dead code but does not obfuscate or optimize. – Adil Hussain May 3, 2016 at 15:37 Seems to directly contradict this answer which is saying that minify does obfuscate a bit stackoverflow.com/questions/17290023/… – pete Jul 10, 2017 at 17:31 So it's recommended to use minifyEnabled true in both debug and release? It works fine with Proguard enabled? What happens when we use useProguard false, while setting the proguard files? Proguard rules are ignored? – android developer Jul 1, 2019 at 11:48

You don't need useProguard true anymore.

Code shrinking with R8 is enabled by default when you set the minifyEnabled property to true.

When you build your project using Android Gradle plugin 3.4.0 or higher, the plugin no longer uses ProGuard to perform compile-time code optimization. Instead, the plugin works with the R8 compiler to handle the tasks according to the official document.

If you want to use ProGuard instead of R8. Add this line in the gradle.properties file

 android.enableR8=false
                tried this, but there was no clue whether its working it or not. The mapping.txt file also not generated.
– arango_86
                Dec 16, 2020 at 16:05

Just enable minifyEnabled will have code both optimized and obfuscated. This is because useProguard true is default so no need to set it explicitly.

See also: Obfuscation in Android Studio

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.