13

In build.gradle (app) file we have this by default,

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

According to https://developer.android.com/studio/build/shrink-code,

minifyEnabled true make the code more secure (making it hard to reverse engineer) and also shrink the size in release build, which we use for publishing the app.

I know that using minifyEnabled true makes compile time longer, but usually debug builds are used for development and testing, which is not affected anyways.

What I'm looking for is that, what are the disadvantages (such as performance impacts) cause by using minifyEnabled true at runtime. I'm not worried about the build time of a release build.

Google Play Console also recommending us to enable it therefore I'm wondering why is minifyEnabled is disabled by default.

  • 1) nope, it does _not_ make it more "secure" - it simply makes it more tedious to inspect; 2) it does take longer, so that's an immediate chalk down; 3) it's only a default, and the "why" is either [lost] in history [such as mailing lists] or a preference of someone who assigned it; 4) see associated shrinkResources documentation and/or ask a [new] question focused explicit on such. – user2864740 May 08 '20 at 19:19
  • @user2864740 Thank you for the reply. So are you suggesting that there are no side effects by making it enabled? I'm still a bit lost. I'm actually worried about the runtime performance. – Amila Abeygunasekara May 08 '20 at 19:25
  • That is an awkward conclusion to arrive at from the previous comment.. – user2864740 May 08 '20 at 19:25
  • 1
    @user2864740 This may be a little late, but yes it does take longer to build the app with minifyEnabled. It is very noticeable on low-to-mid-end PCs. – yuroyami Sep 02 '21 at 18:39

2 Answers2

9

By adding minifyEnabled true in your release build you can obfuscate code but it is set to false by default in release builds because if set true it shall require proguard rules to be written to tell the compiler which classes are to be ignored while obfuscating the code. If minifyEnabled is set to true by default and the developer forgets to add proguard rules, it can lead to runtime crashes.

However, setting minifyEnabled to true and shrinkResources to true can reduce your apk size.

NIKHIL AGGARWAL
  • 448
  • 4
  • 9
2

As NIKHIL AGGARWAL said, setting minifyEnabled to true can lead to runtime crashes.

You should research each used library so that include their ProGuard rules into your project. Also sometimes after Gradle or libraries upgrade you should again check ProGuard rules and accordingly update them in your project.

You should add data classes of your network model to ProGuard.

You should check your release build on several devices/emulators with different Android versions to understand where it can crash. Debugging in release build is difficult and with obfuscation it becomes a nightmare.

However after you set minifyEnabled = true and avoid crashes you will decrease apk size and impede to cracking attempts.

CoolMind
  • 26,736
  • 15
  • 188
  • 224