Resurrected 128-pixel icon for About page
[zxing.git] / android / build.xml
1 <?xml version="1.0" ?>
2 <project name="BarcodeScanner" default="debug">
3   <!-- SDK Locations -->
4   <property file="../build.properties"/>
5   <property name="sdk-folder" value="${android-home}"/>
6   <property name="android-tools" value="${sdk-folder}/tools"/>
7
8   <!-- Application Package Name -->
9   <property name="application-package" value="com.android.barcodes" />
10
11   <!-- The intermediates directory -->
12   <!-- Eclipse uses "bin" for its own output, so we do the same. -->
13   <property name="outdir" value="bin" />
14
15   <!-- ************************************************************************************* -->
16   <!-- No user servicable parts below. -->
17
18   <property name="android-framework" value="${android-tools}/lib/framework.aidl" />
19
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"/>
28   </condition>
29
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"/>
35   </condition>
36
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"/>
43   </condition>
44
45   <!-- Create R.java in the source directory -->
46   <property name="outdir-r" value="src" />
47
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"/>
55   </condition>
56
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"/>
63   </condition>
64
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"/>
70   </condition>
71
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"/>
77   </condition>
78
79   <!-- Tools -->
80   <condition property="aapt" value="${android-tools}/aapt.exe" else="${android-tools}/aapt" >
81     <os family="windows"/>
82   </condition>
83   <condition property="aidl" value="${android-tools}/aidl.exe" else="${android-tools}/aidl" >
84     <os family="windows"/>
85   </condition>
86   <condition property="adb" value="${android-tools}/adb.exe" else="${android-tools}/adb" >
87     <os family="windows"/>
88   </condition>
89   <condition property="dx" value="${android-tools}/dx.bat" else="${android-tools}/dx" >
90     <os family="windows"/>
91   </condition>
92   <condition property="apk-builder" value="${android-tools}/apkbuilder.bat" else="${android-tools}/apkbuilder" >
93     <os family="windows"/>
94   </condition>
95
96   <property name="android-jar" value="${sdk-folder}/android.jar" />
97
98   <!-- Rules -->
99
100   <!-- Create the output directories if they don't exist yet. -->
101   <target name="dirs">
102     <echo>Creating output directories if needed...</echo>
103     <mkdir dir="${outdir}" />
104     <mkdir dir="${outdir-classes}" />
105   </target>
106
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" />
112       <arg value="-m" />
113       <arg value="-J" />
114       <arg value="${outdir-r}" />
115       <arg value="-M" />
116       <arg value="AndroidManifest.xml" />
117       <arg value="-S" />
118       <arg value="${resource-dir}" />
119       <arg value="-I" />
120       <arg value="${android-jar}" />
121     </exec>
122   </target>
123
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"/>
132       </fileset>
133     </apply>
134   </target>
135
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=""
139            srcdir="."
140            destdir="${outdir-classes}"
141            bootclasspath="${android-jar}">
142       <classpath>
143         <fileset dir="${external-libs}" includes="*.jar"/>
144       </classpath>
145     </javac>
146   </target>
147
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"/>
156     </apply>
157   </target>
158
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" />
164       <arg value="-f" />
165       <arg value="-M" />
166       <arg value="AndroidManifest.xml" />
167       <arg value="-S" />
168       <arg value="${resource-dir}" />
169       <arg value="-A" />
170       <arg value="${asset-dir}" />
171       <arg value="-I" />
172       <arg value="${android-jar}" />
173       <arg value="-F" />
174       <arg value="${resources-package}" />
175     </exec>
176   </target>
177
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" />
183       <arg value="-f" />
184       <arg value="-M" />
185       <arg value="AndroidManifest.xml" />
186       <arg value="-S" />
187       <arg value="${resource-dir}" />
188       <!-- No assets directory -->
189       <arg value="-I" />
190       <arg value="${android-jar}" />
191       <arg value="-F" />
192       <arg value="${resources-package}" />
193     </exec>
194   </target>
195
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}" />
205   </target>
206
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}" />
213       <arg value="-z" />
214       <arg value="${resources-package-ospath}" />
215       <arg value="-f" />
216       <arg value="${intermediate-dex-ospath}" />
217       <arg value="-rf" />
218       <arg value="${srcdir-ospath}" />
219       <arg value="-rj" />
220       <arg value="${external-libs-ospath}" />
221     </exec>
222   </target>
223
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}" />
230       <arg value="-u" />
231       <arg value="-z" />
232       <arg value="${resources-package-ospath}" />
233       <arg value="-f" />
234       <arg value="${intermediate-dex-ospath}" />
235       <arg value="-rf" />
236       <arg value="${srcdir-ospath}" />
237       <arg value="-rj" />
238       <arg value="${external-libs-ospath}" />
239     </exec>
240     <echo>It will need to be signed with jarsigner before being published.</echo>
241   </target>
242
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}" />
249     </exec>
250   </target>
251
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" />
256       <arg value="-r" />
257       <arg value="${out-debug-package}" />
258     </exec>
259   </target>
260
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}" />
267     </exec>
268   </target>
269
270   <target name="clean">
271     <delete dir="${outdir}"/>
272   </target>
273
274 </project>