Fixed: pause -> onPause, resume -> onResume
[zxing.git] / android / build.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3 Copyright (C) 2008 ZXing authors
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 <project name="BarcodeScanner" default="debug">
18
19   <!-- Normally the Android build system looks for a local.properties. Since that's only used
20   to find the SDK location, I've removed it and pointed us at the global ZXing build.properties. -->
21   <property file="../build.properties"/>
22   <!-- Parts of the Android build system insist on the name 'sdk-location', so alias it. -->
23   <property name="sdk.dir" value="${android-home}"/>
24
25   <!-- The build.properties file can be created by you and is never touched
26   by the 'android' tool. This is the place to change some of the default property values
27   used by the Ant rules.
28   Here are some properties you may want to change/update:
29
30   application-package
31       the name of your application package as defined in the manifest. Used by the
32       'uninstall' rule.
33   source-folder
34       the name of the source folder. Default is 'src'.
35   out-folder
36       the name of the output folder. Default is 'bin'.
37
38   Properties related to the SDK location or the project target should be updated
39    using the 'android' tool with the 'update' action.
40
41   This file is an integral part of the build system for your application and
42   should be checked in in Version Control Systems.
43
44   -->
45   <property file="build.properties"/>
46
47   <!-- The default.properties file is created and updated by the 'android' tool, as well as ADT.
48   This file is an integral part of the build system for your application and
49   should be checked in in Version Control Systems. -->
50   <property file="default.properties"/>
51
52   <!-- Custom Android task to deal with the project target, and import the proper rules.
53   This requires ant 1.6.0 or above. -->
54   <path id="android.antlibs">
55     <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
56     <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
57     <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
58     <pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" />
59     <pathelement path="${sdk.dir}/tools/lib/jarutils.jar" />
60   </path>
61
62   <taskdef name="setup"
63            classname="com.android.ant.SetupTask"
64            classpathref="android.antlibs"/>
65
66   <!-- Execute the Android Setup task that will setup some properties specific to the target,
67        and import the rules files.
68        To customize the rules, copy/paste them below the task, and disable import by setting
69        the import attribute to false:
70           <setup import="false" />
71
72        This will ensure that the properties are setup correctly but that your customized
73        targets are used.
74   -->
75   <setup import="false" />
76
77   <!-- Custom tasks -->
78   <taskdef name="aaptexec"
79            classname="com.android.ant.AaptExecLoopTask"
80            classpathref="android.antlibs"/>
81
82   <taskdef name="apkbuilder"
83            classname="com.android.ant.ApkBuilderTask"
84            classpathref="android.antlibs"/>
85
86   <!-- Properties -->
87
88   <property name="android-tools" value="${sdk.dir}/tools" />
89
90   <!-- Input directories -->
91   <property name="source-folder" value="src" />
92   <property name="gen-folder" value="gen" />
93   <property name="resource-folder" value="res" />
94   <property name="asset-folder" value="assets" />
95   <property name="source-location" value="${basedir}/${source-folder}" />
96
97   <!-- folder for the 3rd party java libraries -->
98   <!--<property name="external-libs-folder" value="../core" />-->
99
100   <!-- folder for the native libraries -->
101   <property name="native-libs-folder" value="libs" />
102
103   <!-- Output directories -->
104   <property name="gen-folder" value="gen" />
105   <property name="out-folder" value="bin" />
106   <property name="out-classes" value="${out-folder}/classes" />
107   <property name="out-classes-location" value="${basedir}/${out-classes}"/>
108   <!-- out folders for a parent project if this project is an instrumentation project -->
109   <property name="main-out-folder" value="../${out-folder}" />
110   <property name="main-out-classes" value="${main-out-folder}/classes"/>
111
112   <!-- Intermediate files -->
113   <property name="dex-file" value="classes.dex" />
114   <property name="intermediate-dex" value="${out-folder}/${dex-file}" />
115   <!-- dx does not properly support incorrect / or \ based on the platform
116   and Ant cannot convert them because the parameter is not a valid path.
117   Because of this we have to compute different paths depending on the platform. -->
118   <condition property="intermediate-dex-location"
119              value="${basedir}\${intermediate-dex}"
120              else="${basedir}/${intermediate-dex}" >
121     <os family="windows"/>
122   </condition>
123
124   <!-- The final package file to generate -->
125   <property name="out-debug-package" value="${out-folder}/${ant.project.name}-debug.apk"/>
126
127   <!-- Tools -->
128   <condition property="exe" value=".exe" else=""><os family="windows"/></condition>
129   <property name="adb" value="${android-tools}/adb${exe}"/>
130
131   <!-- rules -->
132
133   <!-- Create the output directories if they don't exist yet. All builds do a clean first
134   to prevent stale resources and to make ProGuard happy. -->
135   <target name="dirs" depends="clean">
136     <echo>Creating output directories if needed...</echo>
137     <mkdir dir="${resource-folder}" />
138     <mkdir dir="${external-libs-folder}" />
139     <mkdir dir="${gen-folder}" />
140     <mkdir dir="${out-folder}" />
141     <mkdir dir="${out-classes}" />
142   </target>
143
144   <!-- Generate the R.java file for this project's resources. -->
145   <target name="resource-src" depends="dirs">
146     <echo>Generating R.java / Manifest.java from the resources...</echo>
147     <exec executable="${aapt}" failonerror="true">
148       <arg value="package" />
149       <arg value="-m" />
150       <arg value="-J" />
151       <arg path="${gen-folder}" />
152       <arg value="-M" />
153       <arg path="AndroidManifest.xml" />
154       <arg value="-S" />
155       <arg path="${resource-folder}" />
156       <arg value="-I" />
157       <arg path="${android.jar}" />
158     </exec>
159   </target>
160
161   <!-- Generate java classes from .aidl files. -->
162   <target name="aidl" depends="dirs">
163     <echo>Compiling aidl files into Java classes...</echo>
164     <apply executable="${aidl}" failonerror="true">
165       <arg value="-p${android-aidl}" />
166       <arg value="-I${source-folder}" />
167       <arg value="-o${gen-folder}" />
168       <fileset dir="${source-folder}">
169         <include name="**/*.aidl"/>
170       </fileset>
171     </apply>
172   </target>
173
174   <!-- Compile this project's .java files into .class files. -->
175   <target name="compile" depends="resource-src, aidl">
176     <javac encoding="ascii" target="1.5" debug="false" extdirs=""
177            destdir="${out-classes}"
178            bootclasspathref="android.target.classpath">
179       <src path="${source-folder}" />
180       <src path="${gen-folder}" />
181       <classpath>
182         <fileset dir="${external-libs-folder}" includes="*.jar"/>
183         <!-- yeah, want to not use this mechanism above -->
184         <pathelement path="../core/core.jar"/>
185         <pathelement path="${main-out-classes}"/>
186       </classpath>
187     </javac>
188
189     <unzip src="../core/core.jar" dest="${out-classes}" overwrite="true"/>
190
191     <antcall target="optimize"/>
192   </target>
193
194   <target name="optimize" unless="no-optimize">
195     <mkdir dir="optimized"/>
196     <property name="libraryjars.path" refid="android.target.classpath"/>
197     <java jar="${proguard-jar}" fork="true" failonerror="true">
198       <jvmarg value="-Dmaximum.inlined.code.length=48"/>
199       <arg value="-injars ${out-classes}"/>
200       <arg value="-outjars optimized"/>
201       <arg value="-libraryjars ${libraryjars.path}"/>
202       <arg value="-keep class com.google.zxing.client.android.*Activity"/>
203       <arg value="-keep class com.google.zxing.client.android.ViewfinderView { public * ; }"/>
204       <arg value="-keep class com.google.zxing.client.android.book.SearchBookContents* { public * ; }"/>
205       <arg value="-target 5"/>
206       <arg value="-optimizationpasses 5"/>
207       <arg value="-optimizations !field/*,!class/merging/*"/> <!-- works around dex VerifyError -->
208       <arg value="-dontshrink"/>
209       <arg value="-dontobfuscate"/>
210       <arg value="-dontskipnonpubliclibraryclasses"/>
211       <arg value="-verbose"/>
212       <arg value="-dump proguard-dump.txt"/>
213     </java>
214     <delete dir="${out-classes}"/>
215     <move file="optimized" tofile="${out-classes}"/>
216   </target>
217
218   <!-- Convert this project's .class files into .dex files. -->
219   <target name="dex" depends="compile">
220     <echo>Converting compiled files and external libraries into ${out-folder}/${dex-file}...</echo>
221     <apply executable="${dx}" failonerror="true" parallel="true">
222       <arg value="-JXmx256M"/>
223       <arg value="--dex" />
224       <arg value="--output=${intermediate-dex-location}" />
225       <arg path="${out-classes-location}" />
226       <fileset dir="${external-libs-folder}" includes="*.jar"/>
227     </apply>
228   </target>
229
230   <!-- Put the project's resources into the output package file
231   This actually can create multiple resource package in case
232   Some custom apk with specific configuration have been
233   declared in default.properties.
234   -->
235   <target name="package-resources">
236     <echo>Packaging resources</echo>
237     <aaptexec executable="${aapt}"
238               command="package"
239               manifest="AndroidManifest.xml"
240               resources="${resource-folder}"
241               assets="${asset-folder}"
242               androidjar="${android.jar}"
243               outfolder="${out-folder}"
244               basename="${ant.project.name}" />
245   </target>
246
247   <!--
248   Getting an error like this?
249
250    [apply] UNEXPECTED TOP-LEVEL EXCEPTION:
251    [apply] com.android.dx.cf.code.SimException: local variable type
252    mismatch: attempt to set or access a value of type int using a local
253    variable of type com.google.zxing.qrcode.decoder.Version. This is
254    symptomatic of .class transformation tools that ignore local variable
255    information.
256
257   Build core/ with the 'build-no-debug' target. It's a long story.
258   -->
259
260   <!-- Package the application and sign it with a debug key.
261   This is the default target when building. It is used for debug. -->
262   <target name="debug" depends="dex, package-resources">
263     <apkbuilder
264         outfolder="${out-folder}"
265         basename="${ant.project.name}"
266         signed="true"
267         verbose="false">
268       <file path="${intermediate-dex}" />
269       <sourcefolder path="${source-folder}" />
270       <jarfolder path="${external-libs-folder}" />
271       <nativefolder path="${native-libs-folder}" />
272     </apkbuilder>
273     <copy file="${out-folder}/BarcodeScanner-debug.apk" tofile="${out-folder}/temp.apk" overwrite="true"/>
274     <exec executable="${android-tools}/zipalign">
275       <arg value="-f"/>
276       <arg value="-v"/>
277       <arg value="4"/>
278       <arg value="${out-folder}/temp.apk"/>
279       <arg value="${out-folder}/BarcodeScanner-debug.apk"/>
280     </exec>
281   </target>
282
283   <!-- Package the application without signing it.
284   This allows for the application to be signed later with an official publishing key. -->
285   <target name="release" depends="dex, package-resources">
286     <apkbuilder
287         outfolder="${out-folder}"
288         basename="${ant.project.name}"
289         signed="false"
290         verbose="false">
291       <file path="${intermediate-dex}" />
292       <sourcefolder path="${source-folder}" />
293       <jarfolder path="${external-libs-folder}" />
294       <nativefolder path="${native-libs-folder}" />
295     </apkbuilder>
296     <echo>All generated packages need to be signed with jarsigner before they are published.</echo>
297     <echo>Also run zipalign -f -v 4 BarcodeScanner.apk BarcodeScanner-aligned.apk after signing</echo>
298   </target>
299
300   <!-- Install the package on the default emulator -->
301   <target name="install" depends="debug">
302     <echo>Installing ${out-debug-package} onto default emulator...</echo>
303     <exec executable="${adb}" failonerror="true">
304       <arg value="install" />
305       <arg path="${out-debug-package}" />
306     </exec>
307   </target>
308
309   <target name="reinstall" depends="debug">
310     <echo>Installing ${out-debug-package} onto default emulator...</echo>
311     <exec executable="${adb}" failonerror="true">
312       <arg value="install" />
313       <arg value="-r" />
314       <arg path="${out-debug-package}" />
315     </exec>
316   </target>
317
318   <!-- Uinstall the package from the default emulator -->
319   <target name="uninstall">
320     <echo>Uninstalling ${application-package} from the default emulator...</echo>
321     <exec executable="${adb}" failonerror="true">
322       <arg value="uninstall" />
323       <arg value="${application-package}" />
324     </exec>
325   </target>
326
327   <target name="help">
328     <echo>Android Ant Build. Available targets:</echo>
329     <echo>   help:      Displays this help.</echo>
330     <echo>   debug:     Builds the application and sign it with a debug key.</echo>
331     <echo>   release:   Builds the application. The generated apk file must be</echo>
332     <echo>              signed before it is published.</echo>
333     <echo>   install:   Installs the debug package onto a running emulator or</echo>
334     <echo>              device. This can only be used if the application has </echo>
335     <echo>              not yet been installed.</echo>
336     <echo>   reinstall: Installs the debug package on a running emulator or</echo>
337     <echo>              device that already has the application.</echo>
338     <echo>              The signatures must match.</echo>
339     <echo>   uninstall: uninstall the application from a running emulator or</echo>
340     <echo>              device.</echo>
341   </target>
342
343   <target name="clean">
344     <delete dir="${out-folder}"/>
345     <delete dir="${gen-folder}"/>
346   </target>
347 </project>