1<?xml version="1.0" encoding="UTF-8"?> 2<project name="android_rules" default="debug"> 3 4 <!-- 5 This rules file is meant to be imported by the custom Ant task: 6 com.android.ant.SetupTask 7 8 The following properties are put in place by the importing task: 9 android.jar, android.aidl, aapt, aidl, and dx 10 11 Additionnaly, the task sets up the following classpath reference: 12 android.target.classpath 13 This is used by the compiler task as the boot classpath. 14 --> 15 16 <!-- Custom tasks --> 17 <taskdef name="aapt" 18 classname="com.android.ant.AaptExecLoopTask" 19 classpathref="android.antlibs" /> 20 21 <taskdef name="aidl" 22 classname="com.android.ant.AidlExecTask" 23 classpathref="android.antlibs" /> 24 25 <taskdef name="xpath" 26 classname="com.android.ant.XPathTask" 27 classpathref="android.antlibs" /> 28 29 <taskdef name="if" 30 classname="com.android.ant.IfElseTask" 31 classpathref="android.antlibs" /> 32 33 <!-- Properties --> 34 35 <!-- Tells adb which device to target. You can change this from the command line 36 by invoking "ant -Dadb.device.arg=-d" for device "ant -Dadb.device.arg=-e" for 37 the emulator. --> 38 <property name="adb.device.arg" value="" /> 39 40 <property name="android.tools.dir" location="${sdk.dir}/tools" /> 41 <!-- Name of the application package extracted from manifest file --> 42 <xpath input="AndroidManifest.xml" expression="/manifest/@package" 43 output="manifest.package" /> 44 <xpath input="AndroidManifest.xml" expression="/manifest/application/@android:hasCode" 45 output="manifest.hasCode" default="true"/> 46 47 <!-- Input directories --> 48 <property name="source.dir" value="src" /> 49 <property name="source.absolute.dir" location="${source.dir}" /> 50 <property name="gen.dir" value="gen" /> 51 <property name="gen.absolute.dir" location="${gen.dir}" /> 52 <property name="resource.dir" value="res" /> 53 <property name="resource.absolute.dir" location="${resource.dir}" /> 54 <property name="asset.dir" value="assets" /> 55 <property name="asset.absolute.dir" location="${asset.dir}" /> 56 57 <!-- Directory for the third party java libraries --> 58 <property name="external.libs.dir" value="libs" /> 59 <property name="external.libs.absolute.dir" location="${external.libs.dir}" /> 60 <!-- Directory for the native libraries --> 61 <property name="native.libs.dir" value="libs" /> 62 <property name="native.libs.absolute.dir" location="${native.libs.dir}" /> 63 64 <!-- Output directories --> 65 <property name="out.dir" value="bin" /> 66 <property name="out.absolute.dir" location="${out.dir}" /> 67 <property name="out.classes.dir" value="${out.absolute.dir}/classes" /> 68 <property name="out.classes.absolute.dir" location="${out.classes.dir}" /> 69 70 <!-- Verbosity --> 71 <property name="verbose" value="false" /> 72 <!-- This is needed by emma as it uses multilevel verbosity instead of simple 'true' or 'false' 73 The property 'verbosity' is not user configurable and depends exclusively on 'verbose' 74 value.--> 75 <condition property="verbosity" value="verbose" else="quiet"> 76 <istrue value="${verbose}" /> 77 </condition> 78 79 <!-- Tools --> 80 <condition property="exe" value=".exe" else=""><os family="windows" /></condition> 81 82 <!-- Emma configuration --> 83 <property name="emma.dir" value="${sdk.dir}/tools/lib" /> 84 <path id="emma.lib"> 85 <pathelement location="${emma.dir}/emma.jar" /> 86 <pathelement location="${emma.dir}/emma_ant.jar" /> 87 </path> 88 <taskdef resource="emma_ant.properties" classpathref="emma.lib" /> 89 <!-- End of emma configuration --> 90 91 <!-- Rules --> 92 93 <!-- Creates the output directories if they don't exist yet. --> 94 <target name="-dirs"> 95 <echo>Creating output directories if needed...</echo> 96 <mkdir dir="${resource.absolute.dir}" /> 97 <mkdir dir="${external.libs.absolute.dir}" /> 98 <mkdir dir="${gen.absolute.dir}" /> 99 <mkdir dir="${out.absolute.dir}" /> 100 <mkdir dir="${out.classes.absolute.dir}" /> 101 </target> 102 103 <!-- empty default pre-build target. Create a similar target in 104 your build.xml and it'll be called instead of this one. --> 105 <target name="-pre-build"/> 106 107 <!-- Generates the R.java file for this project's resources. --> 108 <target name="-resource-src" depends="-dirs, -pre-build"> 109 <echo>Generating R.java / Manifest.java from the resources...</echo> 110 <aapt executable="${aapt}" 111 command="package" 112 verbose="${verbose}" 113 manifest="AndroidManifest.xml" 114 androidjar="${android.jar}" 115 rfolder="${gen.absolute.dir}"> 116 <res path="${resource.absolute.dir}" /> 117 </aapt> 118 </target> 119 120 <!-- Generates java classes from .aidl files. --> 121 <target name="-aidl" depends="-dirs"> 122 <if condition="${manifest.hasCode}"> 123 <then> 124 <echo>Compiling aidl files into Java classes...</echo> 125 <aidl executable="${aidl}" framework="${android.aidl}" 126 genFolder="${gen.absolute.dir}"> 127 <source path="${source.absolute.dir}"/> 128 <source refid="android.libraries.src"/> 129 </aidl> 130 </then> 131 <else> 132 <echo>hasCode = false. Skipping...</echo> 133 </else> 134 </if> 135 </target> 136 137 <!-- empty default pre-compile target. Create a similar target in 138 your build.xml and it'll be called instead of this one. --> 139 <target name="-pre-compile"/> 140 141 <!-- Compiles this project's .java files into .class files. --> 142 <target name="compile" depends="-resource-src, -aidl, -pre-compile" 143 description="Compiles project's .java files into .class files"> 144 <!-- If android rules are used for a test project, its classpath should include 145 tested project's location --> 146 <condition property="extensible.classpath" 147 value="${tested.project.absolute.dir}/bin/classes" else="."> 148 <isset property="tested.project.absolute.dir" /> 149 </condition> 150 <condition property="extensible.libs.classpath" 151 value="${tested.project.absolute.dir}/libs" 152 else="./libs"> 153 <isset property="tested.project.absolute.dir" /> 154 </condition> 155 <javac encoding="ascii" target="1.5" debug="true" extdirs="" 156 destdir="${out.classes.absolute.dir}" 157 bootclasspathref="android.target.classpath" 158 verbose="${verbose}" 159 classpath="${extensible.classpath}" 160 classpathref="android.libraries.jars"> 161 <src path="${source.absolute.dir}" /> 162 <src path="${gen.absolute.dir}" /> 163 <src refid="android.libraries.src" /> 164 <classpath> 165 <fileset dir="${external.libs.absolute.dir}" includes="*.jar" /> 166 <fileset dir="${extensible.libs.classpath}" includes="*.jar" /> 167 </classpath> 168 </javac> 169 </target> 170 171 <target name="clean" description="Removes output files created by other targets."> 172 <delete dir="${out.absolute.dir}" verbose="${verbose}" /> 173 <delete dir="${gen.absolute.dir}" verbose="${verbose}" /> 174 </target> 175 176 <target name="help"> 177 <!-- displays starts at col 13 178 |13 80| --> 179 <echo>Android Ant Build. Available targets:</echo> 180 <echo> help: Displays this help.</echo> 181 <echo> clean: Removes output files created by other targets.</echo> 182 <echo> compile: Compiles project's .java files into .class files.</echo> 183 </target> 184</project> 185