Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is minifyEnabled is false in release builds by default?

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.

like image 721
Amila Abeygunasekara Avatar asked May 08 '20 19:05

Amila Abeygunasekara


People also ask

Is minifyEnabled true?

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

How do I enable R8 on my Android?

To enable R8, open build. gradle module app file and add this piece of code inside the buildTypes . The code inside the release{} block means that this will be applied to the release build version of your application. If you launch the app in the emulator, this code is not executed.


1 Answers

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.

like image 191
NIKHIL AGGARWAL Avatar answered Sep 22 '22 14:09

NIKHIL AGGARWAL