7fd06fe30f35be7c40f003b988025a42f741888f
[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      <arg value="-injars temp.jar"/>
145      <arg value="-outjars optimized.jar"/>
146      <arg value="-libraryjars ${android-jar}"/>
147      <arg value="-dontpreverify"/>
148      <arg value="-dontobfuscate"/>
149      <arg value="-keep public class com.google.zxing.client.android.BarcodeReaderCaptureActivity"/>
150      <arg value="-optimizationpasses 7"/>
151      <arg value="-overloadaggressively"/>
152      <arg value="-verbose"/>
153    </java>
154    <delete file="temp.jar"/>
155    <delete dir="${outdir-classes}"/>
156    <mkdir dir="${outdir-classes}"/>
157    <unzip src="optimized.jar" dest="${outdir-classes}"/>
158    <delete file="optimized.jar"/>
159   </target>
160
161   <!-- Convert this project's .class files into .dex files. -->
162   <target name="dex" depends="compile, optimize">
163
164     <condition property="locals" value="full">
165       <isset property="debug"/>
166     </condition>
167     <condition property="locals" value="none">
168       <not>
169         <isset property="debug"/>
170       </not>
171     </condition>
172     <condition property="positions" value="lines">
173       <isset property="debug"/>
174     </condition>
175     <condition property="positions" value="none">
176       <not>
177         <isset property="debug"/>
178       </not>
179     </condition>
180
181     <exec executable="${dx}" failonerror="true">
182       <arg value="-JXmx384M"/>
183       <arg value="--dex"/>
184       <arg value="--output=${intermediate-dex}"/>
185       <arg value="--locals=${locals}"/>
186       <arg value="--positions=${positions}"/>
187       <arg path="${outdir-classes}"/>
188     </exec>
189   </target>
190
191   <!-- Put the project's resources into the output package file. -->
192   <target name="package-res-and-assets">
193     <echo>Packaging resources and assets...</echo>
194     <exec executable="${aapt}" failonerror="true">
195       <arg value="package"/>
196       <arg value="-f"/>
197       <arg value="-c"/>
198       <arg value="-M"/>
199       <arg value="AndroidManifest.xml"/>
200       <arg value="-S"/>
201       <arg value="${resource-dir}"/>
202       <arg value="-A"/>
203       <arg value="${asset-dir}"/>
204       <arg value="-I"/>
205       <arg value="${android-jar}"/>
206       <arg value="${out-package}"/>
207     </exec>
208   </target>
209
210   <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
211   <target name="package-res-no-assets">
212     <echo>Packaging resources...</echo>
213     <exec executable="${aapt}" failonerror="true">
214       <arg value="package"/>
215       <arg value="-f"/>
216       <arg value="-c"/>
217       <arg value="-M"/>
218       <arg value="AndroidManifest.xml"/>
219       <arg value="-S"/>
220       <arg value="${resource-dir}"/>
221       <!-- No assets directory -->
222       <arg value="-I"/>
223       <arg value="${android-jar}"/>
224       <arg value="${out-package}"/>
225     </exec>
226   </target>
227
228   <!-- Invoke the proper target depending on whether or not
229 an assets directory is present. -->
230   <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
231 only when the assets dir exists. -->
232   <target name="package-res">
233     <available file="${asset-dir}" type="dir"
234                property="res-target" value="and-assets"/>
235     <property name="res-target" value="no-assets"/>
236     <antcall target="package-res-${res-target}"/>
237   </target>
238
239   <!-- Put the project's .class files into the output package file. -->
240   <target name="package-java" depends="compile, package-res">
241     <echo>Packaging java...</echo>
242     <jar destfile="${out-package}"
243          basedir="${outdir-classes}"
244          update="true"/>
245   </target>
246
247   <!-- Put the project's .dex files into the output package file. -->
248   <target name="package-dex" depends="dex, package-res">
249     <echo>Packaging dex...</echo>
250     <exec executable="${zip}" failonerror="true">
251       <arg value="-qj"/>
252       <arg value="${out-package}"/>
253       <arg value="${intermediate-dex}"/>
254     </exec>
255   </target>
256
257   <!-- Create the package file for this project from the sources. -->
258   <target name="package" depends="package-dex"/>
259
260   <target name="clean">
261     <delete dir="${outdir}"/>
262   </target>
263
264 </project>