2 <project name="BarcodeScanner" default="debug">
4 <property file="../build.properties"/>
5 <property name="sdk-folder" value="${android-home}"/>
6 <property name="android-tools" value="${sdk-folder}/tools"/>
8 <!-- Application Package Name -->
9 <property name="application-package" value="com.android.barcodes" />
11 <!-- The intermediates directory -->
12 <!-- Eclipse uses "bin" for its own output, so we do the same. -->
13 <property name="outdir" value="bin" />
15 <!-- ************************************************************************************* -->
16 <!-- No user servicable parts below. -->
18 <property name="android-framework" value="${android-tools}/lib/framework.aidl" />
20 <!-- Input directories -->
21 <property name="resource-dir" value="res" />
22 <property name="asset-dir" value="assets" />
23 <property name="srcdir" value="src" />
24 <condition property="srcdir-ospath"
25 value="${basedir}\${srcdir}"
26 else="${basedir}/${srcdir}" >
27 <os family="windows"/>
30 <property name="external-libs" value="../core" />
31 <condition property="external-libs-ospath"
32 value="${basedir}\${external-libs}"
33 else="${basedir}/${external-libs}" >
34 <os family="windows"/>
37 <!-- Output directories -->
38 <property name="outdir-classes" value="${outdir}/classes" />
39 <condition property="outdir-classes-ospath"
40 value="${basedir}\${outdir-classes}"
41 else="${basedir}/${outdir-classes}" >
42 <os family="windows"/>
45 <!-- Create R.java in the source directory -->
46 <property name="outdir-r" value="src" />
48 <!-- Intermediate files -->
49 <property name="dex-file" value="classes.dex" />
50 <property name="intermediate-dex" value="${outdir}/${dex-file}" />
51 <condition property="intermediate-dex-ospath"
52 value="${basedir}\${intermediate-dex}"
53 else="${basedir}/${intermediate-dex}" >
54 <os family="windows"/>
57 <!-- The final package file to generate -->
58 <property name="resources-package" value="${outdir}/${ant.project.name}.ap_" />
59 <condition property="resources-package-ospath"
60 value="${basedir}\${resources-package}"
61 else="${basedir}/${resources-package}" >
62 <os family="windows"/>
65 <property name="out-debug-package" value="${outdir}/${ant.project.name}-debug.apk" />
66 <condition property="out-debug-package-ospath"
67 value="${basedir}\${out-debug-package}"
68 else="${basedir}/${out-debug-package}" >
69 <os family="windows"/>
72 <property name="out-unsigned-package" value="${outdir}/${ant.project.name}-unsigned.apk" />
73 <condition property="out-unsigned-package-ospath"
74 value="${basedir}\${out-unsigned-package}"
75 else="${basedir}/${out-unsigned-package}" >
76 <os family="windows"/>
80 <condition property="aapt" value="${android-tools}/aapt.exe" else="${android-tools}/aapt" >
81 <os family="windows"/>
83 <condition property="aidl" value="${android-tools}/aidl.exe" else="${android-tools}/aidl" >
84 <os family="windows"/>
86 <condition property="adb" value="${android-tools}/adb.exe" else="${android-tools}/adb" >
87 <os family="windows"/>
89 <condition property="dx" value="${android-tools}/dx.bat" else="${android-tools}/dx" >
90 <os family="windows"/>
92 <condition property="apk-builder" value="${android-tools}/apkbuilder.bat" else="${android-tools}/apkbuilder" >
93 <os family="windows"/>
96 <property name="android-jar" value="${sdk-folder}/android.jar" />
100 <!-- Create the output directories if they don't exist yet. -->
102 <echo>Creating output directories if needed...</echo>
103 <mkdir dir="${outdir}" />
104 <mkdir dir="${outdir-classes}" />
107 <!-- Generate the R.java file for this project's resources. -->
108 <target name="resource-src" depends="dirs">
109 <echo>Generating R.java / Manifest.java from the resources...</echo>
110 <exec executable="${aapt}" failonerror="true">
111 <arg value="package" />
114 <arg value="${outdir-r}" />
116 <arg value="AndroidManifest.xml" />
118 <arg value="${resource-dir}" />
120 <arg value="${android-jar}" />
124 <!-- Generate java classes from .aidl files. -->
125 <target name="aidl" depends="dirs">
126 <echo>Compiling aidl files into Java classes...</echo>
127 <apply executable="${aidl}" failonerror="true">
128 <arg value="-p${android-framework}" />
129 <arg value="-I${srcdir}" />
130 <fileset dir="${srcdir}">
131 <include name="**/*.aidl"/>
136 <!-- Compile this project's .java files into .class files. -->
137 <target name="compile" depends="dirs, resource-src, aidl">
138 <javac encoding="ascii" target="1.5" debug="true" extdirs=""
140 destdir="${outdir-classes}"
141 bootclasspath="${android-jar}">
143 <fileset dir="${external-libs}" includes="*.jar"/>
148 <!-- Convert this project's .class files into .dex files. -->
149 <target name="dex" depends="compile">
150 <echo>Converting compiled files and external libraries into ${outdir}/${dex-file}...</echo>
151 <apply executable="${dx}" failonerror="true" parallel="true">
152 <arg value="--dex" />
153 <arg value="--output=${intermediate-dex-ospath}" />
154 <arg path="${outdir-classes-ospath}" />
155 <fileset dir="${external-libs}" includes="*.jar"/>
159 <!-- Put the project's resources into the output package file. -->
160 <target name="package-res-and-assets">
161 <echo>Packaging resources and assets...</echo>
162 <exec executable="${aapt}" failonerror="true">
163 <arg value="package" />
166 <arg value="AndroidManifest.xml" />
168 <arg value="${resource-dir}" />
170 <arg value="${asset-dir}" />
172 <arg value="${android-jar}" />
174 <arg value="${resources-package}" />
178 <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
179 <target name="package-res-no-assets">
180 <echo>Packaging resources...</echo>
181 <exec executable="${aapt}" failonerror="true">
182 <arg value="package" />
185 <arg value="AndroidManifest.xml" />
187 <arg value="${resource-dir}" />
188 <!-- No assets directory -->
190 <arg value="${android-jar}" />
192 <arg value="${resources-package}" />
196 <!-- Invoke the proper target depending on whether or not
197 an assets directory is present. -->
198 <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
199 only when the assets dir exists. -->
200 <target name="package-res">
201 <available file="${asset-dir}" type="dir"
202 property="res-target" value="and-assets" />
203 <property name="res-target" value="no-assets" />
204 <antcall target="package-res-${res-target}" />
207 <!-- Package the application and sign it with a debug key.
208 This is the default target when building. It is used for debug. -->
209 <target name="debug" depends="dex, package-res">
210 <echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo>
211 <exec executable="${apk-builder}" failonerror="true">
212 <arg value="${out-debug-package-ospath}" />
214 <arg value="${resources-package-ospath}" />
216 <arg value="${intermediate-dex-ospath}" />
218 <arg value="${srcdir-ospath}" />
220 <arg value="${external-libs-ospath}" />
224 <!-- Package the application without signing it.
225 This allows for the application to be signed later with an official publishing key. -->
226 <target name="release" depends="dex, package-res">
227 <echo>Packaging ${out-unsigned-package} for release...</echo>
228 <exec executable="${apk-builder}" failonerror="true">
229 <arg value="${out-unsigned-package-ospath}" />
232 <arg value="${resources-package-ospath}" />
234 <arg value="${intermediate-dex-ospath}" />
236 <arg value="${srcdir-ospath}" />
238 <arg value="${external-libs-ospath}" />
240 <echo>It will need to be signed with jarsigner before being published.</echo>
243 <!-- Install the package on the default emulator -->
244 <target name="install" depends="debug">
245 <echo>Installing ${out-debug-package} onto default emulator...</echo>
246 <exec executable="${adb}" failonerror="true">
247 <arg value="install" />
248 <arg value="${out-debug-package}" />
252 <target name="reinstall" depends="debug">
253 <echo>Installing ${out-debug-package} onto default emulator...</echo>
254 <exec executable="${adb}" failonerror="true">
255 <arg value="install" />
257 <arg value="${out-debug-package}" />
261 <!-- Uinstall the package from the default emulator -->
262 <target name="uninstall">
263 <echo>Uninstalling ${application-package} from the default emulator...</echo>
264 <exec executable="${adb}" failonerror="true">
265 <arg value="uninstall" />
266 <arg value="${application-package}" />
270 <target name="clean">
271 <delete dir="${outdir}"/>