问题描述
我遍历了文档,以寻找在运行gradle时如何禁用dexguard但保留插件'dexguard'的方法.
I went through the documentation looking for the way how to disable dexguard when running gradle but keeping plugin: 'dexguard'.
我试图修改proguardFile getDefaultDexGuardFile('dexguard-debug.pro'),但是不幸的是,它什么也没做.我不需要为无法测试apk的功能测试服MonkeyTalk设置任何dexguard功能.
I tried to modify proguardFile getDefaultDexGuardFile('dexguard-debug.pro') to do nothing but unfortunately no luck. I need to set no dexguard functionality for my functional testing suit MonkeyTalk which cannot instrument the apk now.
如何关闭dexguard功能?
How to turn the dexguard functionality off?
推荐答案
从zatziky的答案更新为当前的Android Gradle插件(v1.0 +)和Dexguard插件(6.1.+)
要创建dexguard插件开关,您可以执行以下操作
To create a dexguard plugin switch you may do the following
在您的根 build.gradle
中向您的 ext
添加一个属性(如果尚未创建,请创建它,在此处查看您为什么选择会做到这一点)
In your root build.gradle
add a property to your ext
(or create it if not done yet, see here why you would do that)
ext {
enableDexGuardPlugin = false
....
}
在您的应用程序build.gradle中添加如下所示的插件:
In your app build.gradle add the plugin like this:
apply plugin: 'com.android.application'
if(rootProject.ext.enableDexGuardPlugin) {
apply plugin: 'dexguard'
}
如果您有图书馆项目,请这样做
and if you have library projects do it like this
apply plugin: 'com.android.library'
if(rootProject.ext.enableDexGuardPlugin) {
apply plugin: 'dexguard'
}
如果不需要,请从调试构建类型(尤其是 getDefaultDexGuardFile('dexguard-release.pro')
)中删除所有proguard配置.不幸的是,至少对于lib项目,所有buil类型都可以在assembleDebug中生成,因此您必须为 getDefaultDexGuardFile
提供一个存根,就像 zatziky 所说:
remove all proguard configs from your debug build-types (especially getDefaultDexGuardFile('dexguard-release.pro')
) if you dont need them. Unfortunatly at least with lib projects, all buil-types are build even in assembleDebug, so you have to provide a stub for getDefaultDexGuardFile
like zatziky said:
private File getDefaultDexGuardFile(String name) { new File(name) }
您可以将其添加到根 build.gradle
中,以便每个脚本都具有它.
you may add this to your root build.gradle
so every script has it.
现在,如果您期望从中获得巨大的性能收益,您可能会感到失望.关键是在调试版本中禁用所有 minifyEnabled
,因为如前所述,当前gradle android是愚蠢的,并且会构建所有构建类型(至少使用libs).您可以为其使用上面的属性: enableDexGuardPlugin
Now if you expected huge performance benefits from that you may be disapointed. The key is to disable ALL minifyEnabled
on debug builds, since as said before currently gradle android is dumb and builds all build-types (at least with libs). You may use the property above for it: enableDexGuardPlugin
release {
...
minifyEnabled rootProject.ext.enableDexGuardPlugin
...
}
这篇关于如何禁用Dexguard?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!