More aggressive inlining, to inline some key methods like BitArray.get(), resulting...
[zxing.git] / android / build.xml
1 <?xml version="1.0" ?>
2
3 <!--
4  Copyright (C) 2008 Google Inc.
5
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9
10       http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17  -->
18
19 <!-- This is a mildly hacked version of the auto-generated project
20      build.xml file. -->
21 <project name="BarcodeReader" default="package">
22   <property file="../build.properties"/>
23   <property name="sdk-folder" value="${android-home}"/>
24   <property name="android-tools" value="${sdk-folder}/tools"/>
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}/${ant.project.name}.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="zip" value="zip"/>
55   <property name="android-jar" value="${sdk-folder}/android.jar"/>
56
57   <!-- Rules -->
58
59   <target name="init">
60     <tstamp/>
61     <fail message="Please set 'android-home' in build.properties">
62       <condition>
63         <not>
64           <available file="${android-home}" type="dir"/>
65         </not>
66       </condition>
67     </fail>
68     <fail message="Please build 'core' first">
69       <condition>
70         <not>
71           <available file="../core/core.jar" type="file"/>
72         </not>
73       </condition>
74     </fail>
75     <fail message="Please put proguard.jar in 'bin' under the WTK install directory">
76       <condition>
77         <and>
78           <not>
79             <isset property="debug"/>
80           </not>
81           <not>
82             <available file="${WTK-home}/bin/proguard.jar" type="file"/>
83           </not>
84         </and>
85       </condition>
86     </fail>
87   </target>
88
89   <!-- Create the output directories if they don't exist yet. -->
90   <target name="dirs">
91     <mkdir dir="${outdir}"/>
92     <mkdir dir="${outdir-classes}"/>
93   </target>
94
95   <!-- Generate the R.java file for this project's resources. -->
96   <target name="resource-src" depends="dirs">
97
98     <copy file="strings.xml.template" tofile="res/values/strings.xml" overwrite="true">
99       <filterset>
100         <filter token="VERSION" value="${version}"/>
101       </filterset>
102     </copy>
103
104     <echo>Generating R.java...</echo>
105     <exec executable="${aapt}" failonerror="true">
106       <arg value="compile"/>
107       <arg value="-m"/>
108       <arg value="-J"/>
109       <arg value="${outdir-r}"/>
110       <arg value="-M"/>
111       <arg value="AndroidManifest.xml"/>
112       <arg value="-S"/>
113       <arg value="${resource-dir}"/>
114       <arg value="-I"/>
115       <arg value="${android-jar}"/>
116     </exec>
117   </target>
118
119   <!-- Generate java classes from .aidl files. -->
120   <target name="aidl" depends="dirs">
121     <apply executable="${aidl}" failonerror="true">
122       <fileset dir="${srcdir}">
123         <include name="**/*.aidl"/>
124       </fileset>
125     </apply>
126   </target>
127
128   <!-- Compile this project's .java files into .class files. -->
129   <target name="compile" depends="init, clean, dirs, resource-src, aidl">
130     <javac encoding="ascii" target="1.5" debug="true" optimize="true" extdirs=""
131            srcdir="."
132            destdir="${outdir-classes}"
133            bootclasspath="${android-jar}">
134       <classpath>
135         <pathelement location="../core/core.jar"/>
136       </classpath>
137     </javac>
138     <unzip src="../core/core.jar" dest="${outdir-classes}"/>
139   </target>
140
141   <target name="optimize" depends="compile" unless="debug">
142     <jar basedir="${outdir-classes}" destfile="temp.jar"/>
143     <java jar="${WTK-home}/bin/proguard.jar" fork="true" failonerror="true">
144      <jvmarg value="-Dmaximum.inlined.code.length=32"/>
145      <arg value="-injars temp.jar"/>
146      <arg value="-outjars optimized.jar"/>
147      <arg value="-libraryjars ${android-jar}"/>
148      <arg value="-dontpreverify"/>
149      <arg value="-dontobfuscate"/>
150      <arg value="-keep public class com.google.zxing.client.android.BarcodeReaderCaptureActivity"/>
151      <arg value="-optimizationpasses 7"/>
152      <arg value="-overloadaggressively"/>
153      <arg value="-verbose"/>
154    </java>
155    <delete file="temp.jar"/>
156    <delete dir="${outdir-classes}"/>
157    <mkdir dir="${outdir-classes}"/>
158    <unzip src="optimized.jar" dest="${outdir-classes}"/>
159    <delete file="optimized.jar"/>
160   </target>
161
162   <!-- Convert this project's .class files into .dex files. -->
163   <target name="dex" depends="compile, optimize">
164
165     <condition property="locals" value="full">
166       <isset property="debug"/>
167     </condition>
168     <condition property="locals" value="none">
169       <not>
170         <isset property="debug"/>
171       </not>
172     </condition>
173     <condition property="positions" value="lines">
174       <isset property="debug"/>
175     </condition>
176     <condition property="positions" value="none">
177       <not>
178         <isset property="debug"/>
179       </not>
180     </condition>
181
182     <exec executable="${dx}" failonerror="true">
183       <arg value="-JXmx384M"/>
184       <arg value="--dex"/>
185       <arg value="--output=${intermediate-dex}"/>
186       <arg value="--locals=${locals}"/>
187       <arg value="--positions=${positions}"/>
188       <arg path="${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   <target name="package-dex" depends="dex, package-res">
250     <echo>Packaging dex...</echo>
251     <exec executable="${zip}" failonerror="true">
252       <arg value="-qj"/>
253       <arg value="${out-package}"/>
254       <arg value="${intermediate-dex}"/>
255     </exec>
256   </target>
257
258   <!-- Create the package file for this project from the sources. -->
259   <target name="package" depends="package-dex"/>
260
261   <target name="clean">
262     <delete dir="${outdir}"/>
263   </target>
264
265 </project>