4a6550a6a6c568be90d9c9ed2f7dcc69d85b6058
[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" else="none">
169       <isset property="debug"/>
170     </condition>
171     <condition property="positions" value="lines" else="none">
172       <isset property="debug"/>
173     </condition>
174
175     <exec executable="${dx}" failonerror="true">
176       <arg value="-JXmx384M"/>
177       <arg value="--dex"/>
178       <arg value="--output=${intermediate-dex}"/>
179       <arg value="--locals=${locals}"/>
180       <arg value="--positions=${positions}"/>
181       <arg path="${basedir}/${outdir-classes}"/>
182     </exec>
183   </target>
184
185   <!-- Put the project's resources into the output package file. -->
186   <target name="package-res-and-assets">
187     <echo>Packaging resources and assets...</echo>
188     <exec executable="${aapt}" failonerror="true">
189       <arg value="package"/>
190       <arg value="-f"/>
191       <arg value="-c"/>
192       <arg value="-M"/>
193       <arg value="AndroidManifest.xml"/>
194       <arg value="-S"/>
195       <arg value="${resource-dir}"/>
196       <arg value="-A"/>
197       <arg value="${asset-dir}"/>
198       <arg value="-I"/>
199       <arg value="${android-jar}"/>
200       <arg value="${out-package}"/>
201     </exec>
202   </target>
203
204   <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
205   <target name="package-res-no-assets">
206     <echo>Packaging resources...</echo>
207     <exec executable="${aapt}" failonerror="true">
208       <arg value="package"/>
209       <arg value="-f"/>
210       <arg value="-c"/>
211       <arg value="-M"/>
212       <arg value="AndroidManifest.xml"/>
213       <arg value="-S"/>
214       <arg value="${resource-dir}"/>
215       <!-- No assets directory -->
216       <arg value="-I"/>
217       <arg value="${android-jar}"/>
218       <arg value="${out-package}"/>
219     </exec>
220   </target>
221
222   <!-- Invoke the proper target depending on whether or not
223 an assets directory is present. -->
224   <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
225 only when the assets dir exists. -->
226   <target name="package-res">
227     <available file="${asset-dir}" type="dir"
228                property="res-target" value="and-assets"/>
229     <property name="res-target" value="no-assets"/>
230     <antcall target="package-res-${res-target}"/>
231   </target>
232
233   <!-- Put the project's .class files into the output package file. -->
234   <target name="package-java" depends="compile, package-res">
235     <echo>Packaging java...</echo>
236     <jar destfile="${out-package}"
237          basedir="${outdir-classes}"
238          update="true"/>
239   </target>
240
241   <!-- Put the project's .dex files into the output package file.
242        Use the "zip" command, available on most un*x/Linux/MacOS systems,
243        to create the new package (Ant 1.7 has an internal 'zip' command,
244        however Ant 1.6.5 lacks it and is still widely installed.)
245   -->
246   <target name="package-dex" depends="dex, package-res">
247     <echo>Packaging dex...</echo>
248     <exec executable="${zip}" failonerror="true">
249       <arg value="-qj"/>
250       <arg value="${out-package}"/>
251       <arg value="${intermediate-dex}"/>
252     </exec>
253   </target>
254
255   <!-- Create the package file for this project from the sources. -->
256   <target name="package" depends="package-dex"/>
257
258   <!-- Install package on the default emulator -->
259   <target name="install">
260     <echo>Sending package to default emulator...</echo>
261     <exec executable="${adb}" failonerror="true">
262       <arg value="install" />
263       <arg value="${out-package}" />
264     </exec>
265   </target>
266
267   <target name="clean">
268     <delete dir="${outdir}"/>
269   </target>
270
271 </project>