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.
Code shrinking with R8 is enabled by default when you set the minifyEnabled property to true .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With