Advertisement
Guest User

TestAppH23 Android Ant Build With Proguard Enabled

a guest
Nov 9th, 2011
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 36.38 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="TestAppH23" default="release">
  3.  
  4. <!-- The local.properties file is created and updated by the 'android'
  5.     tool.
  6.     It contains the path to the SDK. It should *NOT* be checked into
  7.     Version Control Systems. -->
  8.     <property file="local.properties" />
  9.  
  10.     <!-- The build.properties file can be created by you and is never touched
  11.         by the 'android' tool. This is the place to change some of the
  12.         default property values used by the Ant rules.
  13.         Here are some properties you may want to change/update:
  14.  
  15.         source.dir
  16.             The name of the source directory. Default is 'src'.
  17.         out.dir
  18.             The name of the output directory. Default is 'bin'.
  19.  
  20.         Properties related to the SDK location or the project target should
  21.         be updated using the 'android' tool with the 'update' action.
  22.  
  23.         This file is an integral part of the build system for your
  24.         application and should be checked into Version Control Systems.
  25.  
  26.         -->
  27.     <property file="build.properties" />
  28.  
  29.     <!-- The default.properties file is created and updated by the 'android'
  30.         tool, as well as ADT.
  31.         This file is an integral part of the build system for your
  32.         application and should be checked into Version Control Systems. -->
  33.     <property file="default.properties" />
  34.  
  35.  
  36.     <!-- Required pre-setup import -->
  37.     <import file="${sdk.dir}/tools/ant/pre_setup.xml" />
  38.  
  39.  
  40. <!-- extension targets. Uncomment the ones where you want to do custom work
  41.     in between standard targets -->
  42. <!--
  43.    <target name="-pre-build">
  44.    </target>
  45.    <target name="-pre-compile">
  46.    </target>
  47.  
  48.    [This is typically used for code obfuscation.
  49.     Compiled code location: ${out.classes.absolute.dir}
  50.     If this is not done in place, override ${out.dex.input.absolute.dir}]
  51.    <target name="-post-compile">
  52.    </target>
  53. -->
  54.  
  55.     <!-- Execute the Android Setup task that will setup some properties
  56.         specific to the target, and import the build rules files.
  57.  
  58.         The rules file is imported from
  59.            <SDK>/tools/ant/
  60.         Depending on the project type it can be either:
  61.         - main_rules.xml
  62.         - lib_rules.xml
  63.         - test_rules.xml
  64.  
  65.         To customize existing targets, there are two options:
  66.         - Customize only one target:
  67.             - copy/paste the target into this file, *before* the
  68.               <setup> task.
  69.             - customize it to your needs.
  70.         - Customize the whole script.
  71.             - copy/paste the content of the rules files (minus the top node)
  72.               into this file, *after* the <setup> task
  73.             - disable the import of the rules by changing the setup task
  74.               below to <setup import="false" />.
  75.             - customize to your needs.
  76.    -->
  77.     <setup import="true" />
  78.  
  79.     <!--
  80.        This rules file is meant to be imported by the custom Ant task:
  81.            com.android.ant.SetupTask
  82.  
  83.        The following properties are put in place by the importing task:
  84.            android.jar, android.aidl, aapt, aidl, and dx
  85.  
  86.        Additionnaly, the task sets up the following classpath reference:
  87.            android.target.classpath
  88.        This is used by the compiler task as the boot classpath.
  89.    -->
  90.  
  91.     <!-- Custom tasks -->
  92.     <taskdef name="aapt"
  93.        classname="com.android.ant.AaptExecLoopTask"
  94.        classpathref="android.antlibs" />
  95.  
  96.     <taskdef name="aidl"
  97.        classname="com.android.ant.AidlExecTask"
  98.        classpathref="android.antlibs" />
  99.  
  100.     <taskdef name="renderscript"
  101.        classname="com.android.ant.RenderScriptTask"
  102.        classpathref="android.antlibs" />
  103.  
  104.     <taskdef name="apkbuilder"
  105.        classname="com.android.ant.ApkBuilderTask"
  106.        classpathref="android.antlibs" />
  107.  
  108.     <taskdef name="xpath"
  109.        classname="com.android.ant.XPathTask"
  110.        classpathref="android.antlibs" />
  111.  
  112.     <taskdef name="if"
  113.        classname="com.android.ant.IfElseTask"
  114.        classpathref="android.antlibs" />
  115.  
  116.     <!-- Properties -->
  117.  
  118.     <!-- Tells adb which device to target. You can change this from the command line
  119.         by invoking "ant -Dadb.device.arg=-d" for device "ant -Dadb.device.arg=-e" for
  120.         the emulator. -->
  121.     <property name="adb.device.arg" value="" />
  122.  
  123.     <property name="android.tools.dir" location="${sdk.dir}/tools" />
  124.     <property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" />
  125.     <!-- Name of the application package extracted from manifest file -->
  126.     <xpath input="AndroidManifest.xml" expression="/manifest/@package"
  127.                output="manifest.package" />
  128.     <!-- Value of the hasCode attribute (Application node) extracted from manifest file -->
  129.     <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:hasCode"
  130.                output="manifest.hasCode" default="true"/>
  131.  
  132.     <!-- Input directories -->
  133.     <property name="source.dir" value="src" />
  134.     <property name="source.absolute.dir" location="${source.dir}" />
  135.     <property name="gen.dir" value="gen" />
  136.     <property name="gen.absolute.dir" location="${gen.dir}" />
  137.     <property name="resource.dir" value="res" />
  138.     <property name="resource.absolute.dir" location="${resource.dir}" />
  139.     <property name="asset.dir" value="assets" />
  140.     <property name="asset.absolute.dir" location="${asset.dir}" />
  141.  
  142.     <!-- Directory for the third party java libraries -->
  143.     <property name="jar.libs.dir" value="libs" />
  144.     <property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
  145.     <!-- create a path with all the jar files, from the main project and the
  146.         libraries -->
  147.     <path id="jar.libs.ref">
  148.         <fileset dir="${jar.libs.absolute.dir}" includes="*.jar" />
  149.         <path refid="project.libraries.jars" />
  150.     </path>
  151.    
  152.     <!-- Directory for the native libraries -->
  153.     <property name="native.libs.dir" value="libs" />
  154.     <property name="native.libs.absolute.dir" location="${native.libs.dir}" />
  155.  
  156.     <!-- Output directories -->
  157.     <property name="out.dir" value="bin" />
  158.     <property name="out.absolute.dir" location="${out.dir}" />
  159.     <property name="out.classes.dir" value="${out.absolute.dir}/classes" />
  160.     <property name="out.classes.absolute.dir" location="${out.classes.dir}" />
  161.  
  162.     <!-- Intermediate files -->
  163.     <property name="dex.file.name" value="classes.dex" />
  164.     <property name="intermediate.dex.file"
  165.                  location="${out.absolute.dir}/${dex.file.name}" />
  166.     <property name="resource.package.file.name"
  167.                  value="${ant.project.name}.ap_" />
  168.  
  169.     <!-- The final package file to generate
  170.         These can be overridden by setting them earlier to
  171.         different values -->
  172.     <property name="out.debug.unaligned.file"
  173.                  location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" />
  174.     <property name="out.debug.file"
  175.                  location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
  176.  
  177.     <property name="out.unsigned.file.name"
  178.                  value="${ant.project.name}-unsigned.apk" />
  179.     <property name="out.unsigned.file"
  180.                  location="${out.absolute.dir}/${out.unsigned.file.name}" />
  181.  
  182.     <property name="out.unaligned.file.name"
  183.                  value="${ant.project.name}-unaligned.apk" />
  184.     <property name="out.unaligned.file"
  185.                  location="${out.absolute.dir}/${out.unaligned.file.name}" />
  186.  
  187.     <property name="out.release.file.name"
  188.                  value="${ant.project.name}-release.apk" />
  189.     <property name="out.release.file"
  190.                  location="${out.absolute.dir}/${out.release.file.name}" />
  191.  
  192.     <!-- set some properties used for filtering/override. If those weren't defined
  193.         before, then this will create them with empty values, which are then ignored
  194.         by the custom tasks receiving them. -->
  195.     <property name="version.code" value="" />
  196.     <property name="aapt.resource.filter" value="" />
  197.     <property name="filter.abi" value="" />
  198.  
  199.     <!-- compilation options -->
  200.     <property name="java.includeantruntime" value="true" />
  201.     <property name="java.encoding" value="UTF-8" />
  202.     <property name="java.target" value="1.5" />
  203.     <property name="java.source" value="1.5" />
  204.  
  205.     <!-- Verbosity -->
  206.     <property name="verbose" value="false" />
  207.     <!-- This is needed by emma as it uses multilevel verbosity instead of simple 'true' or 'false'
  208.         The property 'verbosity' is not user configurable and depends exclusively on 'verbose'
  209.         value.-->
  210.     <condition property="verbosity" value="verbose" else="quiet">
  211.         <istrue value="${verbose}" />
  212.     </condition>
  213.     <!-- This is needed to switch verbosity of zipalign. Depends exclusively on 'verbose'
  214.         -->
  215.     <condition property="v.option" value="-v" else="">
  216.         <istrue value="${verbose}" />
  217.     </condition>
  218.     <!-- This is needed to switch verbosity of dx. Depends exclusively on 'verbose' -->
  219.     <condition property="verbose.option" value="--verbose" else="">
  220.         <istrue value="${verbose}" />
  221.     </condition>
  222.  
  223.     <!-- properties for signing in release mode -->
  224.     <condition property="has.keystore">
  225.         <and>
  226.             <isset property="key.store" />
  227.             <length string="${key.store}" when="greater" length="0" />
  228.             <isset property="key.alias" />
  229.         </and>
  230.     </condition>
  231.     <condition property="has.password">
  232.         <and>
  233.             <isset property="has.keystore" />
  234.             <isset property="key.store.password" />
  235.             <isset property="key.alias.password" />
  236.         </and>
  237.     </condition>
  238.  
  239.     <!-- Tools -->
  240.     <condition property="exe" value=".exe" else=""><os family="windows" /></condition>
  241.     <property name="adb" location="${android.platform.tools.dir}/adb${exe}" />
  242.     <property name="zipalign" location="${android.tools.dir}/zipalign${exe}" />
  243.  
  244.     <!-- Emma configuration -->
  245.     <property name="emma.dir" value="${sdk.dir}/tools/lib" />
  246.         <path id="emma.lib">
  247.             <pathelement location="${emma.dir}/emma.jar" />
  248.             <pathelement location="${emma.dir}/emma_ant.jar" />
  249.         </path>
  250.     <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
  251.     <!-- End of emma configuration -->
  252.  
  253.     <!-- Macros -->
  254.  
  255.     <!-- Configurable macro, which allows to pass as parameters output directory,
  256.         output dex filename and external libraries to dex (optional) -->
  257.     <macrodef name="dex-helper">
  258.         <element name="external-libs" optional="yes" />
  259.         <element name="extra-parameters" optional="yes" />
  260.         <sequential>
  261.             <!-- sets the primary input for dex. If a pre-dex task sets it to
  262.                 something else this has no effect -->
  263.             <property name="out.dex.input.absolute.dir" value="${out.classes.absolute.dir}" />
  264.  
  265.             <!-- set the secondary dx input: the project (and library) jar files
  266.                 If a pre-dex task sets it to something else this has no effect -->
  267.             <if>
  268.                 <condition>
  269.                     <isreference refid="out.dex.jar.input.ref" />
  270.                 </condition>
  271.                 <else>
  272.                     <path id="out.dex.jar.input.ref">
  273.                         <path refid="jar.libs.ref" />
  274.                     </path>
  275.                 </else>
  276.             </if>
  277.  
  278.             <echo>Converting compiled files and external libraries into ${intermediate.dex.file}...</echo>
  279.             <apply executable="${dx}" failonerror="true" parallel="true">
  280.                 <arg value="--dex" />
  281.                 <arg value="--output=${intermediate.dex.file}" />
  282.                 <extra-parameters />
  283.                 <arg line="${verbose.option}" />
  284.                 <arg path="${out.dex.input.absolute.dir}" />
  285.                 <path refid="out.dex.jar.input.ref" />
  286.                 <external-libs />
  287.             </apply>
  288.         </sequential>
  289.     </macrodef>
  290.  
  291.     <!-- This is macro that enable passing variable list of external jar files to ApkBuilder
  292.         Example of use:
  293.         <package-helper output.filepath="/path/to/foo.apk">
  294.             <extra-jars>
  295.                <jarfolder path="my_jars" />
  296.                <jarfile path="foo/bar.jar" />
  297.                <jarfolder path="your_jars" />
  298.             </extra-jars>
  299.         </package-helper> -->
  300.     <macrodef name="package-helper">
  301.         <attribute name="output.filepath" />
  302.         <element name="extra-jars" optional="yes" />
  303.         <sequential>
  304.             <apkbuilder
  305.                    outfolder="${out.absolute.dir}"
  306.                    resourcefile="${resource.package.file.name}"
  307.                    apkfilepath="@{output.filepath}"
  308.                    debugpackaging="${build.packaging.debug}"
  309.                    debugsigning="${build.signing.debug}"
  310.                    abifilter="${filter.abi}"
  311.                    verbose="${verbose}"
  312.                    hascode="${manifest.hasCode}">
  313.                 <dex path="${intermediate.dex.file}"/>
  314.                 <sourcefolder path="${source.absolute.dir}"/>
  315.                 <sourcefolder refid="project.libraries.src"/>
  316.                 <jarfolder path="${jar.libs.absolute.dir}" />
  317.                 <jarfolder refid="project.libraries.libs" />
  318.                 <nativefolder path="${native.libs.absolute.dir}" />
  319.                 <nativefolder refid="project.libraries.libs" />
  320.                 <extra-jars/>
  321.             </apkbuilder>
  322.         </sequential>
  323.     </macrodef>
  324.  
  325.     <!-- This is macro which zipaligns in.package and outputs it to out.package. Used by targets
  326.         debug, -debug-with-emma and release.-->
  327.     <macrodef name="zipalign-helper">
  328.         <attribute name="in.package" />
  329.         <attribute name="out.package" />
  330.         <sequential>
  331.             <echo>Running zip align on final apk...</echo>
  332.             <exec executable="${zipalign}" failonerror="true">
  333.                 <arg line="${v.option}" />
  334.                 <arg value="-f" />
  335.                 <arg value="4" />
  336.                 <arg path="@{in.package}" />
  337.                 <arg path="@{out.package}" />
  338.             </exec>
  339.         </sequential>
  340.     </macrodef>
  341.  
  342.     <!-- This is macro used only for sharing code among two targets, -install and
  343.         -install-with-emma which do exactly the same but differ in dependencies -->
  344.     <macrodef name="install-helper">
  345.         <sequential>
  346.             <echo>Installing ${out.debug.file} onto default emulator or device...</echo>
  347.             <exec executable="${adb}" failonerror="true">
  348.                 <arg line="${adb.device.arg}" />
  349.                 <arg value="install" />
  350.                 <arg value="-r" />
  351.                 <arg path="${out.debug.file}" />
  352.             </exec>
  353.         </sequential>
  354.     </macrodef>
  355.  
  356.     <!-- Rules -->
  357.  
  358.     <!-- Creates the output directories if they don't exist yet. -->
  359.     <target name="-dirs">
  360.         <echo>Creating output directories if needed...</echo>
  361.         <mkdir dir="${resource.absolute.dir}" />
  362.         <mkdir dir="${jar.libs.absolute.dir}" />
  363.         <mkdir dir="${out.absolute.dir}" />
  364.         <if condition="${manifest.hasCode}">
  365.             <then>
  366.                 <mkdir dir="${gen.absolute.dir}" />
  367.                 <mkdir dir="${out.classes.absolute.dir}" />
  368.             </then>
  369.         </if>
  370.     </target>
  371.  
  372.     <!-- empty default pre-build target. Create a similar target in
  373.         your build.xml and it'll be called instead of this one. -->
  374.     <target name="-pre-build"/>
  375.  
  376.     <!-- Generates the R.java file for this project's resources. -->
  377.     <target name="-resource-src" depends="-dirs">
  378.         <if condition="${manifest.hasCode}">
  379.             <then>
  380.                 <echo>Generating R.java / Manifest.java from the resources...</echo>
  381.                 <aapt executable="${aapt}"
  382.                        command="package"
  383.                        verbose="${verbose}"
  384.                        manifest="AndroidManifest.xml"
  385.                        androidjar="${android.jar}"
  386.                        rfolder="${gen.absolute.dir}">
  387.                     <res path="${resource.absolute.dir}" />
  388.                 </aapt>
  389.             </then>
  390.             <else>
  391.                 <echo>hasCode = false. Skipping...</echo>
  392.             </else>
  393.         </if>
  394.     </target>
  395.  
  396.     <!-- Generates java classes from .aidl files. -->
  397.     <target name="-aidl" depends="-dirs">
  398.         <if condition="${manifest.hasCode}">
  399.             <then>
  400.                 <echo>Compiling aidl files into Java classes...</echo>
  401.                 <aidl executable="${aidl}" framework="${android.aidl}"
  402.                        genFolder="${gen.absolute.dir}">
  403.                     <source path="${source.absolute.dir}"/>
  404.                     <source refid="project.libraries.src"/>
  405.                 </aidl>
  406.             </then>
  407.             <else>
  408.                 <echo>hasCode = false. Skipping...</echo>
  409.             </else>
  410.         </if>
  411.     </target>
  412.  
  413.     <!-- Compiles RenderScript files into Java and bytecode. -->
  414.     <target name="-renderscript" depends="-dirs">
  415.         <if condition="${manifest.hasCode}">
  416.             <then>
  417.                 <echo>Compiling RenderScript files into Java classes and RenderScript bytecode...</echo>
  418.                 <renderscript executable="${renderscript}"
  419.                        framework="${android.rs}"
  420.                        genFolder="${gen.absolute.dir}"
  421.                        resFolder="${resource.absolute.dir}/raw">
  422.                     <source path="${source.absolute.dir}"/>
  423.                     <source refid="project.libraries.src"/>
  424.                 </renderscript>
  425.             </then>
  426.             <else>
  427.                 <echo>hasCode = false. Skipping...</echo>
  428.             </else>
  429.         </if>
  430.     </target>
  431.  
  432.     <!-- empty default pre-compile target. Create a similar target in
  433.         your build.xml and it'll be called instead of this one. -->
  434.     <target name="-pre-compile"/>
  435.  
  436.     <!-- Compiles this project's .java files into .class files. -->
  437.     <target name="compile" depends="-pre-build, -aidl, -renderscript, -resource-src, -pre-compile"
  438.                description="Compiles project's .java files into .class files">
  439.         <if condition="${manifest.hasCode}">
  440.             <then>
  441.                 <!-- If android rules are used for a test project, its classpath should include
  442.                     tested project's location -->
  443.                 <condition property="extensible.classpath"
  444.                        value="${tested.project.absolute.dir}/bin/classes"
  445.                        else=".">
  446.                     <isset property="tested.project.absolute.dir" />
  447.                 </condition>
  448.                 <condition property="extensible.libs.classpath"
  449.                        value="${tested.project.absolute.dir}/libs"
  450.                        else="${jar.libs.dir}">
  451.                     <isset property="tested.project.absolute.dir" />
  452.                 </condition>
  453.                 <javac  includeAntRuntime="${java.includeAntRuntime}"
  454.                         encoding="${java.encoding}"
  455.                        source="${java.source}" target="${java.target}"
  456.                        debug="true" extdirs=""
  457.                        destdir="${out.classes.absolute.dir}"
  458.                        bootclasspathref="android.target.classpath"
  459.                        verbose="${verbose}"
  460.                        classpath="${extensible.classpath}"
  461.                        classpathref="jar.libs.ref">
  462.                     <src path="${source.absolute.dir}" />
  463.                     <src path="${gen.absolute.dir}" />
  464.                     <src refid="project.libraries.src" />
  465.                     <classpath>
  466.                         <fileset dir="${extensible.libs.classpath}" includes="*.jar" />
  467.                     </classpath>
  468.                 </javac>
  469.             </then>
  470.             <else>
  471.                 <echo>hasCode = false. Skipping...</echo>
  472.             </else>
  473.         </if>
  474.     </target>
  475.  
  476.     <!-- empty default post-compile target. Create a similar target in
  477.         your build.xml and it'll be called instead of this one. -->
  478.     <target name="-post-compile"/>
  479.  
  480.     <!-- Obfuscate target
  481.        This is only active in release builds when proguard.config is defined
  482.        in default.properties.
  483.  
  484.        To replace Proguard with a different obfuscation engine:
  485.        Override the following targets in your build.xml, before the call to <setup>
  486.            -release-obfuscation-check
  487.                Check whether obfuscation should happen, and put the result in a property.
  488.            -debug-obfuscation-check
  489.                Obfuscation should not happen. Set the same property to false.
  490.            -obfuscate
  491.                ** Make sure unless="do.not.compile" is used in the target definition **
  492.                check if the property set in -debug/release-obfuscation-check is set to true.
  493.                If true:
  494.                    Perform obfuscation
  495.                    Set property out.dex.input.absolute.dir to be the output of the obfuscation
  496.    -->
  497.     <target name="-obfuscate" unless="do.not.compile">
  498.         <if condition="${proguard.enabled}">
  499.             <then>
  500.                 <property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" />
  501.                 <property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar" />
  502.                 <property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar" />
  503.                 <!-- input for dex will be proguard's output -->
  504.                 <property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" />
  505.  
  506.                 <!-- Add Proguard Tasks -->
  507.                 <property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar" />
  508.                 <taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" />
  509.  
  510.                 <!-- Set the android classpath Path object into a single property. It'll be
  511.                     all the jar files separated by a platform path-separator.
  512.                     Each path must be quoted if it contains spaces.
  513.                -->
  514.                 <pathconvert property="android.libraryjars" refid="android.target.classpath">
  515.                     <firstmatchmapper>
  516.                         <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
  517.                         <identitymapper/>
  518.                     </firstmatchmapper>
  519.                 </pathconvert>
  520.                 <echo>android.libraryjars:${android.libraryjars}</echo>
  521.                 <!-- Build a path object with all the jar files that must be obfuscated.
  522.                     This include the project compiled source code and any 3rd party jar
  523.                     files. -->
  524.                 <path id="project.jars.ref">
  525.                     <pathelement location="${preobfuscate.jar.file}" />
  526.                     <path refid="jar.libs.ref" />
  527.                 </path>
  528.                 <!-- Set the project jar files Path object into a single property. It'll be
  529.                     all the jar files separated by a platform path-separator.
  530.                     Each path must be quoted if it contains spaces.
  531.                -->
  532.                 <pathconvert property="project.jars" refid="project.jars.ref">
  533.                     <firstmatchmapper>
  534.                         <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
  535.                         <identitymapper/>
  536.                     </firstmatchmapper>
  537.                 </pathconvert>
  538.  
  539.                 <mkdir   dir="${obfuscate.absolute.dir}" />
  540.                 <delete file="${preobfuscate.jar.file}"/>
  541.                 <delete file="${obfuscated.jar.file}"/>
  542.                 <jar basedir="${out.classes.dir}"
  543.                    destfile="${preobfuscate.jar.file}" />
  544.                 <proguard>
  545.                     @${proguard.config}
  546.                     -injars       ${project.jars}
  547.                     -outjars      "${obfuscated.jar.file}"
  548.                     -libraryjars  ${android.libraryjars}
  549.                     -dump         "${obfuscate.absolute.dir}/dump.txt"
  550.                     -printseeds   "${obfuscate.absolute.dir}/seeds.txt"
  551.                     -printusage   "${obfuscate.absolute.dir}/usage.txt"
  552.                     -printmapping "${obfuscate.absolute.dir}/mapping.txt"
  553.                 </proguard>
  554.             </then>
  555.         </if>
  556.     </target>
  557.  
  558.     <!-- Converts this project's .class files into .dex files -->
  559.     <target name="-dex" depends="compile, -post-compile, -obfuscate"
  560.            unless="do.not.compile">
  561.         <if condition="${manifest.hasCode}">
  562.             <then>
  563.                 <dex-helper />
  564.             </then>
  565.             <else>
  566.                 <echo>hasCode = false. Skipping...</echo>
  567.             </else>
  568.         </if>
  569.     </target>
  570.  
  571.     <!-- Puts the project's resources into the output package file
  572.         This actually can create multiple resource package in case
  573.         Some custom apk with specific configuration have been
  574.         declared in default.properties.
  575.         -->
  576.     <target name="-package-resources">
  577.         <echo>Packaging resources</echo>
  578.         <aapt executable="${aapt}"
  579.                command="package"
  580.                versioncode="${version.code}"
  581.                debug="${build.packaging.debug}"
  582.                manifest="AndroidManifest.xml"
  583.                assets="${asset.absolute.dir}"
  584.                androidjar="${android.jar}"
  585.                apkfolder="${out.absolute.dir}"
  586.                resourcefilename="${resource.package.file.name}"
  587.                resourcefilter="${aapt.resource.filter}">
  588.             <res path="${resource.absolute.dir}" />
  589.             <!-- <nocompress /> forces no compression on any files in assets or res/raw -->
  590.             <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->
  591.         </aapt>
  592.     </target>
  593.  
  594.     <!-- Packages the application and sign it with a debug key. -->
  595.     <target name="-package-debug-sign" depends="-dex, -package-resources">
  596.         <package-helper
  597.                output.filepath="${out.debug.unaligned.file}" />
  598.     </target>
  599.  
  600.     <!-- Packages the application without signing it. -->
  601.     <target name="-package-release" depends="-dex, -package-resources">
  602.         <package-helper
  603.                output.filepath="${out.unsigned.file}"/>
  604.     </target>
  605.  
  606.     <target name="-compile-tested-if-test" if="tested.project.dir" unless="do.not.compile.again">
  607.        <subant target="compile">
  608.             <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
  609.        </subant>
  610.     </target>
  611.  
  612.     <target name="-debug-obfuscation-check">
  613.         <!-- proguard is never enabled in debug mode -->
  614.         <property name="proguard.enabled" value="false"/>
  615.     </target>
  616.  
  617.     <target name="-set-debug-mode" depends="-debug-obfuscation-check">
  618.         <!-- property only set in debug mode.
  619.             Useful for if/unless attributes in target node
  620.             when using Ant before 1.8 -->
  621.         <property name="build.mode.debug" value="true"/>
  622.  
  623.         <!-- whether the build is a debug build. always set. -->
  624.         <property name="build.packaging.debug" value="true" />
  625.  
  626.         <!-- signing mode: debug -->
  627.         <property name="build.signing.debug" value="true" />
  628.  
  629.     </target>
  630.  
  631.     <!-- Builds debug output package, provided all the necessary files are already dexed -->
  632.     <target name="debug" depends="-set-debug-mode, -compile-tested-if-test, -package-debug-sign"
  633.                description="Builds the application and signs it with a debug key.">
  634.         <zipalign-helper in.package="${out.debug.unaligned.file}"
  635.                                   out.package="${out.debug.file}" />
  636.         <echo>Debug Package: ${out.debug.file}</echo>
  637.     </target>
  638.  
  639.     <!-- called through target 'release'. Only executed if the keystore and
  640.         key alias are known but not their password. -->
  641.     <target name="-release-prompt-for-password" if="has.keystore" unless="has.password">
  642.         <!-- Gets passwords -->
  643.         <input
  644.                message="Please enter keystore password (store:${key.store}):"
  645.                addproperty="key.store.password" />
  646.         <input
  647.                message="Please enter password for alias '${key.alias}':"
  648.                addproperty="key.alias.password" />
  649.     </target>
  650.  
  651.     <!-- called through target 'release'. Only executed if there's no
  652.         keystore/key alias set -->
  653.     <target name="-release-nosign" unless="has.keystore">
  654.         <echo>No key.store and key.alias properties found in build.properties.</echo>
  655.         <echo>Please sign ${out.unsigned.file} manually</echo>
  656.         <echo>and run zipalign from the Android SDK tools.</echo>
  657.     </target>
  658.  
  659.     <target name="-release-obfuscation-check">
  660.         <condition property="proguard.enabled" value="true" else="false">
  661.             <and>
  662.                 <isset property="build.mode.release" />
  663.                 <isset property="proguard.config" />
  664.             </and>
  665.         </condition>
  666.         <if condition="${proguard.enabled}">
  667.             <then>
  668.                 <!-- Secondary dx input (jar files) is empty since all the
  669.                     jar files will be in the obfuscated jar -->
  670.                 <path id="out.dex.jar.input.ref" />
  671.             </then>
  672.         </if>
  673.     </target>
  674.  
  675.     <target name="-set-release-mode">
  676.         <!-- release mode is only valid if the manifest does not explicitly
  677.             set debuggable to true. default is false.
  678.             We actually store build.packaging.debug, not build.release -->
  679.         <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:debuggable"
  680.                output="build.packaging.debug" default="false"/>
  681.  
  682.         <!-- signing mode: release -->
  683.         <property name="build.signing.debug" value="false" />
  684.  
  685.         <if condition="${build.packaging.debug}">
  686.             <then>
  687.                 <echo>*************************************************</echo>
  688.                 <echo>****  Android Manifest has debuggable=true   ****</echo>
  689.                 <echo>**** Doing DEBUG packaging with RELEASE keys ****</echo>
  690.                 <echo>*************************************************</echo>
  691.             </then>
  692.             <else>
  693.                 <!-- property only set in release mode.
  694.                     Useful for if/unless attributes in target node
  695.                     when using Ant before 1.8 -->
  696.                 <property name="build.mode.release" value="true"/>
  697.             </else>
  698.         </if>
  699.     </target>
  700.  
  701.     <!-- This runs -package-release and -release-nosign first and then runs
  702.         only if release-sign is true (set in -release-check,
  703.         called by -release-no-sign)-->
  704.     <target name="release"
  705.                depends="-set-release-mode, -release-obfuscation-check, -package-release, -release-prompt-for-password, -release-nosign"
  706.                if="has.keystore"
  707.                description="Builds the application. The generated apk file must be signed before
  708.                            it is published.">
  709.         <!-- Signs the APK -->
  710.         <echo>Signing final apk...</echo>
  711.         <signjar
  712.                jar="${out.unsigned.file}"
  713.                signedjar="${out.unaligned.file}"
  714.                keystore="${key.store}"
  715.                storepass="${key.store.password}"
  716.                alias="${key.alias}"
  717.                keypass="${key.alias.password}"
  718.                verbose="${verbose}" />
  719.  
  720.         <!-- Zip aligns the APK -->
  721.         <zipalign-helper in.package="${out.unaligned.file}"
  722.                                   out.package="${out.release.file}" />
  723.         <echo>Release Package: ${out.release.file}</echo>
  724.     </target>
  725.  
  726.     <target name="install" depends="debug"
  727.                description="Installs/reinstalls the debug package onto a running
  728.                            emulator or device. If the application was previously installed,
  729.                            the signatures must match." >
  730.         <install-helper />
  731.     </target>
  732.  
  733.     <target name="-uninstall-check">
  734.         <condition property="uninstall.run">
  735.            <isset property="manifest.package" />
  736.         </condition>
  737.     </target>
  738.  
  739.     <target name="-uninstall-error" depends="-uninstall-check" unless="uninstall.run">
  740.         <echo>Unable to run 'ant uninstall', manifest.package property is not defined.
  741.         </echo>
  742.     </target>
  743.  
  744.     <!-- Uninstalls the package from the default emulator/device -->
  745.     <target name="uninstall" depends="-uninstall-error" if="uninstall.run"
  746.                description="Uninstalls the application from a running emulator or device.">
  747.         <echo>Uninstalling ${manifest.package} from the default emulator or device...</echo>
  748.         <exec executable="${adb}" failonerror="true">
  749.             <arg line="${adb.device.arg}" />
  750.             <arg value="uninstall" />
  751.             <arg value="${manifest.package}" />
  752.         </exec>
  753.     </target>
  754.  
  755.     <target name="clean" description="Removes output files created by other targets.">
  756.         <delete dir="${out.absolute.dir}" verbose="${verbose}" />
  757.         <delete dir="${gen.absolute.dir}" verbose="${verbose}" />
  758.     </target>
  759.  
  760.     <!-- Targets for code-coverage measurement purposes, invoked from external file -->
  761.  
  762.     <!-- Emma-instruments tested project classes (compiles the tested project if necessary)
  763.             and writes instrumented classes to ${instrumentation.absolute.dir}/classes -->
  764.     <target name="-emma-instrument" depends="compile">
  765.         <echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
  766.         <!-- It only instruments class files, not any external libs -->
  767.         <emma enabled="true">
  768.             <instr verbosity="${verbosity}"
  769.                   mode="overwrite"
  770.                   instrpath="${out.absolute.dir}/classes"
  771.                   outdir="${out.absolute.dir}/classes">
  772.             </instr>
  773.             <!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
  774.                 user defined file -->
  775.         </emma>
  776.     </target>
  777.  
  778.     <target name="-dex-instrumented" depends="-emma-instrument">
  779.        <dex-helper>
  780.           <extra-parameters>
  781.             <arg value="--no-locals" />
  782.           </extra-parameters>
  783.           <external-libs>
  784.             <fileset file="${emma.dir}/emma_device.jar" />
  785.           </external-libs>
  786.        </dex-helper>
  787.     </target>
  788.  
  789.     <!-- Invoked from external files for code coverage purposes -->
  790.     <target name="-package-with-emma" depends="-dex-instrumented, -package-resources">
  791.         <package-helper
  792.                output.filepath="${out.debug.unaligned.file}">
  793.             <extra-jars>
  794.                 <!-- Injected from external file -->
  795.                 <jarfile path="${emma.dir}/emma_device.jar" />
  796.             </extra-jars>
  797.         </package-helper>
  798.     </target>
  799.  
  800.     <target name="-debug-with-emma" depends="-set-debug-mode, -package-with-emma">
  801.         <zipalign-helper in.package="${out.debug.unaligned.file}"
  802.                                   out.package="${out.debug.file}" />
  803.     </target>
  804.  
  805.     <target name="-install-with-emma" depends="-debug-with-emma">
  806.         <install-helper />
  807.     </target>
  808.  
  809.     <!-- End of targets for code-coverage measurement purposes -->
  810.  
  811.     <target name="help">
  812.         <!-- displays starts at col 13
  813.              |13                                                              80| -->
  814.         <echo>Android Ant Build. Available targets:</echo>
  815.         <echo>   help:      Displays this help.</echo>
  816.         <echo>   clean:     Removes output files created by other targets.</echo>
  817.         <echo>   compile:   Compiles project's .java files into .class files.</echo>
  818.         <echo>   debug:     Builds the application and signs it with a debug key.</echo>
  819.         <echo>   release:   Builds the application. The generated apk file must be</echo>
  820.         <echo>              signed before it is published.</echo>
  821.         <echo>   install:   Installs/reinstalls the debug package onto a running</echo>
  822.         <echo>              emulator or device.</echo>
  823.         <echo>              If the application was previously installed, the</echo>
  824.         <echo>              signatures must match.</echo>
  825.         <echo>   uninstall: Uninstalls the application from a running emulator or</echo>
  826.         <echo>              device.</echo>
  827.     </target>
  828.  
  829. </project>
  830.  
  831.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement