More little tweaks to make the 'release' build target happy again
[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     <echo>Generating R.java...</echo>
98     <exec executable="${aapt}" failonerror="true">
99       <arg value="compile"/>
100       <arg value="-m"/>
101       <arg value="-J"/>
102       <arg value="${outdir-r}"/>
103       <arg value="-M"/>
104       <arg value="AndroidManifest.xml"/>
105       <arg value="-S"/>
106       <arg value="${resource-dir}"/>
107       <arg value="-I"/>
108       <arg value="${android-jar}"/>
109     </exec>
110   </target>
111
112   <!-- Generate java classes from .aidl files. -->
113   <target name="aidl" depends="dirs">
114     <apply executable="${aidl}" failonerror="true">
115       <fileset dir="${srcdir}">
116         <include name="**/*.aidl"/>
117       </fileset>
118     </apply>
119   </target>
120
121   <!-- Compile this project's .java files into .class files. -->
122   <target name="compile" depends="init, clean, dirs, resource-src, aidl">
123     <javac encoding="ascii" target="1.5" debug="true" optimize="true" extdirs=""
124            srcdir="."
125            destdir="${outdir-classes}"
126            bootclasspath="${android-jar}">
127       <classpath>
128         <pathelement location="../core/core.jar"/>
129       </classpath>
130     </javac>
131     <unzip src="../core/core.jar" dest="${outdir-classes}"/>
132   </target>
133
134   <target name="optimize" depends="compile" unless="debug">
135     <jar basedir="${outdir-classes}" destfile="temp.jar"/>
136     <java jar="${WTK-home}/bin/proguard.jar" fork="true" failonerror="true">
137      <arg value="-injars temp.jar"/>
138      <arg value="-outjars optimized.jar"/>
139      <arg value="-libraryjars ${android-jar}"/>
140      <arg value="-dontpreverify"/>
141      <arg value="-dontobfuscate"/>
142      <arg value="-keep public class com.google.zxing.client.android.BarcodeReaderCaptureActivity"/>
143      <arg value="-optimizationpasses 4"/>
144      <arg value="-verbose"/>
145    </java>
146    <delete file="temp.jar"/>
147    <delete dir="${outdir-classes}"/>
148    <mkdir dir="${outdir-classes}"/>
149    <unzip src="optimized.jar" dest="${outdir-classes}"/>
150    <delete file="optimized.jar"/>
151   </target>
152
153   <!-- Convert this project's .class files into .dex files. -->
154   <target name="dex" depends="compile, optimize">
155
156     <condition property="locals" value="full">
157       <isset property="debug"/>
158     </condition>
159     <condition property="locals" value="none">
160       <not>
161         <isset property="debug"/>
162       </not>
163     </condition>
164     <condition property="positions" value="lines">
165       <isset property="debug"/>
166     </condition>
167     <condition property="positions" value="none">
168       <not>
169         <isset property="debug"/>
170       </not>
171     </condition>
172
173     <exec executable="${dx}" failonerror="true">
174       <arg value="-JXmx384M"/>
175       <arg value="--dex"/>
176       <arg value="--output=${intermediate-dex}"/>
177       <arg value="--locals=${locals}"/>
178       <arg value="--positions=${positions}"/>
179       <arg path="${outdir-classes}"/>
180     </exec>
181   </target>
182
183   <!-- Put the project's resources into the output package file. -->
184   <target name="package-res-and-assets">
185     <echo>Packaging resources and assets...</echo>
186     <exec executable="${aapt}" failonerror="true">
187       <arg value="package"/>
188       <arg value="-f"/>
189       <arg value="-c"/>
190       <arg value="-M"/>
191       <arg value="AndroidManifest.xml"/>
192       <arg value="-S"/>
193       <arg value="${resource-dir}"/>
194       <arg value="-A"/>
195       <arg value="${asset-dir}"/>
196       <arg value="-I"/>
197       <arg value="${android-jar}"/>
198       <arg value="${out-package}"/>
199     </exec>
200   </target>
201
202   <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
203   <target name="package-res-no-assets">
204     <echo>Packaging resources...</echo>
205     <exec executable="${aapt}" failonerror="true">
206       <arg value="package"/>
207       <arg value="-f"/>
208       <arg value="-c"/>
209       <arg value="-M"/>
210       <arg value="AndroidManifest.xml"/>
211       <arg value="-S"/>
212       <arg value="${resource-dir}"/>
213       <!-- No assets directory -->
214       <arg value="-I"/>
215       <arg value="${android-jar}"/>
216       <arg value="${out-package}"/>
217     </exec>
218   </target>
219
220   <!-- Invoke the proper target depending on whether or not
221 an assets directory is present. -->
222   <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
223 only when the assets dir exists. -->
224   <target name="package-res">
225     <available file="${asset-dir}" type="dir"
226                property="res-target" value="and-assets"/>
227     <property name="res-target" value="no-assets"/>
228     <antcall target="package-res-${res-target}"/>
229   </target>
230
231   <!-- Put the project's .class files into the output package file. -->
232   <target name="package-java" depends="compile, package-res">
233     <echo>Packaging java...</echo>
234     <jar destfile="${out-package}"
235          basedir="${outdir-classes}"
236          update="true"/>
237   </target>
238
239   <!-- Put the project's .dex files into the output package file. -->
240   <target name="package-dex" depends="dex, package-res">
241     <echo>Packaging dex...</echo>
242     <exec executable="${zip}" failonerror="true">
243       <arg value="-qj"/>
244       <arg value="${out-package}"/>
245       <arg value="${intermediate-dex}"/>
246     </exec>
247   </target>
248
249   <!-- Create the package file for this project from the sources. -->
250   <target name="package" depends="package-dex"/>
251
252   <target name="clean">
253     <delete dir="${outdir}"/>
254   </target>
255
256 </project>