<?xml version="1.0" encoding="UTF-8"?>
<!--

Ant rules for DexGuard, the Android app optimizer and obfuscator.

You can enable DexGuard for Ant builds as follows:
1) Define dexguard.dir in local.properties in your Android project, e.g.
     dexguard.dir=/usr/local/dexguard
2) Copy the following files from ${dexguard.dir}/ant to your Android project:
     custom_rules.xml
     dexguard-project.txt

The build process will automatically pick up custom options from the
following (optional) configuration files:
     dexguard-project.txt         (for all targets)
     dexguard-project-debug.txt   (for target 'debug')
     dexguard-project-release.txt (for target 'release')
     proguard-project.txt         (for backward compatibility with ProGuard)

-->

<project name="dexguard_rules" default="debug">

    <fail message="Please define 'dexguard.dir' in the file 'local.properties'"
        unless="dexguard.dir" />

    <fail message="Please correct 'dexguard.dir' in the file 'local.properties' ('${dexguard.dir}' does not exist)">
        <condition><not><resourceexists>
            <file file="${dexguard.dir}"/>
        </resourceexists></not></condition>
    </fail>

    <fail message="Please correct 'dexguard.dir' in the file 'local.properties' ('${dexguard.dir}' exists, but it does not contain 'lib/dexguard.jar')">
        <condition><not><resourceexists>
            <file file="${dexguard.dir}/lib/dexguard.jar"/>
        </resourceexists></not></condition>
    </fail>

    <fail message="Please correct 'sdk.dir' in the file 'local.properties' ('${sdk.dir}' does not exist)">
        <condition><not><resourceexists>
            <file file="${sdk.dir}"/>
        </resourceexists></not></condition>
    </fail>

    <taskdef resource="com/saikoa/dexguard/ant/task.properties"
        classpath="${dexguard.dir}/lib/dexguard.jar" />

    <macrodef name="dexguard-package-helper">
        <attribute name="configuration" />
        <element name="dexguard-options" optional="yes" />
        <sequential>
            <property name="obfuscate.absolute.dir"
                location="${out.absolute.dir}/proguard" />
            <property name="out.native.libs.absolute.dir"
                location="${out.absolute.dir}/native" />
            <mkdir dir="${obfuscate.absolute.dir}" />
            <mkdir dir="${out.native.libs.absolute.dir}" />
            <copyall todir="${out.native.libs.absolute.dir}/lib">
                <fileset dir="${native.libs.absolute.dir}">
                    <include name="*/*.so" />
                </fileset>
                <filteredpath>
                    <path refid="project.library.native.folder.path" />
                    <include name="*/*.so" />
                </filteredpath>
            </copyall>
            <dexguard
                verbose="${verbose}"
                keystore="${key.store}"
                keystorepassword="${key.store.password}"
                keyalias="${key.alias}"
                keypassword="${key.alias.password}"
                printseeds="${obfuscate.absolute.dir}/seeds.txt"
                printusage="${obfuscate.absolute.dir}/usage.txt"
                printmapping="${obfuscate.absolute.dir}/mapping.txt"
                configuration="@{configuration}">
                <configuration file="proguard-project.txt" />
                <configuration file="dexguard-project.txt" />
                <configuration file="dexguard-project-${build.target}.txt" />
                <dexguard-options />
                <libraryjar refid="project.target.class.path" />
            </dexguard>
        </sequential>
    </macrodef>

    <target name="-package-resources" depends="-crunch">
        <do-only-if-not-library elseText="Library project: do not package resources..." >
            <aapt executable="${aapt}"
                command="package"
                versioncode="${version.code}"
                versionname="${version.name}"
                debug="${build.is.packaging.debug}"
                manifest="${out.manifest.abs.file}"
                assets="${asset.absolute.dir}"
                androidjar="${project.target.android.jar}"
                apkfolder="${out.absolute.dir}"
                nocrunch="${build.packaging.nocrunch}"
                resourcefilename="${resource.package.file.name}"
                resourcefilter="${aapt.resource.filter}"
                libraryResFolderPathRefid="project.library.res.folder.path"
                libraryPackagesRefid="project.library.packages"
                libraryRFileRefid="project.library.bin.r.file.path"
                previousBuildType="${build.last.target}"
                buildType="${build.target}"
                ignoreAssets="${aapt.ignore.assets}">
                <res path="${out.res.absolute.dir}" />
                <res path="${resource.absolute.dir}" />
            </aapt>
        </do-only-if-not-library>
    </target>

    <target name="-package" depends="-compile, -post-compile, -package-resources">
        <if condition="${project.is.library}">
            <then>
                <dexguard-package-helper
                    configuration="${dexguard.dir}/lib/dexguard-library-${build.target}.pro">
                    <dexguard-options>
                        <injar path="${out.classes.absolute.dir}" filter="**.class" />
                        <injar path="${source.absolute.dir}"      filter="!**.java,!.hg**,!**/.hg**,!.git**,!**/.git**,!.svn**,!**/.svn**,!CVS,!CVS/**,!**/CVS,!**/CVS/**,!.cvsignore,!**/.cvsignore,!SCCS,!SCCS/**,!**/SCCS,!**/SCCS/**,!**.orig,!**~,lib/*/*.so,!**.so,!**.keep,!**.DS_Store,!**.aidl,!**.rs,!**.rsh,!**.d,!**.java,!**.scala,!**.scc,!**.swp,!**.bak,!**thumbs.db,!**picasa.ini,!**package.html,!**overview.html,!**.AIDL,!**.RS,!**.RSH,!**.D,!**.JAVA,!**.SCALA,!**.SCC,!**.SWP,!**.BAK,!**THUMBS.DB,!**PICASA.INI,!**PACKAGE.HTML,!**OVERVIEW.HTML" />
                        <outjar path="${out.library.jar.file}" filter="!${project.app.package.path}/R.class,!${project.app.package.path}/R$*.class,!${project.app.package.path}/Manifest.class,!${project.app.package.path}/Manifest$*.class,!${project.app.package.path}/BuildConfig.class" />
                        <libraryjar refid="project.all.jars.path" />
                    </dexguard-options>
                </dexguard-package-helper>
            </then>
            <else>
            <if condition="${build.is.instrumented}">
                <then>
                    <dexguard-package-helper
                        configuration="${dexguard.dir}/lib/dexguard-${build.target}.pro">
                        <dexguard-options>
                            <injar path="${out.classes.absolute.dir}"     filter="**.class" />
                            <injar path="${source.absolute.dir}"          filter="!**.java,!.hg**,!**/.hg**,!.git**,!**/.git**,!.svn**,!**/.svn**,!CVS,!CVS/**,!**/CVS,!**/CVS/**,!.cvsignore,!**/.cvsignore,!SCCS,!SCCS/**,!**/SCCS,!**/SCCS/**,!**.orig,!**~,lib/*/*.so,!**.so,!**.keep,!**.DS_Store,!**.aidl,!**.rs,!**.rsh,!**.d,!**.java,!**.scala,!**.scc,!**.swp,!**.bak,!**thumbs.db,!**picasa.ini,!**package.html,!**overview.html,!**.AIDL,!**.RS,!**.RSH,!**.D,!**.JAVA,!**.SCALA,!**.SCC,!**.SWP,!**.BAK,!**THUMBS.DB,!**PICASA.INI,!**PACKAGE.HTML,!**OVERVIEW.HTML" />
                            <injar refid="project.all.jars.path"          filter="!org/w3c/dom/**,!org/xml/sax/**,!org/xmlpull/v1/**,!org/json/*,!org/apache/commons/logging/Log.class,org/apache/http/Consts.class,org/apache/http/HttpHeaders.class,org/apache/http/entity/ContentType.class,org/apache/http/util/Args.class,org/apache/http/util/Asserts.class,org/apache/http/util/CharsetUtils.class,org/apache/http/util/NetUtils.class,org/apache/http/util/TextUtils.class,!org/apache/http/*,!org/apache/http/auth/*,!org/apache/http/auth/params/*,!org/apache/http/client/*,!org/apache/http/client/entity/*,!org/apache/http/client/methods/*,!org/apache/http/client/params/*,!org/apache/http/client/protocol/*,!org/apache/http/client/utils/*Utils.class,!org/apache/http/conn/*,!org/apache/http/conn/params/*,!org/apache/http/conn/routing/*,!org/apache/http/conn/scheme/*,!org/apache/http/conn/ssl/*,!org/apache/http/conn/util/*,!org/apache/http/cookie/*,!org/apache/http/cookie/params/*,!org/apache/http/entity/*,!org/apache/http/impl/*,!org/apache/http/impl/auth/*,!org/apache/http/impl/client/*,!org/apache/http/impl/conn/*,!org/apache/http/impl/conn/tsccm/*,!org/apache/http/impl/cookie/*,!org/apache/http/impl/entity/*,!org/apache/http/impl/io/*,!org/apache/http/io/*,!org/apache/http/message/*,!org/apache/http/params/*,!org/apache/http/protocol/*,!org/apache/http/util/*,META-INF/services/**,!META-INF/**,!.hg**,!**/.hg**,!.git**,!**/.git**,!.svn**,!**/.svn**,!CVS,!CVS/**,!**/CVS,!**/CVS/**,!.cvsignore,!**/.cvsignore,!SCCS,!SCCS/**,!**/SCCS,!**/SCCS/**,!**.orig,!**~,**.class,lib/*/*.so,!**.so,!**.keep,!**.DS_Store,!**.aidl,!**.rs,!**.rsh,!**.d,!**.java,!**.scala,!**.scc,!**.swp,!**.bak,!**thumbs.db,!**picasa.ini,!**package.html,!**overview.html,!**.AIDL,!**.RS,!**.RSH,!**.D,!**.JAVA,!**.SCALA,!**.SCC,!**.SWP,!**.BAK,!**THUMBS.DB,!**PICASA.INI,!**PACKAGE.HTML,!**OVERVIEW.HTML" />
                            <injar path="${out.native.libs.absolute.dir}" filter="lib/*/*.so" />
                            <injar path="${out.absolute.dir}/${resource.package.file.name}" />
                            <injar path="${emma.dir}/emma_device.jar" />
                            <outjar path="${out.final.file}" />
                        </dexguard-options>
                    </dexguard-package-helper>
                </then>
                <else>
                    <dexguard-package-helper
                        configuration="${dexguard.dir}/lib/dexguard-${build.target}.pro">
                        <dexguard-options>
                            <injar path="${out.classes.absolute.dir}"     filter="**.class" />
                            <injar path="${source.absolute.dir}"          filter="!**.java,!.hg**,!**/.hg**,!.git**,!**/.git**,!.svn**,!**/.svn**,!CVS,!CVS/**,!**/CVS,!**/CVS/**,!.cvsignore,!**/.cvsignore,!SCCS,!SCCS/**,!**/SCCS,!**/SCCS/**,!**.orig,!**~,lib/*/*.so,!**.so,!**.keep,!**.DS_Store,!**.aidl,!**.rs,!**.rsh,!**.d,!**.java,!**.scala,!**.scc,!**.swp,!**.bak,!**thumbs.db,!**picasa.ini,!**package.html,!**overview.html,!**.AIDL,!**.RS,!**.RSH,!**.D,!**.JAVA,!**.SCALA,!**.SCC,!**.SWP,!**.BAK,!**THUMBS.DB,!**PICASA.INI,!**PACKAGE.HTML,!**OVERVIEW.HTML" />
                            <injar refid="project.all.jars.path"          filter="!org/w3c/dom/**,!org/xml/sax/**,!org/xmlpull/v1/**,!org/json/*,!org/apache/commons/logging/Log.class,org/apache/http/Consts.class,org/apache/http/HttpHeaders.class,org/apache/http/entity/ContentType.class,org/apache/http/util/Args.class,org/apache/http/util/Asserts.class,org/apache/http/util/CharsetUtils.class,org/apache/http/util/NetUtils.class,org/apache/http/util/TextUtils.class,!org/apache/http/*,!org/apache/http/auth/*,!org/apache/http/auth/params/*,!org/apache/http/client/*,!org/apache/http/client/entity/*,!org/apache/http/client/methods/*,!org/apache/http/client/params/*,!org/apache/http/client/protocol/*,!org/apache/http/client/utils/*Utils.class,!org/apache/http/conn/*,!org/apache/http/conn/params/*,!org/apache/http/conn/routing/*,!org/apache/http/conn/scheme/*,!org/apache/http/conn/ssl/*,!org/apache/http/conn/util/*,!org/apache/http/cookie/*,!org/apache/http/cookie/params/*,!org/apache/http/entity/*,!org/apache/http/impl/*,!org/apache/http/impl/auth/*,!org/apache/http/impl/client/*,!org/apache/http/impl/conn/*,!org/apache/http/impl/conn/tsccm/*,!org/apache/http/impl/cookie/*,!org/apache/http/impl/entity/*,!org/apache/http/impl/io/*,!org/apache/http/io/*,!org/apache/http/message/*,!org/apache/http/params/*,!org/apache/http/protocol/*,!org/apache/http/util/*,META-INF/services/**,!META-INF/**,!.hg**,!**/.hg**,!.git**,!**/.git**,!.svn**,!**/.svn**,!CVS,!CVS/**,!**/CVS,!**/CVS/**,!.cvsignore,!**/.cvsignore,!SCCS,!SCCS/**,!**/SCCS,!**/SCCS/**,!**.orig,!**~,**.class,lib/*/*.so,!**.so,!**.keep,!**.DS_Store,!**.aidl,!**.rs,!**.rsh,!**.d,!**.java,!**.scala,!**.scc,!**.swp,!**.bak,!**thumbs.db,!**picasa.ini,!**package.html,!**overview.html,!**.AIDL,!**.RS,!**.RSH,!**.D,!**.JAVA,!**.SCALA,!**.SCC,!**.SWP,!**.BAK,!**THUMBS.DB,!**PICASA.INI,!**PACKAGE.HTML,!**OVERVIEW.HTML" />
                            <injar path="${out.native.libs.absolute.dir}" filter="lib/*/*.so" />
                            <injar path="${out.absolute.dir}/${resource.package.file.name}" />
                            <outjar path="${out.final.file}" />
                        </dexguard-options>
                    </dexguard-package-helper>
                </else>
            </if>
            </else>
        </if>
    </target>

    <target name="release"    depends="-set-release-mode, -release-prompt-for-password, -package, -post-package, -post-build" />
    <target name="debug"      depends="-set-debug-mode, -set-debug-files, -package, -post-package, -post-build" />
    <target name="instrument" depends="-set-instrumented-mode, debug" />
</project>
