Improved GridSampler API -- no need for reflection anymore. Reintroduced Android...
[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   </target>
76
77   <!-- Create the output directories if they don't exist yet. -->
78   <target name="dirs">
79     <mkdir dir="${outdir}"/>
80     <mkdir dir="${outdir-classes}"/>
81   </target>
82
83   <!-- Generate the R.java file for this project's resources. -->
84   <target name="resource-src" depends="dirs">
85     <echo>Generating R.java...</echo>
86     <exec executable="${aapt}" failonerror="true">
87       <arg value="compile"/>
88       <arg value="-m"/>
89       <arg value="-J"/>
90       <arg value="${outdir-r}"/>
91       <arg value="-M"/>
92       <arg value="AndroidManifest.xml"/>
93       <arg value="-S"/>
94       <arg value="${resource-dir}"/>
95       <arg value="-I"/>
96       <arg value="${android-jar}"/>
97     </exec>
98   </target>
99
100   <!-- Generate java classes from .aidl files. -->
101   <target name="aidl" depends="dirs">
102     <apply executable="${aidl}" failonerror="true">
103       <fileset dir="${srcdir}">
104         <include name="**/*.aidl"/>
105       </fileset>
106     </apply>
107   </target>
108
109   <!-- Compile this project's .java files into .class files. -->
110   <target name="compile" depends="init, dirs, resource-src, aidl">
111     <javac encoding="ascii" target="1.5" debug="false" optimize="true" extdirs=""
112            srcdir="."
113            destdir="${outdir-classes}"
114            bootclasspath="${android-jar}">
115       <classpath>
116         <pathelement location="../core/core.jar"/>
117       </classpath>
118     </javac>
119     <unzip src="../core/core.jar" dest="${outdir-classes}"/>
120   </target>
121
122   <target name="optimize" depends="compile">
123     <jar basedir="${outdir-classes}" destfile="temp.jar"/>
124     <java jar="${WTK-home}/bin/proguard.jar" fork="true" failonerror="true">
125      <arg value="-injars temp.jar"/>
126      <arg value="-outjars optimized.jar"/>
127      <arg value="-libraryjars ${android-jar}"/>
128      <arg value="-dontpreverify"/>
129      <arg value="-dontobfuscate"/>
130      <arg value="-keep public class com.google.zxing.client.android.BarcodeReaderCaptureActivity"/>
131      <arg value="-optimizationpasses 4"/>
132      <arg value="-verbose"/>
133    </java>
134    <delete file="temp.jar"/>
135    <delete dir="${outdir-classes}"/>
136    <mkdir dir="${outdir-classes}"/>
137    <unzip src="optimized.jar" dest="${outdir-classes}"/>
138    <delete file="optimized.jar"/>
139   </target>
140
141   <!-- Convert this project's .class files into .dex files. -->
142   <target name="dex" depends="compile, optimize">
143     <exec executable="${dx}" failonerror="true">
144       <arg value="-JXmx384M"/>
145       <arg value="--dex"/>
146       <arg value="--output=${intermediate-dex}"/>
147       <arg value="--locals=none"/>
148       <arg value="--positions=none"/>
149       <arg path="${outdir-classes}"/>
150     </exec>
151   </target>
152
153   <!-- Put the project's resources into the output package file. -->
154   <target name="package-res-and-assets">
155     <echo>Packaging resources and assets...</echo>
156     <exec executable="${aapt}" failonerror="true">
157       <arg value="package"/>
158       <arg value="-f"/>
159       <arg value="-c"/>
160       <arg value="-M"/>
161       <arg value="AndroidManifest.xml"/>
162       <arg value="-S"/>
163       <arg value="${resource-dir}"/>
164       <arg value="-A"/>
165       <arg value="${asset-dir}"/>
166       <arg value="-I"/>
167       <arg value="${android-jar}"/>
168       <arg value="${out-package}"/>
169     </exec>
170   </target>
171
172   <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
173   <target name="package-res-no-assets">
174     <echo>Packaging resources...</echo>
175     <exec executable="${aapt}" failonerror="true">
176       <arg value="package"/>
177       <arg value="-f"/>
178       <arg value="-c"/>
179       <arg value="-M"/>
180       <arg value="AndroidManifest.xml"/>
181       <arg value="-S"/>
182       <arg value="${resource-dir}"/>
183       <!-- No assets directory -->
184       <arg value="-I"/>
185       <arg value="${android-jar}"/>
186       <arg value="${out-package}"/>
187     </exec>
188   </target>
189
190   <!-- Invoke the proper target depending on whether or not
191 an assets directory is present. -->
192   <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
193 only when the assets dir exists. -->
194   <target name="package-res">
195     <available file="${asset-dir}" type="dir"
196                property="res-target" value="and-assets"/>
197     <property name="res-target" value="no-assets"/>
198     <antcall target="package-res-${res-target}"/>
199   </target>
200
201   <!-- Put the project's .class files into the output package file. -->
202   <target name="package-java" depends="compile, package-res">
203     <echo>Packaging java...</echo>
204     <jar destfile="${out-package}"
205          basedir="${outdir-classes}"
206          update="true"/>
207   </target>
208
209   <!-- Put the project's .dex files into the output package file. -->
210   <target name="package-dex" depends="dex, package-res">
211     <echo>Packaging dex...</echo>
212     <exec executable="${zip}" failonerror="true">
213       <arg value="-qj"/>
214       <arg value="${out-package}"/>
215       <arg value="${intermediate-dex}"/>
216     </exec>
217   </target>
218
219   <!-- Create the package file for this project from the sources. -->
220   <target name="package" depends="package-dex"/>
221
222   <target name="clean">
223     <delete dir="${outdir}"/>
224   </target>
225
226 </project>