• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="UTF-8"?>
2<project name="android_rules" default="debug">
3
4    <!--
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.
8
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).
12
13        Follows:
14        - custom task definitions,
15        - more properties (do not override those unless the whole build system is modified).
16        - macros used throughout the build,
17        - base build targets,
18        - debug-specific build targets,
19        - release-specific build targets,
20        - instrument-specific build targets,
21        - test project-specific build targets,
22        - install targets,
23        - help target
24    -->
25
26    <!-- ******************************************************* -->
27    <!-- **************** Overridable Properties *************** -->
28    <!-- ******************************************************* -->
29
30    <!-- You can override these values in your build.xml or ant.properties.
31         Overriding any other properties may result in broken build. -->
32
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
35         the emulator. -->
36    <property name="adb.device.arg" value="" />
37
38    <!-- filename only of the output file. Cannot be a path -->
39    <property name="out.filename" value="${ant.project.name}.jar" />
40
41    <!-- compilation options -->
42    <property name="java.encoding" value="UTF-8" />
43    <property name="java.target" value="1.5" />
44    <property name="java.source" value="1.5" />
45    <property name="java.compilerargs" value="" />
46
47    <!-- Verbosity -->
48    <property name="verbose" value="false" />
49
50    <!-- ******************************************************* -->
51    <!-- ********************* Custom Tasks ******************** -->
52    <!-- ******************************************************* -->
53
54    <!-- jar file from where the tasks are loaded -->
55    <path id="android.antlibs">
56        <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
57    </path>
58
59    <!-- Custom tasks -->
60    <taskdef resource="anttasks.properties" classpathref="android.antlibs" />
61
62    <!-- Emma configuration -->
63    <property name="emma.dir" value="${sdk.dir}/tools/lib" />
64    <path id="emma.lib">
65        <pathelement location="${emma.dir}/emma.jar" />
66        <pathelement location="${emma.dir}/emma_ant.jar" />
67    </path>
68    <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
69    <!-- End of emma configuration -->
70
71
72    <!-- ******************************************************* -->
73    <!-- ******************* Other Properties ****************** -->
74    <!-- ******************************************************* -->
75    <!-- overriding these properties may break the build
76         unless the whole file is updated -->
77
78    <!-- Input directories -->
79    <property name="source.dir" value="src" />
80    <property name="source.absolute.dir" location="${source.dir}" />
81    <property name="jar.libs.dir" value="libs" />
82    <property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
83
84    <!-- Output directories -->
85    <property name="out.dir" value="bin" />
86    <property name="out.absolute.dir" location="${out.dir}" />
87    <property name="out.classes.absolute.dir" location="${out.dir}/classes" />
88
89    <property name="out.file" value="${out.absolute.dir}/${out.filename}" />
90
91    <!-- tools location -->
92    <property name="android.tools.dir" location="${sdk.dir}/tools" />
93    <property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" />
94    <condition property="exe" value=".exe" else=""><os family="windows" /></condition>
95    <condition property="bat" value=".bat" else=""><os family="windows" /></condition>
96    <property name="adb" location="${android.platform.tools.dir}/adb${exe}" />
97    <property name="dx" location="${android.platform.tools.dir}/dx${bat}" />
98
99    <!-- Intermediate files -->
100    <property name="dex.file.name" value="classes.dex" />
101    <property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" />
102    <property name="resource.package.file.name" value="${ant.project.name}.ap_" />
103
104    <!-- whether we need to fork javac.
105         This is only needed on Windows when running Java < 7 -->
106    <condition else="false" property="need.javac.fork">
107        <and>
108            <matches pattern="1\.[56]" string="${java.specification.version}"/>
109            <not>
110                <os family="unix"/>
111            </not>
112        </and>
113    </condition>
114
115    <macrodef name="run-tests-helper">
116        <attribute name="emma.enabled" default="false" />
117        <element name="extra-instrument-args" optional="yes" />
118        <sequential>
119            <echo level="info">Running tests ...</echo>
120            <exec executable="${adb}" failonerror="true">
121                <arg line="${adb.device.arg}" />
122                <arg value="shell" />
123                <arg value="am" />
124                <arg value="instrument" />
125                <arg value="-w" />
126                <arg value="-e" />
127                <arg value="coverage" />
128                <arg value="@{emma.enabled}" />
129                <extra-instrument-args />
130                <arg value="${project.app.package}/${test.runner}" />
131            </exec>
132        </sequential>
133    </macrodef>
134
135    <!-- ******************************************************* -->
136    <!-- ******************** Build Targets ******************** -->
137    <!-- ******************************************************* -->
138
139    <!-- Basic Ant + SDK check -->
140    <target name="-check-env">
141        <checkenv />
142    </target>
143
144    <!-- empty default pre-clean target. Create a similar target in
145         your build.xml and it'll be called instead of this one. -->
146    <target name="-pre-clean"/>
147
148    <!-- clean target -->
149    <target name="clean" depends="-check-env, -pre-clean"
150            description="Removes output files created by other targets.">
151        <delete dir="${out.absolute.dir}" verbose="${verbose}" />
152    </target>
153
154    <!-- Pre build setup -->
155    <target name="-build-setup" depends="-check-env">
156
157        <echo level="info">Resolving Build Target for ${ant.project.name}...</echo>
158        <!-- load project properties, resolve Android target, library dependencies
159             and set some properties with the results.
160             All property names are passed as parameters ending in -Out -->
161        <getuitarget compileClassPathOut="project.target.class.path" />
162
163        <echo level="info">----------</echo>
164        <echo level="info">Creating output directories if needed...</echo>
165        <mkdir dir="${out.absolute.dir}" />
166        <mkdir dir="${out.classes.absolute.dir}" />
167
168    </target>
169
170    <!-- empty default pre-compile target. Create a similar target in
171         your build.xml and it'll be called instead of this one. -->
172    <target name="-pre-compile"/>
173
174    <!-- Compiles this project's .java files into .class files. -->
175    <target name="compile" depends="-build-setup, -pre-compile">
176        <javac encoding="${java.encoding}"
177                source="${java.source}" target="${java.target}"
178                debug="true" extdirs="" includeantruntime="false"
179                destdir="${out.classes.absolute.dir}"
180                bootclasspathref="project.target.class.path"
181                verbose="${verbose}"
182                fork="${need.javac.fork}">
183            <src path="${source.absolute.dir}" />
184            <compilerarg line="${java.compilerargs}" />
185        </javac>
186    </target>
187
188    <!-- empty default post-compile target. Create a similar target in
189         your build.xml and it'll be called instead of this one. -->
190    <target name="-post-compile"/>
191
192    <!-- Converts this project's .class files into .dex files -->
193    <target name="-dex" depends="compile, -post-compile">
194        <dex executable="${dx}"
195                output="${intermediate.dex.file}"
196                nolocals="@{nolocals}"
197                verbose="${verbose}">
198            <path path="${out.classes.absolute.dir}"/>
199        </dex>
200    </target>
201
202    <!-- empty default post-dex target. Create a similar target in
203         your build.xml and it'll be called instead of this one. -->
204    <target name="-post-dex"/>
205
206    <target name="-jar" depends="-dex, -post-dex" >
207        <jar destfile="${out.file}">
208            <fileset file="${intermediate.dex.file}" />
209        </jar>
210    </target>
211
212    <!-- empty default post-jar target. Create a similar target in
213         your build.xml and it'll be called instead of this one. -->
214    <target name="-post-jar"/>
215
216    <target name="build" depends="-jar, -post-jar" />
217
218    <target name="install" description="Install the test package">
219         <exec executable="${adb}" failonerror="true">
220            <arg line="${adb.device.arg}" />
221            <arg value="push" />
222            <arg value="${out.file}" />
223            <arg value="/data/local/tmp" />
224        </exec>
225    </target>
226
227    <target name="test" description="Runs tests">
228        <!-- todo: fix this -->
229        <fail message="Launching tests from Ant not supported yet" />
230
231         <exec executable="${adb}" failonerror="true">
232            <arg line="${adb.device.arg}" />
233            <arg value="shell" />
234            <arg value="uiautomator" />
235            <arg value="runtest" />
236            <arg value="${out.filename}" />
237            <arg value="-e" />
238            <arg value="class" />
239            <arg value="com.android.uiautomator.samples.skeleton.DemoTestCase" />
240        </exec>
241    </target>
242
243    <target name="help">
244        <!-- displays starts at col 13
245              |13                                                              80| -->
246        <echo>Android Ant Build. Available targets:</echo>
247        <echo>   help:      Displays this help.</echo>
248        <echo>   clean:     Removes output files created by other targets.</echo>
249        <echo>   build:     Builds the test library.</echo>
250        <echo>   install:   Installs the library on a connected device or</echo>
251        <echo>              emulator.</echo>
252        <echo>   test:      Runs the tests.</echo>
253        <echo></echo>
254        <echo>It is possible to mix targets. For instance:</echo>
255        <echo>   ant build install test</echo>
256        <echo>This will build, install and run the test in a single command.</echo>
257    </target>
258
259</project>
260