797df7981f15711a46855c17b29d5e035735b26e
[zxing.git] / android / build.xml
1 <?xml version="1.0" ?>
2 <!--
3 Copyright (C) 2008 ZXing authors
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9      http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 -->
17 <project name="BarcodeScanner" default="debug">
18   <!-- SDK Locations -->
19   <property file="../build.properties"/>
20   <property name="sdk-folder" value="${android-home}"/>
21   <property name="android-tools" value="${sdk-folder}/tools"/>
22
23   <!-- Application Package Name -->
24   <property name="application-package" value="com.google.zxing.client.android" />
25
26   <!-- The intermediates directory -->
27   <!-- Eclipse uses "bin" for its own output, so we do the same. -->
28   <property name="outdir" value="bin" />
29
30   <!-- ************************************************************************************* -->
31   <!-- No user servicable parts below. -->
32
33   <property name="android-framework" value="${android-tools}/lib/framework.aidl" />
34
35   <!-- Input directories -->
36   <property name="resource-dir" value="res" />
37   <property name="asset-dir" value="assets" />
38   <property name="srcdir" value="src" />
39   <condition property="srcdir-ospath"
40              value="${basedir}\${srcdir}"
41              else="${basedir}/${srcdir}" >
42     <os family="windows"/>
43   </condition>
44
45   <property name="external-libs" value="../core" />
46   <condition property="external-libs-ospath"
47              value="${basedir}\${external-libs}"
48              else="${basedir}/${external-libs}" >
49     <os family="windows"/>
50   </condition>
51
52   <!-- Output directories -->
53   <property name="outdir-classes" value="${outdir}/classes" />
54   <condition property="outdir-classes-ospath"
55              value="${basedir}\${outdir-classes}"
56              else="${basedir}/${outdir-classes}" >
57     <os family="windows"/>
58   </condition>
59
60   <!-- Create R.java in the source directory -->
61   <property name="outdir-r" value="src" />
62
63   <!-- Intermediate files -->
64   <property name="dex-file" value="classes.dex" />
65   <property name="intermediate-dex" value="${outdir}/${dex-file}" />
66   <condition property="intermediate-dex-ospath"
67              value="${basedir}\${intermediate-dex}"
68              else="${basedir}/${intermediate-dex}" >
69     <os family="windows"/>
70   </condition>
71
72   <!-- The final package file to generate -->
73   <property name="resources-package" value="${outdir}/${ant.project.name}.ap_" />
74   <condition property="resources-package-ospath"
75              value="${basedir}\${resources-package}"
76              else="${basedir}/${resources-package}" >
77     <os family="windows"/>
78   </condition>
79
80   <property name="out-debug-package" value="${outdir}/${ant.project.name}-debug.apk" />
81   <condition property="out-debug-package-ospath"
82              value="${basedir}\${out-debug-package}"
83              else="${basedir}/${out-debug-package}" >
84     <os family="windows"/>
85   </condition>
86
87   <property name="out-unsigned-package" value="${outdir}/${ant.project.name}-unsigned.apk" />
88   <condition property="out-unsigned-package-ospath"
89              value="${basedir}\${out-unsigned-package}"
90              else="${basedir}/${out-unsigned-package}" >
91     <os family="windows"/>
92   </condition>
93
94   <!-- Tools -->
95   <condition property="aapt" value="${android-tools}/aapt.exe" else="${android-tools}/aapt" >
96     <os family="windows"/>
97   </condition>
98   <condition property="aidl" value="${android-tools}/aidl.exe" else="${android-tools}/aidl" >
99     <os family="windows"/>
100   </condition>
101   <condition property="adb" value="${android-tools}/adb.exe" else="${android-tools}/adb" >
102     <os family="windows"/>
103   </condition>
104   <condition property="dx" value="${android-tools}/dx.bat" else="${android-tools}/dx" >
105     <os family="windows"/>
106   </condition>
107   <condition property="apk-builder" value="${android-tools}/apkbuilder.bat" else="${android-tools}/apkbuilder" >
108     <os family="windows"/>
109   </condition>
110
111   <property name="android-jar" value="${sdk-folder}/android.jar" />
112
113   <!-- Rules -->
114
115   <!-- Create the output directories if they don't exist yet. -->
116   <target name="dirs">
117     <echo>Creating output directories if needed...</echo>
118     <mkdir dir="${outdir}" />
119     <mkdir dir="${outdir-classes}" />
120   </target>
121
122   <!-- Generate the R.java file for this project's resources. -->
123   <target name="resource-src" depends="dirs">
124     <echo>Generating R.java / Manifest.java from the resources...</echo>
125     <exec executable="${aapt}" failonerror="true">
126       <arg value="package" />
127       <arg value="-m" />
128       <arg value="-J" />
129       <arg value="${outdir-r}" />
130       <arg value="-M" />
131       <arg value="AndroidManifest.xml" />
132       <arg value="-S" />
133       <arg value="${resource-dir}" />
134       <arg value="-I" />
135       <arg value="${android-jar}" />
136     </exec>
137   </target>
138
139   <!-- Generate java classes from .aidl files. -->
140   <target name="aidl" depends="dirs">
141     <echo>Compiling aidl files into Java classes...</echo>
142     <apply executable="${aidl}" failonerror="true">
143       <arg value="-p${android-framework}" />
144       <arg value="-I${srcdir}" />
145       <fileset dir="${srcdir}">
146         <include name="**/*.aidl"/>
147       </fileset>
148     </apply>
149   </target>
150
151   <!-- Compile this project's .java files into .class files. -->
152   <target name="compile" depends="dirs, resource-src, aidl">
153     <javac encoding="ascii" target="1.5" debug="true" extdirs=""
154            srcdir="."
155            destdir="${outdir-classes}"
156            bootclasspath="${android-jar}">
157       <classpath>
158         <fileset dir="${external-libs}" includes="*.jar"/>
159       </classpath>
160     </javac>
161   </target>
162
163   <!-- Convert this project's .class files into .dex files. -->
164   <target name="dex" depends="compile">
165     <echo>Converting compiled files and external libraries into ${outdir}/${dex-file}...</echo>
166     <apply executable="${dx}" failonerror="true" parallel="true">
167       <arg value="--dex" />
168       <arg value="--output=${intermediate-dex-ospath}" />
169       <arg path="${outdir-classes-ospath}" />
170       <fileset dir="${external-libs}" includes="*.jar"/>
171     </apply>
172   </target>
173
174   <!-- Put the project's resources into the output package file. -->
175   <target name="package-res-and-assets">
176     <echo>Packaging resources and assets...</echo>
177     <exec executable="${aapt}" failonerror="true">
178       <arg value="package" />
179       <arg value="-f" />
180       <arg value="-M" />
181       <arg value="AndroidManifest.xml" />
182       <arg value="-S" />
183       <arg value="${resource-dir}" />
184       <arg value="-A" />
185       <arg value="${asset-dir}" />
186       <arg value="-I" />
187       <arg value="${android-jar}" />
188       <arg value="-F" />
189       <arg value="${resources-package}" />
190     </exec>
191   </target>
192
193   <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
194   <target name="package-res-no-assets">
195     <echo>Packaging resources...</echo>
196     <exec executable="${aapt}" failonerror="true">
197       <arg value="package" />
198       <arg value="-f" />
199       <arg value="-M" />
200       <arg value="AndroidManifest.xml" />
201       <arg value="-S" />
202       <arg value="${resource-dir}" />
203       <!-- No assets directory -->
204       <arg value="-I" />
205       <arg value="${android-jar}" />
206       <arg value="-F" />
207       <arg value="${resources-package}" />
208     </exec>
209   </target>
210
211   <!-- Invoke the proper target depending on whether or not
212 an assets directory is present. -->
213   <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
214 only when the assets dir exists. -->
215   <target name="package-res">
216     <available file="${asset-dir}" type="dir"
217                property="res-target" value="and-assets" />
218     <property name="res-target" value="no-assets" />
219     <antcall target="package-res-${res-target}" />
220   </target>
221
222   <!-- Package the application and sign it with a debug key.
223       This is the default target when building. It is used for debug. -->
224   <target name="debug" depends="dex, package-res">
225     <echo>Packaging ${out-debug-package}, and signing it with a debug key...</echo>
226     <exec executable="${apk-builder}" failonerror="true">
227       <arg value="${out-debug-package-ospath}" />
228       <arg value="-z" />
229       <arg value="${resources-package-ospath}" />
230       <arg value="-f" />
231       <arg value="${intermediate-dex-ospath}" />
232       <arg value="-rf" />
233       <arg value="${srcdir-ospath}" />
234       <arg value="-rj" />
235       <arg value="${external-libs-ospath}" />
236     </exec>
237   </target>
238
239   <!-- Package the application without signing it.
240         This allows for the application to be signed later with an official publishing key. -->
241   <target name="release" depends="dex, package-res">
242     <echo>Packaging ${out-unsigned-package} for release...</echo>
243     <exec executable="${apk-builder}" failonerror="true">
244       <arg value="${out-unsigned-package-ospath}" />
245       <arg value="-u" />
246       <arg value="-z" />
247       <arg value="${resources-package-ospath}" />
248       <arg value="-f" />
249       <arg value="${intermediate-dex-ospath}" />
250       <arg value="-rf" />
251       <arg value="${srcdir-ospath}" />
252       <arg value="-rj" />
253       <arg value="${external-libs-ospath}" />
254     </exec>
255     <echo>It will need to be signed with jarsigner before being published.</echo>
256   </target>
257
258   <!-- Install the package on the default emulator -->
259   <target name="install" depends="debug">
260     <echo>Installing ${out-debug-package} onto default emulator...</echo>
261     <exec executable="${adb}" failonerror="true">
262       <arg value="install" />
263       <arg value="${out-debug-package}" />
264     </exec>
265   </target>
266
267   <target name="reinstall" depends="debug">
268     <echo>Installing ${out-debug-package} onto default emulator...</echo>
269     <exec executable="${adb}" failonerror="true">
270       <arg value="install" />
271       <arg value="-r" />
272       <arg value="${out-debug-package}" />
273     </exec>
274   </target>
275
276   <!-- Uinstall the package from the default emulator -->
277   <target name="uninstall">
278     <echo>Uninstalling ${application-package} from the default emulator...</echo>
279     <exec executable="${adb}" failonerror="true">
280       <arg value="uninstall" />
281       <arg value="${application-package}" />
282     </exec>
283   </target>
284
285   <target name="clean">
286     <delete dir="${outdir}"/>
287   </target>
288
289 </project>