I use the below code to automatically generate pro guard mapping file apparently according to product flavors.
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
if (variant.getBuildType().isMinifyEnabled()) {
variant.assemble.doLast {
copy {
from variant.mappingFile
into "${rootDir}/proguardTools"
rename { String fileName ->
"mapping-${variant.name}.txt"
}
}
}
}
}
}
}
After upgrading android studio to 3.0 it shows a warning saying isMinifyEnabled()
is Deprecated and I could not find any solution or an alternative for this isMinifyEnabled()
. Any help thanks in advance?
Enabling R8 in your project 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.
Shrink your code. Code shrinking with R8 is enabled by default when you set the minifyEnabled property to true . Code shrinking (also known as tree shaking), is the process of removing code that R8 determines is not required at runtime.
minify is an Android tool that will decrease the size of your application when you go to build it. It's extremely useful as it means smaller apk files! It detects any code or libraries that aren't being used and ignores them from your final apk.
Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle. There are two build types defined by default, debug and release , and you can customize them and create additional build types.
From the sources of Android Gradle Plugin 3.0:
/**
* Returns whether minification is enabled for this build type.
*
* @return true if minification is enabled.
* @deprecated remember that this flag means that some "ProGuard-like" tool has run, it does not
* say if the tool was used to obfuscate and/or minify. In build system code this
* information is available elsewhere and should be used instead of this method.
*/
@Deprecated
boolean isMinifyEnabled();
This documentation is vague and does not directly tell what to use instead. In the blame we can see, that it's Michał Bendowski that has performed those changes, from whom I have asked to help out with that question in twitter. Here's the reply:
Also I cannot see @Deprecated
annotation in the latest commit (at the time of writing this it's android-8.0.0_r34
), which means, that the API is not deprecated there.
As a fix, you can suppress that warning putting this line before if
statement:
//noinspection GrDeprecatedAPIUsage
if (variant.getBuildType().isMinifyEnabled()) {
...
}
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