Proguard with Android
<p>I want to use proguard with ant to obfuscate my android app:<br>
I am working with <code>mac os x lion</code> and <code>android 2.3.3</code></p>

<p>This is the configuration of <code>build.xml</code>:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project name="Test" default="help"&gt;

&lt;!-- The local.properties file is created and updated by the 'android' tool.
     It contains the path to the SDK. It should *NOT* be checked into
     Version Control Systems. --&gt;
&lt;property file="local.properties" /&gt;

&lt;!-- The ant.properties file can be created by you. It is only edited by the
     'android' tool to add properties to it.
     This is the place to change some Ant specific build properties.
     Here are some properties you may want to change/update:

     source.dir
         The name of the source directory. Default is 'src'.
     out.dir
         The name of the output directory. Default is 'bin'.

     For other overridable properties, look at the beginning of the rules
     files in the SDK, at tools/ant/build.xml

     Properties related to the SDK location or the project target should
     be updated using the 'android' tool with the 'update' action.

     This file is an integral part of the build system for your
     application and should be checked into Version Control Systems.

     --&gt;
&lt;property file="ant.properties" /&gt;

   &lt;!-- The project.properties file is created and updated by the 'android'
       tool, as well as ADT.

       This contains project specific properties such as project target, and library
       dependencies. Lower level build properties are stored in ant.properties
        (or in .classpath for Eclipse projects).

       This file is an integral part of the build system for your
       application and should be checked into Version Control Systems. --&gt;
  &lt;loadproperties srcFile="project.properties" /&gt;

  &lt;!-- quick check on sdk.dir --&gt;
   &lt;fail
          message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
        unless="sdk.dir"
  /&gt;

&lt;!--
    Import per project custom build rules if present at the root of the project.
    This is the place to put custom intermediary targets such as:
        -pre-build
        -pre-compile
        -post-compile (This is typically used for code obfuscation.
                       Compiled code location: ${out.classes.absolute.dir}
                       If this is not done in place, override    ${out.dex.input.absolute.dir})
        -post-package
        -post-build
        -pre-clean
--&gt;
&lt;import file="custom_rules.xml" optional="true" /&gt;

&lt;!-- Import the actual build file.

     To customize existing targets, there are two options:
     - Customize only one target:
         - copy/paste the target into this file, *before* the
           &lt;import&gt; task.
         - customize it to your needs.
     - Customize the whole content of build.xml
         - copy/paste the content of the rules files (minus the top node)
           into this file, replacing the &lt;import&gt; task.
         - customize to your needs.

     ***********************
     ****** IMPORTANT ******
     ***********************
     In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
     in order to avoid having your file be overridden by tools such as "android update project"
--&gt;
&lt;!-- version-tag: 1 --&gt;
&lt;import file="${sdk.dir}/tools/ant/build.xml" /&gt;
   &lt;path id="android.antlibs"&gt;
    &lt;pathelement path="${sdk.dir}/tools/lib/anttasks.jar" /&gt;
    &lt;pathelement path="${sdk.dir}/tools/lib/sdklib.jar" /&gt;
    &lt;pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" /&gt;
    &lt;pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" /&gt;
    &lt;pathelement path="${sdk.dir}/tools/lib/jarutils.jar" /&gt;
    &lt;/path&gt;

&lt;taskdef name="setup"
    classname="com.android.ant.SetupTask"
    classpathref="android.antlibs" /&gt;

&lt;!-- Execute the Android Setup task that will setup some properties specific to the target,
     and import the build rules files.

     The rules file is imported from
        &lt;SDK&gt;/platforms/&lt;target_platform&gt;/templates/android_rules.xml

     To customize some build steps for your project:
     - copy the content of the main node &lt;project&gt; from android_rules.xml
     - paste it in this build.xml below the &lt;setup /&gt; task.
     - disable the import by changing the setup task below to &lt;setup import="false" /&gt;

     This will ensure that the properties are setup correctly but that your customized
     build steps are used.
