android – isMinifyEnabled()已弃用.有什么选择?

前端之家收集整理的这篇文章主要介绍了android – 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().有任何帮助提前感谢吗?

解决方法

来自Android Gradle Plugin 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中,我们可以看到,已经执行了这些更改的Michał Bendowski,我已经请求帮助了question in twitter.这是回复

另外我在latest commit中看不到@Deprecated注释(在写这篇文章的时候是android-8.0.0_r34),这意味着API不会在那里被弃用.

作为修复,您可以在if语句之前禁止将此行放入警告:


//noinspection GrDeprecatedAPIUsage
    if (variant.getBuildType().isMinifyEnabled()) {
        ...
    }
原文链接:https://www.f2er.com/android/318040.html

猜你在找的Android相关文章