Changed the project names for the two Android clients to disambiguate them.
[zxing.git] / android / build.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  Copyright (C) 2008 Google Inc.
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
18 <!-- This is a mildly hacked version of the auto-generated project
19      build.xml file. -->
20 <project name="BarcodeReaderM5" default="package">
21   <property file="../build.properties"/>
22   <property name="sdk-folder" value="${android-home}"/>
23   <property name="android-tools" value="${sdk-folder}/tools"/>
24   <property name="android-framework" value="${android-tools}/lib/framework.aidl"/>
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   <!-- No user servicable parts below. -->
31
32   <!-- Input directories -->
33   <property name="resource-dir" value="res"/>
34   <property name="asset-dir" value="assets"/>
35   <property name="srcdir" value="src"/>
36
37   <!-- Output directories -->
38   <property name="outdir-classes" value="${outdir}/classes"/>
39
40   <!-- Create R.java in the source directory -->
41   <property name="outdir-r" value="src"/>
42
43   <!-- Intermediate files -->
44   <property name="dex-file" value="classes.dex"/>
45   <property name="intermediate-dex" value="${outdir}/${dex-file}"/>
46
47   <!-- The final package file to generate -->
48   <property name="out-package" value="${outdir}/BarcodeReader.apk"/>
49
50   <!-- Tools -->
51   <property name="aapt" value="${android-tools}/aapt"/>
52   <property name="aidl" value="${android-tools}/aidl"/>
53   <property name="dx" value="${android-tools}/dx"/>
54   <property name="adb" value="${android-tools}/adb" />
55   <property name="android-jar" value="${sdk-folder}/android.jar" />
56   <property name="zip" value="zip"/>
57
58   <!-- Rules -->
59
60   <target name="init">
61     <tstamp/>
62     <fail message="Please set 'android-home' in build.properties">
63       <condition>
64         <not>
65           <available file="${android-home}" type="dir"/>
66         </not>
67       </condition>
68     </fail>
69     <fail message="Please build 'core' first">
70       <condition>
71         <not>
72           <available file="../core/core.jar" type="file"/>
73         </not>
74       </condition>
75     </fail>
76     <fail message="Please put proguard.jar in 'bin' under the WTK install directory">
77       <condition>
78         <and>
79           <not>
80             <isset property="debug"/>
81           </not>
82           <not>
83             <available file="${WTK-home}/bin/proguard.jar" type="file"/>
84           </not>
85         </and>
86       </condition>
87     </fail>
88   </target>
89
90   <!-- Create the output directories if they don't exist yet. -->
91   <target name="dirs">
92     <mkdir dir="${outdir}"/>
93     <mkdir dir="${outdir-classes}"/>
94   </target>
95
96   <!-- Generate the R.java file for this project's resources. -->
97   <target name="resource-src" depends="dirs">
98
99     <copy file="strings.xml.template" tofile="res/values/strings.xml" overwrite="true">
100       <filterset>
101         <filter token="VERSION" value="${version}"/>
102       </filterset>
103     </copy>
104
105     <echo>Generating R.java...</echo>
106     <exec executable="${aapt}" failonerror="true">
107       <arg value="compile"/>
108       <arg value="-m"/>
109       <arg value="-J"/>
110       <arg value="${outdir-r}"/>
111       <arg value="-M"/>
112       <arg value="AndroidManifest.xml"/>
113       <arg value="-S"/>
114       <arg value="${resource-dir}"/>
115       <arg value="-I"/>
116       <arg value="${android-jar}"/>
117     </exec>
118   </target>
119
120   <!-- Generate java classes from .aidl files. -->
121   <target name="aidl" depends="dirs">
122     <apply executable="${aidl}" failonerror="true">
123       <arg value="-p${android-framework}"/>
124       <arg value="-I${srcdir}"/>
125       <fileset dir="${srcdir}">
126         <include name="**/*.aidl"/>
127       </fileset>
128     </apply>
129   </target>
130
131   <!-- Compile this project's .java files into .class files. -->
132   <target name="compile" depends="init, clean, dirs, resource-src, aidl">
133     <javac encoding="ascii" target="1.5" debug="true" optimize="true" extdirs=""
134            srcdir="."
135            destdir="${outdir-classes}"
136            bootclasspath="${android-jar}">
137       <classpath>
138         <pathelement location="../core/core.jar"/>
139       </classpath>
140     </javac>
141     <unzip src="../core/core.jar" dest="${outdir-classes}"/>
142   </target>
143
144   <target name="optimize" depends="compile" unless="debug">
145     <jar basedir="${outdir-classes}" destfile="temp.jar"/>
146     <java jar="${WTK-home}/bin/proguard.jar" fork="true" failonerror="true">
147      <jvmarg value="-Dmaximum.inlined.code.length=32"/>
148      <arg value="-injars temp.jar"/>
149      <arg value="-outjars optimized.jar"/>
150      <arg value="-libraryjars ${android-jar}"/>
151      <arg value="-dontpreverify"/>
152      <arg value="-dontobfuscate"/>
153      <arg value="-keep public class com.google.zxing.client.android.BarcodeReaderCaptureActivity"/>
154      <arg value="-optimizationpasses 7"/>
155      <arg value="-overloadaggressively"/>
156      <arg value="-verbose"/>
157    </java>
158    <delete file="temp.jar"/>
159    <delete dir="${outdir-classes}"/>
160    <mkdir dir="${outdir-classes}"/>
161    <unzip src="optimized.jar" dest="${outdir-classes}"/>
162    <delete file="optimized.jar"/>
163   </target>
164
165   <!-- Convert this project's .class files into .dex files. -->
166   <target name="dex" depends="compile, optimize">
167
168     <condition property="locals" value="full">
169       <isset property="debug"/>
170     </condition>
171     <condition property="locals" value="none">
172       <not>
173         <isset property="debug"/>
174       </not>
175     </condition>
176     <condition property="positions" value="lines">
177       <isset property="debug"/>
178     </condition>
179     <condition property="positions" value="none">
180       <not>
181         <isset property="debug"/>
182       </not>
183     </condition>
184
185     <exec executable="${dx}" failonerror="true">
186       <arg value="-JXmx384M"/>
187       <arg value="--dex"/>
188       <arg value="--output=${intermediate-dex}"/>
189       <arg value="--locals=${locals}"/>
190       <arg value="--positions=${positions}"/>
191       <arg path="${basedir}/${outdir-classes}"/>
192     </exec>
193   </target>
194
195   <!-- Put the project's resources into the output package file. -->
196   <target name="package-res-and-assets">
197     <echo>Packaging resources and assets...</echo>
198     <exec executable="${aapt}" failonerror="true">
199       <arg value="package"/>
200       <arg value="-f"/>
201       <arg value="-c"/>
202       <arg value="-M"/>
203       <arg value="AndroidManifest.xml"/>
204       <arg value="-S"/>
205       <arg value="${resource-dir}"/>
206       <arg value="-A"/>
207       <arg value="${asset-dir}"/>
208       <arg value="-I"/>
209       <arg value="${android-jar}"/>
210       <arg value="${out-package}"/>
211     </exec>
212   </target>
213
214   <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
215   <target name="package-res-no-assets">
216     <echo>Packaging resources...</echo>
217     <exec executable="${aapt}" failonerror="true">
218       <arg value="package"/>
219       <arg value="-f"/>
220       <arg value="-c"/>
221       <arg value="-M"/>
222       <arg value="AndroidManifest.xml"/>
223       <arg value="-S"/>
224       <arg value="${resource-dir}"/>
225       <!-- No assets directory -->
226       <arg value="-I"/>
227       <arg value="${android-jar}"/>
228       <arg value="${out-package}"/>
229     </exec>
230   </target>
231
232   <!-- Invoke the proper target depending on whether or not
233 an assets directory is present. -->
234   <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
235 only when the assets dir exists. -->
236   <target name="package-res">
237     <available file="${asset-dir}" type="dir"
238                property="res-target" value="and-assets"/>
239     <property name="res-target" value="no-assets"/>
240     <antcall target="package-res-${res-target}"/>
241   </target>
242
243   <!-- Put the project's .class files into the output package file. -->
244   <target name="package-java" depends="compile, package-res">
245     <echo>Packaging java...</echo>
246     <jar destfile="${out-package}"
247          basedir="${outdir-classes}"
248          update="true"/>
249   </target>
250
251   <!-- Put the project's .dex files into the output package file.
252        Use the "zip" command, available on most un*x/Linux/MacOS systems,
253        to create the new package (Ant 1.7 has an internal 'zip' command,
254        however Ant 1.6.5 lacks it and is still widely installed.)
255   -->
256   <target name="package-dex" depends="dex, package-res">
257     <echo>Packaging dex...</echo>
258     <exec executable="${zip}" failonerror="true">
259       <arg value="-qj"/>
260       <arg value="${out-package}"/>
261       <arg value="${intermediate-dex}"/>
262     </exec>
263   </target>
264
265   <!-- Create the package file for this project from the sources. -->
266   <target name="package" depends="package-dex"/>
267
268   <!-- Install package on the default emulator -->
269   <target name="install">
270     <echo>Sending package to default emulator...</echo>
271     <exec executable="${adb}" failonerror="true">
272       <arg value="install" />
273       <arg value="${out-package}" />
274     </exec>
275   </target>
276
277   <target name="clean">
278     <delete dir="${outdir}"/>
279   </target>
280
281 </project>