Is it possible to use proguard in debug mode?

Solution 1:

If you want to make the whole build process easier for you, you should switch over to gradle and Android Studio IDE.

Then you could easily add the following to your build.gradle file to run ProGuard:

android {
    buildTypes {
        release {
        }
        debug {
            minifyEnabled true
            proguardFile 'proguard-android.txt'
            zipAlignEnabled true
        }
    }
}

This will run ProGuard on your debug build, configured with the file "proguard-android.txt", which should be put at your project's root folder. And in addition your apk is being zip aligned (Just remove "zipAlignEnabled true", if you don't want that to happen). If you want to do the same for your release build, just add those three lines under "release".

Slightly off-topic: Stuff like adding dependencies, signing your apk or adding other custom tasks to your build process is also way more uncomplicated with gradle. In addition you'll be able to not only build your apk via Android Studio IDE, but also via a simple command on the command line (e.g. ./gradlew assembleDebug). So if you are working on a team, the setup process for new members is just one "./gradlew assembleDebug" away. Without the need for any IDE configuration at all. Importing your project including all dependencies is as simple as a one-click process

EDIT: As of Gradle Android Build Tools version 0.14.0 the property names have changed (http://tools.android.com/tech-docs/new-build-system):

  • BuildType.runProguard -> minifyEnabled
  • BuildType.zipAlign -> zipAlignEnabled

I've updated the above code.

Solution 2:

Old Answer :

http://developer.android.com/tools/help/proguard.html

ProGuard runs only when you build your application in release mode, so you do not have to deal with obfuscated code when you build your application in debug mode.

When you build your application in release mode, either by running ant release or by using the Export Wizard in Eclipse, the build system automatically checks to see if the proguard.config property is set. If it is, ProGuard automatically processes the application's bytecode before packaging everything into an .apk file. Building in debug mode does not invoke ProGuard, because it makes debugging more cumbersome.

Update: 13-3-2016

It is possible with the new gradle build system. You need to set minifyEnabled to true in your build.gradle file. Generally you have pro-guard running in release mode. There are other options available like shrinking resources. You can find some useful info @ http://tools.android.com/tech-docs/new-build-system

Also do have a look @

http://developer.android.com/tools/building/configuring-gradle.html

 android {
   ...
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
     debug {

        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
   }
 }

Solution 3:

Regarding custom Ant builds (and based on Victor's answer), adding the following to my build.xml file works for me:

<target name="-debug-obfuscation-check">
    <!-- enable proguard even in debug mode -->
    <property name="proguard.enabled" value="true"/>

    <!-- Secondary dx input (jar files) is empty since all the jar files will be in the obfuscated jar -->
    <path id="out.dex.jar.input.ref" />
</target>

Notice that I had to override (actually pre-set) the out.dex.jar.input.ref; otherwise, the later running of dx will attempt to merge non-disjoint jars and throw the DexException: Multiple dex files define Xxx.

Solution 4:

It is possible if you build with Ant. See Android custom build using Ant on how to build your project with ant. Then, simply override in the project's build.xml the target "-debug-obfuscation-check" and set proguard.enabled to true:

<target name="-debug-obfuscation-check">
    <!-- proguard is never enabled in debug mode -->
    <property name="proguard.enabled" value="true"/>
</target>