1 <?xml version="1.0" encoding="UTF-8"?>
2 <project name="" default="debug">
5 This build file is imported by the project build file. It contains
6 all the targets and tasks necessary to build Android projects, be they
7 regular projects, library projects, or test projects.
9 At the beginning of the file is a list of properties that can be overridden
10 by adding them to your ant.properties (properties are immutable, so their
11 first definition sticks and is never changed).
14 - custom task definitions,
15 - more properties (do not override those unless the whole build system is modified).
16 - macros used throughout the build,
18 - debug-specific build targets,
19 - release-specific build targets,
20 - instrument-specific build targets,
21 - test project-specific build targets,
26 <!-- ******************************************************* -->
27 <!-- **************** Overridable Properties *************** -->
28 <!-- ******************************************************* -->
30 <!-- You can override these values in your build.xml or build.properties.
31 Overriding any other properties may result in broken build. -->
33 <!-- Tells adb which device to target. You can change this from the command line
34 by invoking "ant -Dadb.device.arg=-d" for device "ant -Dadb.device.arg=-e" for
36 <property name="adb.device.arg" value="" />
38 <!-- fileset exclude patterns (space separated) to prevent
39 files inside src/ from being packaged. -->
40 <property name="android.package.excludes" value="" />
42 <!-- set some properties used for filtering/override. If those weren't defined
43 before, then this will create them with empty values, which are then ignored
44 by the custom tasks receiving them. -->
45 <property name="version.code" value="" />
46 <property name="version.name" value="" />
47 <property name="aapt.resource.filter" value="" />
49 <!-- compilation options -->
50 <property name="java.encoding" value="UTF-8" />
51 <property name="java.target" value="1.5" />
52 <property name="java.source" value="1.5" />
55 <property name="verbose" value="false" />
57 <!-- ******************************************************* -->
58 <!-- ********************* Custom Tasks ******************** -->
59 <!-- ******************************************************* -->
61 <!-- jar file from where the tasks are loaded -->
62 <path id="android.antlibs">
63 <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
68 classname="com.android.ant.NewSetupTask"
69 classpathref="android.antlibs" />
72 classname="com.android.ant.AaptExecTask"
73 classpathref="android.antlibs" />
76 classname="com.android.ant.AidlExecTask"
77 classpathref="android.antlibs" />
79 <taskdef name="renderscript"
80 classname="com.android.ant.RenderScriptTask"
81 classpathref="android.antlibs" />
83 <taskdef name="buildconfig"
84 classname="com.android.ant.BuildConfigTask"
85 classpathref="android.antlibs" />
88 classname="com.android.ant.DexExecTask"
89 classpathref="android.antlibs" />
91 <taskdef name="apkbuilder"
92 classname="com.android.ant.ApkBuilderTask"
93 classpathref="android.antlibs" />
95 <taskdef name="zipalign"
96 classname="com.android.ant.ZipAlignTask"
97 classpathref="android.antlibs" />
100 classname="com.android.ant.XPathTask"
101 classpathref="android.antlibs" />
104 classname="com.android.ant.IfElseTask"
105 classpathref="android.antlibs" />
107 <!-- Emma configuration -->
108 <property name="emma.dir" value="${sdk.dir}/tools/lib" />
110 <pathelement location="${emma.dir}/emma.jar" />
111 <pathelement location="${emma.dir}/emma_ant.jar" />
113 <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
114 <!-- End of emma configuration -->
117 <!-- ******************************************************* -->
118 <!-- ******************* Other Properties ****************** -->
119 <!-- ******************************************************* -->
120 <!-- overriding these properties may break the build
121 unless the whole file is updated -->
123 <!-- Input directories -->
124 <property name="source.dir" value="src" />
125 <property name="source.absolute.dir" location="${source.dir}" />
126 <property name="gen.absolute.dir" location="gen" />
127 <property name="resource.absolute.dir" location="res" />
128 <property name="asset.absolute.dir" location="assets" />
129 <property name="jar.libs.dir" value="libs" />
130 <property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
131 <property name="native.libs.absolute.dir" location="libs" />
133 <!-- Output directories -->
134 <property name="out.dir" value="bin" />
135 <property name="out.absolute.dir" location="${out.dir}" />
136 <property name="out.classes.absolute.dir" location="${out.dir}/classes" />
137 <property name="out.res.absolute.dir" location="${out.dir}/res" />
139 <!-- tools location -->
140 <property name="android.tools.dir" location="${sdk.dir}/tools" />
141 <property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" />
142 <condition property="exe" value=".exe" else=""><os family="windows" /></condition>
143 <condition property="bat" value=".bat" else=""><os family="windows" /></condition>
144 <property name="adb" location="${android.platform.tools.dir}/adb${exe}" />
145 <property name="zipalign" location="${android.tools.dir}/zipalign${exe}" />
146 <property name="aidl" location="${android.platform.tools.dir}/aidl${exe}" />
147 <property name="aapt" location="${android.platform.tools.dir}/aapt${exe}" />
148 <property name="dx" location="${android.platform.tools.dir}/dx${bat}" />
149 <!-- renderscript location is set by NewSetupTask since we have a choice of
150 several executables based on minSdkVersion -->
152 <!-- Intermediate files -->
153 <property name="dex.file.name" value="classes.dex" />
154 <property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" />
155 <property name="resource.package.file.name" value="${ant.project.name}.ap_" />
157 <!-- Build property file -->
158 <property name="out.build.prop.file" location="${out.absolute.dir}/build.prop" />
161 <!-- This is needed by emma as it uses multilevel verbosity instead of simple 'true' or 'false'
162 The property 'verbosity' is not user configurable and depends exclusively on 'verbose'
164 <condition property="verbosity" value="verbose" else="quiet">
165 <istrue value="${verbose}" />
168 <!-- properties for signing in release mode -->
169 <condition property="has.keystore">
171 <isset property="key.store" />
172 <length string="${key.store}" when="greater" length="0" />
173 <isset property="key.alias" />
176 <condition property="has.password">
178 <isset property="has.keystore" />
179 <isset property="key.store.password" />
180 <isset property="key.alias.password" />
184 <!-- properties for packaging -->
185 <property name="build.packaging.nocrunch" value="true" />
187 <!-- ******************************************************* -->
188 <!-- ************************ Macros *********************** -->
189 <!-- ******************************************************* -->
191 <!-- macro to do a task on if project.is.library is false.
192 elseText attribute is displayed otherwise -->
193 <macrodef name="do-only-if-not-library">
194 <attribute name="elseText" />
195 <element name="task-to-do" implicit="yes" />
197 <if condition="${project.is.library}">
202 <echo>@{elseText}</echo>
208 <!-- macro to do a task on if manifest.hasCode is true.
209 elseText attribute is displayed otherwise -->
210 <macrodef name="do-only-if-manifest-hasCode">
211 <attribute name="elseText" default=""/>
212 <element name="task-to-do" implicit="yes" />
214 <if condition="${manifest.hasCode}">
221 <length string="@{elseText}" trim="true" when="greater" length="0" />
224 <echo>@{elseText}</echo>
233 <!-- Configurable macro, which allows to pass as parameters output directory,
234 output dex filename and external libraries to dex (optional) -->
235 <macrodef name="dex-helper">
236 <element name="external-libs" optional="yes" />
237 <attribute name="nolocals" default="false" />
239 <!-- sets the primary input for dex. If a pre-dex task sets it to
240 something else this has no effect -->
241 <property name="out.dex.input.absolute.dir" value="${out.classes.absolute.dir}" />
243 <!-- set the secondary dx input: the project (and library) jar files
244 If a pre-dex task sets it to something else this has no effect -->
247 <isreference refid="out.dex.jar.input.ref" />
250 <path id="out.dex.jar.input.ref">
251 <path refid="jar.libs.ref" />
256 <dex executable="${dx}"
257 output="${intermediate.dex.file}"
258 nolocals="@{nolocals}"
259 verbose="${verbose}">
260 <path path="${out.dex.input.absolute.dir}"/>
261 <path refid="out.dex.jar.input.ref" />
267 <!-- This is macro that enable passing variable list of external jar files to ApkBuilder
271 <jarfolder path="my_jars" />
272 <jarfile path="foo/bar.jar" />
273 <jarfolder path="your_jars" />
275 </package-helper> -->
276 <macrodef name="package-helper">
277 <element name="extra-jars" optional="yes" />
280 outfolder="${out.absolute.dir}"
281 resourcefile="${resource.package.file.name}"
282 apkfilepath="${out.packaged.file}"
283 debugpackaging="${build.is.packaging.debug}"
284 debugsigning="${build.is.signing.debug}"
286 hascode="${manifest.hasCode}"
287 previousBuildType="${build.last.is.packaging.debug}/${build.last.is.signing.debug}"
288 buildType="${build.is.packaging.debug}/${build.is.signing.debug}">
289 <dex path="${intermediate.dex.file}"/>
290 <sourcefolder path="${source.absolute.dir}"/>
291 <jarfile refid="jar.libs.ref" />
292 <nativefolder path="${native.libs.absolute.dir}" />
293 <nativefolder refid="project.libraries.libs" />
299 <!-- This is macro which zipaligns in.package and outputs it to out.package. Used by targets
300 debug, -debug-with-emma and release.-->
301 <macrodef name="zipalign-helper">
302 <attribute name="in.package" />
303 <attribute name="out.package" />
306 executable="${zipalign}"
307 input="@{in.package}"
308 output="@{out.package}"
309 verbose="${verbose}" />
313 <macrodef name="run-tests-helper">
314 <attribute name="emma.enabled" default="false" />
315 <element name="extra-instrument-args" optional="yes" />
317 <echo>Running tests ...</echo>
318 <exec executable="${adb}" failonerror="true">
319 <arg line="${adb.device.arg}" />
320 <arg value="shell" />
322 <arg value="instrument" />
325 <arg value="coverage" />
326 <arg value="@{emma.enabled}" />
327 <extra-instrument-args />
328 <arg value="${tested.manifest.package}/${test.runner}" />
333 <macrodef name="record-build-key">
334 <attribute name="key" default="false" />
335 <attribute name="value" default="false" />
337 <propertyfile file="${out.build.prop.file}" comment="Last build type">
338 <entry key="@{key}" value="@{value}"/>
343 <macrodef name="record-build-info">
345 <record-build-key key="build.last.target" value="${build.target}" />
346 <record-build-key key="build.last.is.instrumented" value="${build.is.instrumented}" />
347 <record-build-key key="build.last.is.packaging.debug" value="${build.is.packaging.debug}" />
348 <record-build-key key="build.last.is.signing.debug" value="${build.is.signing.debug}" />
352 <macrodef name="uninstall-helper">
353 <attribute name="app.package" default="false" />
355 <echo>Uninstalling @{app.package} from the default emulator or device...</echo>
356 <exec executable="${adb}" failonerror="true">
357 <arg line="${adb.device.arg}" />
358 <arg value="uninstall" />
359 <arg value="@{app.package}" />
364 <!-- ******************************************************* -->
365 <!-- ******************** Build Targets ******************** -->
366 <!-- ******************************************************* -->
368 <!-- target to disable building dependencies -->
369 <target name="nodeps">
370 <property name="dont.build.deps" value="true" />
373 <!-- this target simply force running -setup making
374 the project info be read. To be used as
376 to clean the main project as well as the libraries and tested project -->
377 <target name="all" depends="-setup"/>
379 <!-- clean target -->
380 <target name="clean" description="Removes output files created by other targets.">
381 <delete dir="${out.absolute.dir}" verbose="${verbose}" />
382 <delete dir="${gen.absolute.dir}" verbose="${verbose}" />
384 <!-- if we know about a tested project or libraries, we clean them too. This
385 will only work if the target 'all' was called first -->
386 <if condition="${project.is.test}">
388 <property name="tested.project.absolute.dir" location="${tested.project.dir}" />
389 <subant failonerror="true">
390 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
391 <target name="all" />
392 <target name="clean" />
399 <isreference refid="project.libraries" />
403 buildpathref="project.libraries"
406 <target name="all" />
407 <target name="clean" />
413 <!-- generic setup -->
414 <target name="-setup">
417 <not><isset property="setup.done" /></not>
420 <property name="setup.done" value="true" />
421 <echo>Gathering info for ${ant.project.name}...</echo>
422 <!-- load project properties, resolve Android target, library dependencies
423 and set some properties with the results.
424 All property names are passed as parameters ending in -Out -->
426 projectTypeOut="android.project.type"
427 androidJarFileOut="android.jar"
428 androidAidlFileOut="android.aidl"
429 renderScriptExeOut="renderscript"
430 renderScriptIncludeDirOut="android.rs"
431 bootclasspathrefOut="android.target.classpath"
432 projectLibrariesRootOut="project.libraries"
433 projectLibrariesJarsOut="project.libraries.jars"
434 projectLibrariesResOut="project.libraries.res"
435 projectLibrariesPackageOut="project.libraries.package"
436 projectLibrariesLibsOut="project.libraries.libs"
437 targetApiOut="target.api"
440 <!-- sets a few boolean based on android.project.type
441 to make the if task easier -->
442 <condition property="project.is.library" else="false">
443 <equals arg1="${android.project.type}" arg2="library" />
445 <condition property="project.is.test" else="false">
446 <equals arg1="${android.project.type}" arg2="test" />
449 <!-- If a test project, resolve absolute path to tested project. -->
450 <if condition="${project.is.test}">
452 <property name="tested.project.absolute.dir" location="${tested.project.dir}" />
459 <!-- Pre build setup -->
460 <target name="-build-setup" depends="-setup">
462 <!-- read the previous build mode -->
463 <property file="${out.build.prop.file}" />
464 <!-- if empty the props won't be set, meaning it's a new build.
465 To force a build, set the prop to empty values. -->
466 <property name="build.last.target" value="" />
467 <property name="build.last.is.instrumented" value="" />
468 <property name="build.last.is.packaging.debug" value="" />
469 <property name="build.last.is.signing.debug" value="" />
471 <!-- compile the libraries if any -->
475 <isreference refid="project.libraries" />
476 <not><isset property="dont.build.deps" /></not>
480 <echo>Building Libraries</echo>
481 <subant failonerror="true"
482 buildpathref="project.libraries"
484 <target name="nodeps" />
485 <target name="${build.target}" />
488 <echo>############################################</echo>
489 <echo>**** Back to project ${ant.project.name} ****</echo>
490 <echo>############################################</echo>
494 <!-- compile the main project if this is a test project -->
495 <if condition="${project.is.test}">
497 <!-- figure out which target must be used to build the tested project.
498 If emma is enabled, then use 'instrument' otherwise, use 'debug' -->
499 <condition property="tested.project.target" value="instrument" else="debug">
500 <isset property="emma.enabled" />
503 <echo>Building tested project at ${tested.project.absolute.dir}</echo>
504 <subant target="${tested.project.target}" failonerror="true">
505 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
508 <echo>############################################</echo>
509 <echo>**** Back to project ${ant.project.name} ****</echo>
510 <echo>############################################</echo>
514 <!-- Value of the hasCode attribute (Application node) extracted from manifest file -->
515 <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:hasCode"
516 output="manifest.hasCode" default="true"/>
518 <!-- create a path with all the jar files, from the main project and the
520 <path id="jar.libs.ref">
521 <fileset dir="${jar.libs.absolute.dir}" includes="*.jar" />
522 <path refid="project.libraries.jars" />
525 <!-- If the "debug" build type changed, clear out the compiled code.
526 This is to make sure the new BuildConfig.DEBUG value is picked up
527 as javac can't deal with this type of change in its dependency computation. -->
531 <length string="${build.last.is.packaging.debug}" trim="true" when="greater" length="0" />
533 arg1="${build.is.packaging.debug}"
534 arg2="${build.last.is.packaging.debug}" /></not>
538 <echo>Switching between debug and non debug build: Deleting previous compilation output...</echo>
539 <delete dir="${out.classes.absolute.dir}" verbose="${verbose}" />
542 <!-- Else, we may still need to clean the code, for another reason.
543 special case for instrumented: if the previous build was
544 instrumented but not this one, clear out the compiled code -->
548 <istrue value="${build.last.is.instrumented}" />
549 <isfalse value="${build.is.instrumented}" />
553 <echo>Switching from instrumented to non-instrumented build: Deleting previous compilation output...</echo>
554 <delete dir="${out.classes.absolute.dir}" verbose="${verbose}" />
560 <echo>Creating output directories if needed...</echo>
561 <mkdir dir="${resource.absolute.dir}" />
562 <mkdir dir="${jar.libs.absolute.dir}" />
563 <mkdir dir="${out.absolute.dir}" />
564 <mkdir dir="${out.res.absolute.dir}" />
565 <do-only-if-manifest-hasCode>
566 <mkdir dir="${gen.absolute.dir}" />
567 <mkdir dir="${out.classes.absolute.dir}" />
568 </do-only-if-manifest-hasCode>
571 <!-- empty default pre-build target. Create a similar target in
572 your build.xml and it'll be called instead of this one. -->
573 <target name="-pre-build"/>
575 <!-- Code Generation: compile resources (aapt -> R.java), aidl, renderscript -->
576 <target name="-code-gen">
577 <do-only-if-manifest-hasCode
578 elseText="hasCode = false. Skipping aidl/renderscript/R.java">
579 <echo>----------</echo>
580 <echo>Handling aidl files...</echo>
581 <aidl executable="${aidl}" framework="${android.aidl}"
582 genFolder="${gen.absolute.dir}">
583 <source path="${source.absolute.dir}"/>
586 <!-- renderscript generates resources so it must be called before aapt -->
587 <echo>----------</echo>
588 <echo>Handling RenderScript files...</echo>
589 <renderscript executable="${renderscript}"
590 framework="${android.rs}"
591 genFolder="${gen.absolute.dir}"
592 resFolder="${out.res.absolute.dir}/raw"
593 targetApi="${target.api}">
594 <source path="${source.absolute.dir}"/>
597 <echo>----------</echo>
598 <echo>Handling Resources...</echo>
599 <aapt executable="${aapt}"
602 manifest="AndroidManifest.xml"
603 androidjar="${android.jar}"
604 rfolder="${gen.absolute.dir}"
605 nonConstantId="${android.library}"
606 projectLibrariesResName="project.libraries.res"
607 projectLibrariesPackageName="project.libraries.package">
608 <res path="${out.res.absolute.dir}" />
609 <res path="${resource.absolute.dir}" />
612 <echo>----------</echo>
613 <echo>Handling BuildConfig class...</echo>
614 <xpath input="AndroidManifest.xml" expression="/manifest/@package"
615 output="manifest.package" />
617 genFolder="${gen.absolute.dir}"
618 package="${manifest.package}"
619 buildType="${build.is.packaging.debug}"
620 previousBuildType="${build.last.is.packaging.debug}"/>
622 </do-only-if-manifest-hasCode>
625 <!-- empty default pre-compile target. Create a similar target in
626 your build.xml and it'll be called instead of this one. -->
627 <target name="-pre-compile"/>
629 <!-- Compiles this project's .java files into .class files. -->
630 <target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile">
631 <do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
632 <!-- If android rules are used for a test project, its classpath should include
633 tested project's location -->
634 <condition property="extensible.classpath"
635 value="${tested.project.absolute.dir}/bin/classes"
637 <isset property="tested.project.absolute.dir" />
639 <condition property="extensible.libs.classpath"
640 value="${tested.project.absolute.dir}/${jar.libs.dir}"
641 else="${jar.libs.dir}">
642 <isset property="tested.project.absolute.dir" />
644 <javac encoding="${java.encoding}"
645 source="${java.source}" target="${java.target}"
646 debug="true" extdirs="" includeantruntime="false"
647 destdir="${out.classes.absolute.dir}"
648 bootclasspathref="android.target.classpath"
650 classpath="${extensible.classpath}"
651 classpathref="jar.libs.ref">
652 <src path="${source.absolute.dir}" />
653 <src path="${gen.absolute.dir}" />
655 <fileset dir="${extensible.libs.classpath}" includes="*.jar" />
658 <!-- if the project is a library then we generate a jar file -->
659 <if condition="${project.is.library}">
661 <echo>Creating library output jar file...</echo>
662 <property name="out.library.jar.file" location="${out.absolute.dir}/classes.jar" />
665 <length string="${android.package.excludes}" trim="true" when="greater" length="0" />
668 <echo>Custom jar packaging exclusion: ${android.package.excludes}</echo>
671 <jar destfile="${out.library.jar.file}">
672 <fileset dir="${out.classes.absolute.dir}" excludes="**/R.class **/R$*.class"/>
673 <fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" />
678 <!-- if the project is instrumented, intrument the classes -->
679 <if condition="${build.is.instrumented}">
681 <echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
682 <!-- It only instruments class files, not any external libs -->
683 <emma enabled="true">
684 <instr verbosity="${verbosity}"
686 instrpath="${out.absolute.dir}/classes"
687 outdir="${out.absolute.dir}/classes">
689 <!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
690 user defined file -->
694 </do-only-if-manifest-hasCode>
697 <!-- empty default post-compile target. Create a similar target in
698 your build.xml and it'll be called instead of this one. -->
699 <target name="-post-compile"/>
701 <!-- Obfuscate target
702 This is only active in release builds when proguard.config is defined
703 in default.properties.
705 To replace Proguard with a different obfuscation engine:
706 Override the following targets in your build.xml, before the call to <setup>
707 -release-obfuscation-check
708 Check whether obfuscation should happen, and put the result in a property.
709 -debug-obfuscation-check
710 Obfuscation should not happen. Set the same property to false.
712 check if the property set in -debug/release-obfuscation-check is set to true.
715 Set property out.dex.input.absolute.dir to be the output of the obfuscation
717 <target name="-obfuscate">
718 <if condition="${proguard.enabled}">
720 <property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" />
721 <property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar" />
722 <property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar" />
723 <!-- input for dex will be proguard's output -->
724 <property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" />
726 <!-- Add Proguard Tasks -->
727 <property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar" />
728 <taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" />
730 <!-- Set the android classpath Path object into a single property. It'll be
731 all the jar files separated by a platform path-separator.
732 Each path must be quoted if it contains spaces.
734 <pathconvert property="android.libraryjars" refid="android.target.classpath">
736 <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
741 <!-- Build a path object with all the jar files that must be obfuscated.
742 This include the project compiled source code and any 3rd party jar
744 <path id="project.jars.ref">
745 <pathelement location="${preobfuscate.jar.file}" />
746 <path refid="jar.libs.ref" />
748 <!-- Set the project jar files Path object into a single property. It'll be
749 all the jar files separated by a platform path-separator.
750 Each path must be quoted if it contains spaces.
752 <pathconvert property="project.jars" refid="project.jars.ref">
754 <regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"'/>
759 <mkdir dir="${obfuscate.absolute.dir}" />
760 <delete file="${preobfuscate.jar.file}"/>
761 <delete file="${obfuscated.jar.file}"/>
762 <jar basedir="${out.classes.absolute.dir}"
763 destfile="${preobfuscate.jar.file}" />
766 -injars ${project.jars}
767 -outjars "${obfuscated.jar.file}"
768 -libraryjars ${android.libraryjars}
769 -dump "${obfuscate.absolute.dir}/dump.txt"
770 -printseeds "${obfuscate.absolute.dir}/seeds.txt"
771 -printusage "${obfuscate.absolute.dir}/usage.txt"
772 -printmapping "${obfuscate.absolute.dir}/mapping.txt"
778 <!-- Converts this project's .class files into .dex files -->
779 <target name="-dex" depends="-compile, -post-compile, -obfuscate">
780 <do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
781 <!-- only convert to dalvik bytecode is *not* a library -->
782 <do-only-if-not-library elseText="Library project: do not convert bytecode..." >
783 <!-- special case for instrumented builds: need to use no-locals and need
784 to pass in the emma jar. -->
785 <if condition="${build.is.instrumented}">
787 <dex-helper nolocals="true">
789 <fileset file="${emma.dir}/emma_device.jar" />
797 </do-only-if-not-library>
798 </do-only-if-manifest-hasCode>
801 <!-- Updates the pre-processed PNG cache -->
802 <target name="-crunch">
803 <exec executable="${aapt}" taskName="crunch">
804 <arg value="crunch" />
807 <arg path="${resource.absolute.dir}" />
809 <arg path="${out.res.absolute.dir}" />
813 <!-- Puts the project's resources into the output package file
814 This actually can create multiple resource package in case
815 Some custom apk with specific configuration have been
816 declared in default.properties.
818 <target name="-package-resources" depends="-crunch">
819 <!-- only package resources if *not* a library project -->
820 <do-only-if-not-library elseText="Library project: do not package resources..." >
821 <aapt executable="${aapt}"
823 versioncode="${version.code}"
824 versionname="${version.name}"
825 debug="${build.is.packaging.debug}"
826 manifest="AndroidManifest.xml"
827 assets="${asset.absolute.dir}"
828 androidjar="${android.jar}"
829 apkfolder="${out.absolute.dir}"
830 nocrunch="${build.packaging.nocrunch}"
831 resourcefilename="${resource.package.file.name}"
832 resourcefilter="${aapt.resource.filter}"
833 projectLibrariesResName="project.libraries.res"
834 projectLibrariesPackageName="project.libraries.package"
835 previousBuildType="${build.last.target}"
836 buildType="${build.target}">
837 <res path="${out.res.absolute.dir}" />
838 <res path="${resource.absolute.dir}" />
839 <!-- <nocompress /> forces no compression on any files in assets or res/raw -->
840 <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->
842 </do-only-if-not-library>
845 <!-- Packages the application. -->
846 <target name="-package" depends="-dex, -package-resources">
847 <!-- only package apk if *not* a library project -->
848 <do-only-if-not-library elseText="Library project: do not package apk..." >
849 <if condition="${build.is.instrumented}">
853 <!-- Injected from external file -->
854 <jarfile path="${emma.dir}/emma_device.jar" />
862 </do-only-if-not-library>
865 <target name="-set-mode-check">
866 <fail if="out.final.file"
867 message="Cannot run two different modes at the same time. If you are running more than one debug/release/instrument type targets, call them from different Ant calls." />
870 <!-- ******************************************************* -->
871 <!-- **************** Debug specific targets *************** -->
872 <!-- ******************************************************* -->
874 <target name="-set-debug-files" depends="-set-mode-check">
876 <property name="out.packaged.file" location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" />
877 <property name="out.final.file" location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
881 <target name="-set-debug-mode">
882 <!-- record the current build target -->
883 <property name="build.target" value="debug" />
885 <property name="build.is.instrumented" value="false" />
887 <!-- whether the build is a debug build. always set. -->
888 <property name="build.is.packaging.debug" value="true" />
890 <!-- signing mode: debug -->
891 <property name="build.is.signing.debug" value="true" />
895 <target name="-debug-obfuscation-check">
896 <!-- proguard is never enabled in debug mode -->
897 <property name="proguard.enabled" value="false"/>
900 <!-- Builds debug output package -->
901 <target name="-do-debug" depends="-set-debug-mode, -debug-obfuscation-check, -package">
902 <!-- only create apk if *not* a library project -->
903 <do-only-if-not-library elseText="Library project: do not create apk..." >
905 <zipalign-helper in.package="${out.packaged.file}" out.package="${out.final.file}" />
906 <echo>Debug Package: ${out.final.file}</echo>
908 </do-only-if-not-library>
911 <!-- Builds debug output package -->
912 <target name="debug" depends="-set-debug-files, -do-debug"
913 description="Builds the application and signs it with a debug key.">
914 <record-build-info />
918 <!-- ******************************************************* -->
919 <!-- *************** Release specific targets ************** -->
920 <!-- ******************************************************* -->
922 <!-- called through target 'release'. Only executed if the keystore and
923 key alias are known but not their password. -->
924 <target name="-release-prompt-for-password" if="has.keystore" unless="has.password">
925 <!-- Gets passwords -->
927 message="Please enter keystore password (store:${key.store}):"
928 addproperty="key.store.password" />
930 message="Please enter password for alias '${key.alias}':"
931 addproperty="key.alias.password" />
934 <!-- called through target 'release'. Only executed if there's no
935 keystore/key alias set -->
936 <target name="-release-nosign" unless="has.keystore">
937 <!-- no release builds for library project -->
938 <do-only-if-not-library elseText="" >
940 <echo>No key.store and key.alias properties found in build.properties.</echo>
941 <echo>Please sign ${out.packaged.file} manually</echo>
942 <echo>and run zipalign from the Android SDK tools.</echo>
944 </do-only-if-not-library>
945 <record-build-info />
948 <target name="-release-obfuscation-check">
949 <condition property="proguard.enabled" value="true" else="false">
951 <isset property="build.is.mode.release" />
952 <isset property="proguard.config" />
955 <if condition="${proguard.enabled}">
957 <!-- Secondary dx input (jar files) is empty since all the
958 jar files will be in the obfuscated jar -->
959 <path id="out.dex.jar.input.ref" />
964 <target name="-set-release-mode" depends="-set-mode-check">
965 <property name="out.packaged.file" location="${out.absolute.dir}/${ant.project.name}-release-unsigned.apk" />
966 <property name="out.final.file" location="${out.absolute.dir}/${ant.project.name}-release.apk" />
968 <!-- record the current build target -->
969 <property name="build.target" value="release" />
971 <property name="build.is.instrumented" value="false" />
973 <!-- release mode is only valid if the manifest does not explicitly
974 set debuggable to true. default is false. -->
975 <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:debuggable"
976 output="build.is.packaging.debug" default="false"/>
978 <!-- signing mode: release -->
979 <property name="build.is.signing.debug" value="false" />
981 <if condition="${build.is.packaging.debug}">
983 <echo>*************************************************</echo>
984 <echo>**** Android Manifest has debuggable=true ****</echo>
985 <echo>**** Doing DEBUG packaging with RELEASE keys ****</echo>
986 <echo>*************************************************</echo>
989 <!-- property only set in release mode.
990 Useful for if/unless attributes in target node
991 when using Ant before 1.8 -->
992 <property name="build.is.mode.release" value="true"/>
997 <!-- This runs -package-release and -release-nosign first and then runs
998 only if release-sign is true (set in -release-check,
999 called by -release-no-sign)-->
1000 <target name="release"
1001 depends="-set-release-mode, -release-obfuscation-check, -package, -release-prompt-for-password, -release-nosign"
1003 description="Builds the application. The generated apk file must be signed before
1006 <!-- only create apk if *not* a library project -->
1007 <do-only-if-not-library elseText="Library project: do not create apk..." >
1009 <property name="out.unaligned.file" location="${out.absolute.dir}/${ant.project.name}-release-unaligned.apk" />
1011 <!-- Signs the APK -->
1012 <echo>Signing final apk...</echo>
1014 jar="${out.packaged.file}"
1015 signedjar="${out.unaligned.file}"
1016 keystore="${key.store}"
1017 storepass="${key.store.password}"
1018 alias="${key.alias}"
1019 keypass="${key.alias.password}"
1020 verbose="${verbose}" />
1022 <!-- Zip aligns the APK -->
1023 <zipalign-helper in.package="${out.unaligned.file}"
1024 out.package="${out.final.file}" />
1025 <echo>Release Package: ${out.final.file}</echo>
1027 </do-only-if-not-library>
1028 <record-build-info />
1031 <!-- ******************************************************* -->
1032 <!-- ************ Instrumented specific targets ************ -->
1033 <!-- ******************************************************* -->
1035 <!-- These targets are specific for the project under test when it
1036 gets compiled by the test projects in a way that will make it
1037 support emma code coverage -->
1039 <target name="-set-instrumented-mode" depends="-set-mode-check">
1040 <property name="out.packaged.file" location="${out.absolute.dir}/${ant.project.name}-instrumented-unaligned.apk" />
1041 <property name="out.final.file" location="${out.absolute.dir}/${ant.project.name}-instrumented.apk" />
1043 <!-- whether the build is an instrumented build. -->
1044 <property name="build.is.instrumented" value="true" />
1047 <!-- Builds instrumented output package -->
1048 <target name="instrument" depends="-set-instrumented-mode, -do-debug"
1049 description="Builds an instrumented packaged.">
1050 <!-- only create apk if *not* a library project -->
1051 <do-only-if-not-library elseText="Library project: do not create apk..." >
1053 <zipalign-helper in.package="${out.packaged.file}" out.package="${out.final.file}" />
1054 <echo>Instrumented Package: ${out.final.file}</echo>
1056 </do-only-if-not-library>
1057 <record-build-info />
1060 <!-- ******************************************************* -->
1061 <!-- ************ Test project specific targets ************ -->
1062 <!-- ******************************************************* -->
1064 <!-- enable code coverage -->
1065 <target name="emma">
1066 <property name="emma.enabled" value="true" />
1069 <!-- fails if the project is not a test project -->
1070 <target name="-test-project-check">
1071 <!-- can't use project.is.test since the setup target is not run -->
1074 <isset property="tested.project.dir" />
1077 <fail message="Project is not a test project." />
1082 <!-- Installs the tested project. This make sure to install the proper package based on
1083 the value of emma.enabled -->
1084 <target name="-install-tested-project" depends="-test-project-check, -setup">
1085 <!-- figure out which tested package to install based on emma.enabled -->
1086 <condition property="tested.project.install.target" value="installi" else="installd">
1087 <isset property="emma.enabled" />
1089 <subant target="${tested.project.install.target}" failonerror="true">
1090 <fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
1094 <target name="test" depends="-test-project-check"
1095 description="Runs tests from the package defined in test.package property">
1097 <property name="tested.project.absolute.dir" location="${tested.project.dir}" />
1099 <property name="test.runner" value="android.test.InstrumentationTestRunner" />
1101 <!-- Application package of the tested project extracted from its manifest file -->
1102 <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml"
1103 expression="/manifest/@package" output="tested.manifest.package" />
1105 <property name="emma.dump.file"
1106 value="/data/data/${tested.manifest.package}/coverage.ec" />
1108 <if condition="${emma.enabled}">
1110 <echo>WARNING: Code Coverage is currently only supported on the emulator and rooted devices.</echo>
1111 <run-tests-helper emma.enabled="true">
1112 <extra-instrument-args>
1114 <arg value="coverageFile" />
1115 <arg value="${emma.dump.file}" />
1116 </extra-instrument-args>
1118 <echo>Downloading coverage file into project directory...</echo>
1119 <exec executable="${adb}" failonerror="true">
1120 <arg line="${adb.device.arg}" />
1121 <arg value="pull" />
1122 <arg value="${emma.dump.file}" />
1123 <arg value="coverage.ec" />
1125 <echo>Extracting coverage report...</echo>
1127 <report sourcepath="${tested.project.absolute.dir}/${source.dir}"
1128 verbosity="${verbosity}">
1129 <!-- TODO: report.dir or something like should be introduced if necessary -->
1131 <include name="coverage.ec" />
1132 <include name="coverage.em" />
1134 <!-- TODO: reports in other, indicated by user formats -->
1135 <html outfile="coverage.html" />
1138 <echo>Cleaning up temporary files...</echo>
1139 <delete file="coverage.ec" />
1140 <delete file="coverage.em" />
1141 <echo>Saving the report file in ${basedir}/coverage/coverage.html</echo>
1144 <run-tests-helper />
1150 <!-- ******************************************************* -->
1151 <!-- ********** Install/uninstall specific targets ********* -->
1152 <!-- ******************************************************* -->
1154 <target name="install"
1155 description="Installs the newly build package. Must be used in conjunction with a build target
1156 (debug/release/instrument). If the application was previously installed, the application
1157 is reinstalled if the signature matches." >
1158 <!-- only do install if *not* a library project -->
1159 <do-only-if-not-library elseText="Library project: nothing to install!" >
1162 <isset property="out.final.file" />
1168 <file file="${out.final.file}"/>
1172 <echo>Installing ${out.final.file} onto default emulator or device...</echo>
1173 <exec executable="${adb}" failonerror="true">
1174 <arg line="${adb.device.arg}" />
1175 <arg value="install" />
1177 <arg path="${out.final.file}" />
1181 <fail message="File {out.final.file} does not exist." />
1186 <echo>Install file not specified.</echo>
1188 <echo>'ant install' now requires the build target to be specified as well.</echo>
1191 <echo> ant debug install</echo>
1192 <echo> ant release install</echo>
1193 <echo> ant instrument install</echo>
1194 <echo>This will build the given package and install it.</echo>
1196 <echo>Alternatively, you can use</echo>
1197 <echo> ant installd</echo>
1198 <echo> ant installr</echo>
1199 <echo> ant installi</echo>
1200 <echo> ant installt</echo>
1201 <echo>to only install an existing package (this will not rebuild the package.)</echo>
1205 </do-only-if-not-library>
1208 <target name="installd" depends="-set-debug-files, install"
1209 description="Installs (only) the debug package." />
1210 <target name="installr" depends="-set-release-mode, install"
1211 description="Installs (only) the release package." />
1212 <target name="installi" depends="-set-instrumented-mode, install"
1213 description="Installs (only) the instrumented package." />
1214 <target name="installt" depends="-install-tested-project, installd"
1215 description="Installs (only) the test and tested packages." />
1218 <!-- Uninstalls the package from the default emulator/device -->
1219 <target name="uninstall"
1220 description="Uninstalls the application from a running emulator or device.">
1221 <!-- Name of the application package extracted from manifest file -->
1222 <xpath input="AndroidManifest.xml" expression="/manifest/@package"
1223 output="manifest.package" />
1227 <isset property="manifest.package" />
1230 <uninstall-helper app.package="${manifest.package}" />
1233 <echo>Could not find application package in manifest. Cannot run 'adb uninstall'.</echo>
1237 <if condition="${project.is.test}">
1239 <property name="tested.project.absolute.dir" location="${tested.project.dir}" />
1241 <!-- Application package of the tested project extracted from its manifest file -->
1242 <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml"
1243 expression="/manifest/@package" output="tested.manifest.package" />
1246 <isset property="tested.manifest.package" />
1249 <uninstall-helper app.package="${tested.manifest.package}" />
1252 <echo>Could not find tested application package in manifest. Cannot run 'adb uninstall'.</echo>
1261 <!-- ******************************************************* -->
1262 <!-- ************************* Help ************************ -->
1263 <!-- ******************************************************* -->
1265 <target name="help">
1266 <!-- displays starts at col 13
1268 <echo>Android Ant Build. Available targets:</echo>
1269 <echo> help: Displays this help.</echo>
1270 <echo> clean: Removes output files created by other targets.</echo>
1271 <echo> The 'all' target can be used to clean dependencies</echo>
1272 <echo> (tested projects and libraries)at the same time</echo>
1273 <echo> using: 'ant all clean'</echo>
1274 <echo> debug: Builds the application and signs it with a debug key.</echo>
1275 <echo> The 'nodeps' target can be used to only build the</echo>
1276 <echo> current project and ignore the libraries using:</echo>
1277 <echo> 'ant nodeps debug'</echo>
1278 <echo> release: Builds the application. The generated apk file must be</echo>
1279 <echo> signed before it is published.</echo>
1280 <echo> The 'nodeps' target can be used to only build the</echo>
1281 <echo> current project and ignore the libraries using:</echo>
1282 <echo> 'ant nodeps release'</echo>
1283 <echo> instrument:Builds an instrumented package and signs it with a</echo>
1284 <echo> debug key.</echo>
1285 <echo> test: Runs the tests. Project must be a test project and</echo>
1286 <echo> must have been built. Typical usage would be:</echo>
1287 <echo> ant [emma] debug installt test</echo>
1288 <echo> emma: Transiently enables code coverage for subsequent</echo>
1289 <echo> targets.</echo>
1290 <echo> install: Installs the newly build package. Must either be used</echo>
1291 <echo> in conjunction with a build target (debug/release/</echo>
1292 <echo> instrument) or with the proper suffix indicating</echo>
1293 <echo> which package to install (see below).</echo>
1294 <echo> If the application was previously installed, the</echo>
1295 <echo> application is reinstalled if the signature matches.</echo>
1296 <echo> installd: Installs (only) the debug package.</echo>
1297 <echo> installr: Installs (only) the release package.</echo>
1298 <echo> installi: Installs (only) the instrumented package.</echo>
1299 <echo> installt: Installs (only) the test and tested packages.</echo>
1300 <echo> uninstall: Uninstalls the application from a running emulator or</echo>
1301 <echo> device.</echo>