--&gt;

 &lt;macrodef name="dex-helper"&gt;
       &lt;element name="external-libs" optional="yes" /&gt;
       &lt;element name="extra-parameters" optional="yes" /&gt;
       &lt;sequential&gt;
         &lt;apply executable="${dx}" failonerror="true" parallel="true"&gt;
             &lt;arg value="--dex" /&gt;
             &lt;arg value="--output=${intermediate.dex.file}" /&gt;
             &lt;extra-parameters /&gt;
             &lt;arg line="${verbose.option}" /&gt;
             &lt;arg path="${out.classes.absolute.dir}" /&gt;
             &lt;fileset dir="${external.libs.absolute.dir}" includes="*.jar" /&gt;
             &lt;external-libs /&gt;
         &lt;/apply&gt;
       &lt;/sequential&gt;
    &lt;/macrodef&gt;
&lt;target name="-dex" depends="optimize"&gt; 
      &lt;dex-helper /&gt;
        &lt;/target&gt;
        &lt;property name="proguard-dir" value="proguard"/&gt;
        &lt;property name="unoptimized" value="${proguard-dir}/unoptimized.jar"/&gt;
        &lt;property name="optimized" value="${proguard-dir}/optimized.jar"/&gt;
        &lt;target name="optimize" unless="nooptimize"&gt;
            &lt;jar basedir="${out.classes.dir}" destfile="${unoptimized}"/&gt;

            &lt;java jar="${proguard-dir}/proguard.jar" fork="true" failonerror="true"&gt;
                &lt;jvmarg value="-Dmaximum.inlined.code.length=16"/&gt;
                &lt;arg value="@${proguard-dir}/config.txt"/&gt;          
                &lt;arg value="-injars ${unoptimized}"/&gt;
                &lt;arg value="-outjars ${optimized}"/&gt;
                &lt;arg value="-libraryjars ${android.jar}"/&gt;
            &lt;/java&gt;     

            &lt;delete dir="${out.classes.dir}"/&gt;
            &lt;mkdir dir="${out.classes.dir}"/&gt;
            &lt;unzip src="${proguard-dir}/optimized.jar" dest="${out.classes.dir}"/&gt;
            &lt;delete file="optimized.jar"/&gt;

          &lt;/target&gt;
</code></pre>

<p></p>

<p>and the configuration of <code>project.properties</code>:</p>

<pre><code>target=android-10
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
</code></pre>

<p>when I execute in terminal : ant debug I get this error</p>

<pre><code> Trying to override old definition of task setup
  Trying to override old definition of task dex-helper


-set-mode-check:

 -set-debug-files:


 -set-debug-mode:

 -debug-obfuscation-check:

optimize:

BUILD FAILED
/Users/FikriSaad/Desktop/BIRT/workplace/TestAuthoriseAPI/build.xml:131:         java.lang.OutOfMemoryError: Java heap space
at java.io.UnixFileSystem.list(Native Method)
at java.io.File.list(File.java:973)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1249)
at  org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.accountForIncludedDir(DirectoryScanner.java:1325)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1272)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1203)
at org.apache.tools.ant.DirectoryScanner.scandir(DirectoryScanner.java:1165)
at org.apache.tools.ant.DirectoryScanner.checkIncludePatterns(DirectoryScanner.java:947)
at org.apache.tools.ant.DirectoryScanner.scan(DirectoryScanner.java:901)
at org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFileSet.java:499)
at org.apache.tools.ant.taskdefs.Zip.grabResources(Zip.java:1547)
at org.apache.tools.ant.taskdefs.Zip.getResourcesToAdd(Zip.java:1286)
at org.apache.tools.ant.taskdefs.Zip.getResourcesToAdd(Zip.java:1220)
at org.apache.tools.ant.taskdefs.Jar.getResourcesToAdd(Jar.java:868)
</code></pre>
