score:47

Accepted answer

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

score:0

with android studio you can use -dontobfuscate option in your proguard rules file and debugger will work fine. i'm not sure if it works with eclipe as well.

score:7

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>

score:11

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.

score:75

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.


Related Query

More Query from same tag