Merged revisions 321,327,330,332,334,342-343,352-353,355-358,361-363,365,372 via...
[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" location="${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   <!-- dx is a special case as it is a .bat file on Windows -->
54   <condition property="dx" value="${android-tools}/dx.bat" else="${android-tools}/dx">
55     <os family="windows"/>
56   </condition>
57   <property name="adb" value="${android-tools}/adb" />
58   <property name="android-jar" value="${sdk-folder}/android.jar" />
59   <property name="zip" value="zip"/>
60
61   <!-- Rules -->
62
63   <target name="init">
64     <tstamp/>
65     <fail message="Please set 'android-m5-home' in build.properties">
66       <condition>
67         <not>
68           <available file="${android-home}" type="dir"/>
69         </not>
70       </condition>
71     </fail>
72     <fail message="Please build 'core' first">
73       <condition>
74         <not>
75           <available file="../core/core.jar" type="file"/>
76         </not>
77       </condition>
78     </fail>
79     <fail message="Please put proguard.jar in 'bin' under the WTK install directory">
80       <condition>
81         <and>
82           <not>
83             <isset property="debug"/>
84           </not>
85           <not>
86             <available file="${WTK-home}/bin/proguard.jar" type="file"/>
87           </not>
88         </and>
89       </condition>
90     </fail>
91   </target>
92
93   <!-- Create the output directories if they don't exist yet. -->
94   <target name="dirs">
95     <mkdir dir="${outdir}"/>
96     <mkdir dir="${outdir-classes}"/>
97   </target>
98
99   <!-- Generate the R.java file for this project's resources. -->
100   <target name="resource-src" depends="dirs">
101
102     <copy file="strings.xml.template" tofile="res/values/strings.xml" overwrite="true">
103       <filterset>
104         <filter token="VERSION" value="${version}"/>
105       </filterset>
106     </copy>
107
108     <echo>Generating R.java...</echo>
109     <exec executable="${aapt}" failonerror="true">
110       <arg value="compile"/>
111       <arg value="-m"/>
112       <arg value="-J"/>
113       <arg value="${outdir-r}"/>
114       <arg value="-M"/>
115       <arg value="AndroidManifest.xml"/>
116       <arg value="-S"/>
117       <arg value="${resource-dir}"/>
118       <arg value="-I"/>
119       <arg value="${android-jar}"/>
120     </exec>
121   </target>
122
123   <!-- Generate java classes from .aidl files. -->
124   <target name="aidl" depends="dirs">
125     <apply executable="${aidl}" failonerror="true">
126       <arg value="-p${android-framework}"/>
127       <arg value="-I${srcdir}"/>
128       <fileset dir="${srcdir}">
129         <include name="**/*.aidl"/>
130       </fileset>
131     </apply>
132   </target>
133
134   <!-- Compile this project's .java files into .class files. -->
135   <target name="compile" depends="init, clean, dirs, resource-src, aidl">
136     <javac encoding="ascii" target="1.5" debug="true" optimize="true" extdirs=""
137            srcdir="."
138            destdir="${outdir-classes}"
139            bootclasspath="${android-jar}">
140       <classpath>
141         <pathelement location="../core/core.jar"/>
142       </classpath>
143     </javac>
144     <unzip src="../core/core.jar" dest="${outdir-classes}"/>
145   </target>
146
147   <target name="optimize" depends="compile" unless="debug">
148     <jar basedir="${outdir-classes}" destfile="temp.jar"/>
149     <java jar="${WTK-home}/bin/proguard.jar" fork="true" failonerror="true">
150       <jvmarg value="-Dmaximum.inlined.code.length=32"/>
151       <arg value="-injars temp.jar"/>
152       <arg value="-outjars optimized.jar"/>
153       <arg value="-libraryjars ${android-jar}"/>
154       <arg value="-dontpreverify"/>
155       <arg value="-dontobfuscate"/>
156       <!-- Temporary workaround to keep important stuff in the client, while inlining core. -->
157       <arg value="-keep class com.google.zxing.client.android.BarcodeReaderCaptureActivity { *; }"/>
158       <arg value="-keep class com.google.zxing.client.android.CameraManager { *; }"/>
159       <arg value="-keep class com.google.zxing.client.android.CameraThread { *; }"/>
160       <arg value="-optimizationpasses 7"/>
161       <arg value="-overloadaggressively"/>
162       <arg value="-verbose"/>
163       <!-- Needed to allow getters which refer to private members to be inlined. -->
164       <arg value="-allowaccessmodification"/>
165     </java>
166     <delete file="temp.jar"/>
167     <delete dir="${outdir-classes}"/>
168     <mkdir dir="${outdir-classes}"/>
169     <unzip src="optimized.jar" dest="${outdir-classes}"/>
170     <delete file="optimized.jar"/>
171   </target>
172
173   <!-- Convert this project's .class files into .dex files. -->
174   <target name="dex" depends="compile, optimize">
175
176     <condition property="locals" value="full" else="none">
177       <isset property="debug"/>
178     </condition>
179     <condition property="positions" value="lines" else="none">
180       <isset property="debug"/>
181     </condition>
182
183     <exec executable="${dx}" failonerror="true">
184       <arg value="--dex"/>
185       <arg value="--output=${intermediate-dex}"/>
186       <arg value="--locals=${locals}"/>
187       <arg value="--positions=${positions}"/>
188       <arg path="${basedir}/${outdir-classes}"/>
189     </exec>
190   </target>
191
192   <!-- Put the project's resources into the output package file. -->
193   <target name="package-res-and-assets">
194     <echo>Packaging resources and assets...</echo>
195     <exec executable="${aapt}" failonerror="true">
196       <arg value="package"/>
197       <arg value="-f"/>
198       <arg value="-c"/>
199       <arg value="-M"/>
200       <arg value="AndroidManifest.xml"/>
201       <arg value="-S"/>
202       <arg value="${resource-dir}"/>
203       <arg value="-A"/>
204       <arg value="${asset-dir}"/>
205       <arg value="-I"/>
206       <arg value="${android-jar}"/>
207       <arg value="${out-package}"/>
208     </exec>
209   </target>
210
211   <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
212   <target name="package-res-no-assets">
213     <echo>Packaging resources...</echo>
214     <exec executable="${aapt}" failonerror="true">
215       <arg value="package"/>
216       <arg value="-f"/>
217       <arg value="-c"/>
218       <arg value="-M"/>
219       <arg value="AndroidManifest.xml"/>
220       <arg value="-S"/>
221       <arg value="${resource-dir}"/>
222       <!-- No assets directory -->
223       <arg value="-I"/>
224       <arg value="${android-jar}"/>
225       <arg value="${out-package}"/>
226     </exec>
227   </target>
228
229   <!-- Invoke the proper target depending on whether or not
230 an assets directory is present. -->
231   <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
232 only when the assets dir exists. -->
233   <target name="package-res">
234     <available file="${asset-dir}" type="dir"
235                property="res-target" value="and-assets"/>
236     <property name="res-target" value="no-assets"/>
237     <antcall target="package-res-${res-target}"/>
238   </target>
239
240   <!-- Put the project's .class files into the output package file. -->
241   <target name="package-java" depends="compile, package-res">
242     <echo>Packaging java...</echo>
243     <jar destfile="${out-package}"
244          basedir="${outdir-classes}"
245          update="true"/>
246   </target>
247
248   <!-- Put the project's .dex files into the output package file.
249        Use the "zip" command, available on most un*x/Linux/MacOS systems,
250        to create the new package (Ant 1.7 has an internal 'zip' command,
251        however Ant 1.6.5 lacks it and is still widely installed.)
252   -->
253   <target name="package-dex" depends="dex, package-res">
254     <echo>Packaging dex...</echo>
255     <exec executable="${zip}" failonerror="true">
256       <arg value="-qj"/>
257       <arg value="${out-package}"/>
258       <arg value="${intermediate-dex}"/>
259     </exec>
260   </target>
261
262   <!-- Create the package file for this project from the sources. -->
263   <target name="package" depends="package-dex"/>
264
265   <!-- Install package on the default emulator -->
266   <target name="install">
267     <echo>Sending package to default emulator...</echo>
268     <exec executable="${adb}" failonerror="true">
269       <arg value="install" />
270       <arg value="${out-package}" />
271     </exec>
272   </target>
273
274   <target name="clean">
275     <delete dir="${outdir}"/>
276   </target>
277
278 </project>