Search code examples
android-gradle-pluginmonkeytalkdexguard

How to disable Dexguard?


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?


Solution

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