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?
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()) {
...
}