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/ant-tasks.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 98 <!-- Intermediate files --> 99 <property name="dex.file.name" value="classes.dex" /> 100 <property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" /> 101 <property name="resource.package.file.name" value="${ant.project.name}.ap_" /> 102 103 <!-- whether we need to fork javac. 104 This is only needed on Windows when running Java < 7 --> 105 <condition else="false" property="need.javac.fork"> 106 <and> 107 <matches pattern="1\.[56]" string="${java.specification.version}"/> 108 <not> 109 <os family="unix"/> 110 </not> 111 </and> 112 </condition> 113 114 <macrodef name="run-tests-helper"> 115 <attribute name="emma.enabled" default="false" /> 116 <element name="extra-instrument-args" optional="yes" /> 117 <sequential> 118 <echo level="info">Running tests ...</echo> 119 <exec executable="${adb}" failonerror="true"> 120 <arg line="${adb.device.arg}" /> 121 <arg value="shell" /> 122 <arg value="am" /> 123 <arg value="instrument" /> 124 <arg value="-w" /> 125 <arg value="-e" /> 126 <arg value="coverage" /> 127 <arg value="@{emma.enabled}" /> 128 <extra-instrument-args /> 129 <arg value="${project.app.package}/${test.runner}" /> 130 </exec> 131 </sequential> 132 </macrodef> 133 134 <!-- ******************************************************* --> 135 <!-- ******************** Build Targets ******************** --> 136 <!-- ******************************************************* --> 137 138 <!-- Basic Ant + SDK check --> 139 <target name="-check-env"> 140 <checkenv /> 141 </target> 142 143 <!-- empty default pre-clean target. Create a similar target in 144 your build.xml and it'll be called instead of this one. --> 145 <target name="-pre-clean"/> 146 147 <!-- clean target --> 148 <target name="clean" depends="-check-env, -pre-clean" 149 description="Removes output files created by other targets."> 150 <delete dir="${out.absolute.dir}" verbose="${verbose}" /> 151 </target> 152 153 <!-- Pre build setup --> 154 <target name="-build-setup" depends="-check-env"> 155 <getbuildtools name="android.build.tools.dir" /> 156 <property name="dx" location="${android.build.tools.dir}/dx${bat}" /> 157 158 <echo level="info">Resolving Build Target for ${ant.project.name}...</echo> 159 <!-- load project properties, resolve Android target, library dependencies 160 and set some properties with the results. 161 All property names are passed as parameters ending in -Out --> 162 <getuitarget compileClassPathOut="project.target.class.path" /> 163 164 <echo level="info">----------</echo> 165 <echo level="info">Creating output directories if needed...</echo> 166 <mkdir dir="${out.absolute.dir}" /> 167 <mkdir dir="${out.classes.absolute.dir}" /> 168 169 </target> 170 171 <!-- empty default pre-compile target. Create a similar target in 172 your build.xml and it'll be called instead of this one. --> 173 <target name="-pre-compile"/> 174 175 <!-- Compiles this project's .java files into .class files. --> 176 <target name="compile" depends="-build-setup, -pre-compile"> 177 <javac encoding="${java.encoding}" 178 source="${java.source}" target="${java.target}" 179 debug="true" extdirs="" includeantruntime="false" 180 destdir="${out.classes.absolute.dir}" 181 bootclasspathref="project.target.class.path" 182 verbose="${verbose}" 183 fork="${need.javac.fork}"> 184 <src path="${source.absolute.dir}" /> 185 <compilerarg line="${java.compilerargs}" /> 186 </javac> 187 </target> 188 189 <!-- empty default post-compile target. Create a similar target in 190 your build.xml and it'll be called instead of this one. --> 191 <target name="-post-compile"/> 192 193 <!-- Converts this project's .class files into .dex files --> 194 <target name="-dex" depends="compile, -post-compile"> 195 <dex executable="${dx}" 196 output="${intermediate.dex.file}" 197 nolocals="@{nolocals}" 198 verbose="${verbose}"> 199 <path path="${out.classes.absolute.dir}"/> 200 </dex> 201 </target> 202 203 <!-- empty default post-dex target. Create a similar target in 204 your build.xml and it'll be called instead of this one. --> 205 <target name="-post-dex"/> 206 207 <target name="-jar" depends="-dex, -post-dex" > 208 <jar destfile="${out.file}"> 209 <fileset file="${intermediate.dex.file}" /> 210 </jar> 211 </target> 212 213 <!-- empty default post-jar target. Create a similar target in 214 your build.xml and it'll be called instead of this one. --> 215 <target name="-post-jar"/> 216 217 <target name="build" depends="-jar, -post-jar" /> 218 219 <target name="install" description="Install the test package"> 220 <exec executable="${adb}" failonerror="true"> 221 <arg line="${adb.device.arg}" /> 222 <arg value="push" /> 223 <arg value="${out.file}" /> 224 <arg value="/data/local/tmp" /> 225 </exec> 226 </target> 227 228 <target name="test" description="Runs tests"> 229 <!-- todo: fix this --> 230 <fail message="Launching tests from Ant not supported yet" /> 231 232 <exec executable="${adb}" failonerror="true"> 233 <arg line="${adb.device.arg}" /> 234 <arg value="shell" /> 235 <arg value="uiautomator" /> 236 <arg value="runtest" /> 237 <arg value="${out.filename}" /> 238 <arg value="-e" /> 239 <arg value="class" /> 240 <arg value="com.android.uiautomator.samples.skeleton.DemoTestCase" /> 241 </exec> 242 </target> 243 244 <target name="help"> 245 <!-- displays starts at col 13 246 |13 80| --> 247 <echo>Android Ant Build. Available targets:</echo> 248 <echo> help: Displays this help.</echo> 249 <echo> clean: Removes output files created by other targets.</echo> 250 <echo> build: Builds the test library.</echo> 251 <echo> install: Installs the library on a connected device or</echo> 252 <echo> emulator.</echo> 253 <echo> test: Runs the tests.</echo> 254 <echo></echo> 255 <echo>It is possible to mix targets. For instance:</echo> 256 <echo> ant build install test</echo> 257 <echo>This will build, install and run the test in a single command.</echo> 258 </target> 259 260</project> 261