Question

I want to use ProGruad's for my open source Android app when creating a debug apk with ant debug. I only use ProGuard's optimizations and do not use any code obfuscation settings, i.e. basically the ProGuard configuration from $ANDROID_HOME/tools/proguard/proguard-android-optimize.txt.

But the ProGuard invokation, which is done withing the -obfuscate task in Android's build.xml, is disabled by the debug target. How can I enable it?

Was it helpful?

Solution

In order to configure Android ant build system to invoke proguard even with debug builds, the two variables need to be set: proguard.enabled and out.dex.jar.input.ref.

Here is the example configuration. Put the custom_rules.xml file directly in your projects root.

custom_rules.xml

<project name="android_rules" default="debug">
  <!-- Zap debug-obfuscation-check from SDK's build.xml so that it
       can't set proguard.enabled to false !-->
  <target name="-debug-obfuscation-check"/>
  <target name="-pre-build">
    <condition property="proguard.enabled" value="true" else="false">
      <isset property="proguard.config" />
    </condition>
    <if condition="${proguard.enabled}">
      <then>
    <echo level="info">Proguard.config is enabled</echo>
    <!-- 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" />
      </then>
      <else>
    <echo level="info">Proguard.config is disabled</echo>
      </else>
    </if>
  </target>
</project>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top