How to disable Dexguard?

為{幸葍}努か 提交于 2021-02-18 17:59:48

问题


I went through the documentation looking for the way how to disable dexguard when running gradle but keeping plugin: '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.

How to turn the dexguard functionality off?


回答1:


Update from zatziky's answer for current Android Gradle Plugin (v1.0+) and Dexguard Plugin (6.1.+)

To create a dexguard plugin switch you may do the following

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
    ....
}

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'
}

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) }

you may add this to your root build.gradle so every script has it.

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
    ...
}



回答2:


It is not possible to keep the dexguard plugin on.

This is a workaround that Eric La Fortune send me and it works (Dexguard 6.x):

For disabling DexGuard, you would need to revert to the Android plugin. You could create a separate Gradle builld file. Alternatively, you could pick the preferred plugin with Groovy. E.g. in

build.gradle:
boolean dexguard = ......

apply plugin: dexguard ? 'dexguard' : 'android'

You can also call the utility method getDefaultDexGuardFile in the same way:

runProguard true
proguardFile dexguard ?
getDefaultDexGuardFile('dexguard-release.pro') :
getDefaultProguardFile('proguard-android.txt')

You do need to define a dummy version of this method in the build file, in case the standard Android plugin is chosen. It is not called in either case, but it solves the missing method definition for the standard plugin:

private File getDefaultDexGuardFile(String name) { new File(name) }



回答3:


In the recent versions of DexGuard you can disable processing for specific build variants simply by not listing the 'proguardFile' lines.

So for example, to disable it for the debug build:

buildTypes {
    debug {
    }
    release {
        proguardFile getDefaultDexGuardFile('dexguard-release.pro')
        proguardFile 'dexguard-project.txt'
        proguardFile 'proguard-project.txt'
    }
}

Edit - all proguardFiles must be gone for it to work



来源:https://stackoverflow.com/questions/27508560/how-to-disable-dexguard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!