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