isMinifyEnabled() 已弃用。有什么选择?
isMinifyEnabled() is deprecated. What is the alternative?
我使用下面的代码根据产品口味自动生成 pro guard 映射文件。
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"
}
}
}
}
}
}
}
将 android studio 升级到 3.0 后,它显示警告说 isMinifyEnabled()
已弃用,我找不到任何解决方案或替代方案 isMinifyEnabled()
。提前感谢任何帮助?
我的解决方案是将 variant.getBuildType().isMinifyEnabled()
替换为 variant.mappingFile.exists()
。
我之前的位置:
applicationVariants.all { variant ->
if (variant.getBuildType().isMinifyEnabled()) {
variant.assemble.doLast {
(new File(variant.mappingFile.parent, "$archivesBaseName-$variant.baseName-mapping.txt")).delete()
variant.mappingFile.renameTo(variant.mappingFile.parent +
"/$archivesBaseName-$variant.baseName-mapping.txt")
}
}
}
我将其替换为:
applicationVariants.all { variant ->
variant.assemble.doLast {
if (variant.mappingFile != null && variant.mappingFile.exists()) {
def mappingFilename = "$archivesBaseName-$variant.baseName-mapping.txt"
(new File(variant.mappingFile.parent, mappingFilename)).delete()
variant.mappingFile.renameTo(variant.mappingFile.parent +
"/" + mappingFilename)
}
}
}
或者在你的情况下替换
applicationVariants.all { variant ->
if (variant.getBuildType().isMinifyEnabled()) {
variant.assemble.doLast {
copy {
from variant.mappingFile
into "${rootDir}/proguardTools"
rename { String fileName ->
"mapping-${variant.name}.txt"
}
}
}
}
}
与:
applicationVariants.all { variant ->
variant.assemble.doLast {
if (variant.mappingFile != null && variant.mappingFile.exists()) {
copy {
from variant.mappingFile
into "${rootDir}/proguardTools"
rename { String fileName ->
"mapping-${variant.name}.txt"
}
}
}
}
}
请注意我如何重新安排代码中的条件,以便仅在所有其他组装任务完成后才搜索映射文件。
来自 Android Gradle 插件 3.0 的 sources:
/**
* 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();
该文档含糊不清,没有直接说明使用什么。
在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。回复如下:
我也看不到 latest commit 中的 @Deprecated
注释(在撰写本文时它是 android-8.0.0_r34
),这意味着 API 是 未 已弃用。
作为修复,您可以取消将此行放在 if
语句之前的警告:
//noinspection GrDeprecatedAPIUsage
if (variant.getBuildType().isMinifyEnabled()) {
...
}
我使用下面的代码根据产品口味自动生成 pro guard 映射文件。
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"
}
}
}
}
}
}
}
将 android studio 升级到 3.0 后,它显示警告说 isMinifyEnabled()
已弃用,我找不到任何解决方案或替代方案 isMinifyEnabled()
。提前感谢任何帮助?
我的解决方案是将 variant.getBuildType().isMinifyEnabled()
替换为 variant.mappingFile.exists()
。
我之前的位置:
applicationVariants.all { variant ->
if (variant.getBuildType().isMinifyEnabled()) {
variant.assemble.doLast {
(new File(variant.mappingFile.parent, "$archivesBaseName-$variant.baseName-mapping.txt")).delete()
variant.mappingFile.renameTo(variant.mappingFile.parent +
"/$archivesBaseName-$variant.baseName-mapping.txt")
}
}
}
我将其替换为:
applicationVariants.all { variant ->
variant.assemble.doLast {
if (variant.mappingFile != null && variant.mappingFile.exists()) {
def mappingFilename = "$archivesBaseName-$variant.baseName-mapping.txt"
(new File(variant.mappingFile.parent, mappingFilename)).delete()
variant.mappingFile.renameTo(variant.mappingFile.parent +
"/" + mappingFilename)
}
}
}
或者在你的情况下替换
applicationVariants.all { variant ->
if (variant.getBuildType().isMinifyEnabled()) {
variant.assemble.doLast {
copy {
from variant.mappingFile
into "${rootDir}/proguardTools"
rename { String fileName ->
"mapping-${variant.name}.txt"
}
}
}
}
}
与:
applicationVariants.all { variant ->
variant.assemble.doLast {
if (variant.mappingFile != null && variant.mappingFile.exists()) {
copy {
from variant.mappingFile
into "${rootDir}/proguardTools"
rename { String fileName ->
"mapping-${variant.name}.txt"
}
}
}
}
}
请注意我如何重新安排代码中的条件,以便仅在所有其他组装任务完成后才搜索映射文件。
来自 Android Gradle 插件 3.0 的 sources:
/**
* 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();
该文档含糊不清,没有直接说明使用什么。 在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。回复如下:
我也看不到 latest commit 中的 @Deprecated
注释(在撰写本文时它是 android-8.0.0_r34
),这意味着 API 是 未 已弃用。
作为修复,您可以取消将此行放在 if
语句之前的警告:
//noinspection GrDeprecatedAPIUsage
if (variant.getBuildType().isMinifyEnabled()) {
...
}