Finished work on the local binarizer and renamed it to HybridBinarizer. It uses the...
[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-location" 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-location}/tools/lib/anttasks.jar" />
56     <pathelement path="${sdk-location}/tools/lib/sdklib.jar" />
57     <pathelement path="${sdk-location}/tools/lib/androidprefs.jar" />
58     <pathelement path="${sdk-location}/tools/lib/apkbuilder.jar" />
59     <pathelement path="${sdk-location}/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-location}/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. -->
134   <target name="dirs">
135     <echo>Creating output directories if needed...</echo>
136     <mkdir dir="${resource-folder}" />
137     <mkdir dir="${external-libs-folder}" />
138     <mkdir dir="${gen-folder}" />
139     <mkdir dir="${out-folder}" />
140     <mkdir dir="${out-classes}" />
141   </target>
142
143   <!-- Generate the R.java file for this project's resources. -->
144   <target name="resource-src" depends="dirs">
145     <echo>Generating R.java / Manifest.java from the resources...</echo>
146     <exec executable="${aapt}" failonerror="true">
147       <arg value="package" />
148       <arg value="-m" />
149       <arg value="-J" />
150       <arg path="${gen-folder}" />
151       <arg value="-M" />
152       <arg path="AndroidManifest.xml" />
153       <arg value="-S" />
154       <arg path="${resource-folder}" />
155       <arg value="-I" />
156       <arg path="${android-jar}" />
157     </exec>
158   </target>
159
160   <!-- Generate java classes from .aidl files. -->
161   <target name="aidl" depends="dirs">
162     <echo>Compiling aidl files into Java classes...</echo>
163     <apply executable="${aidl}" failonerror="true">
164       <arg value="-p${android-aidl}" />
165       <arg value="-I${source-folder}" />
166       <arg value="-o${gen-folder}" />
167       <fileset dir="${source-folder}">
168         <include name="**/*.aidl"/>
169       </fileset>
170     </apply>
171   </target>
172
173   <!-- Compile this project's .java files into .class files. -->
174   <target name="compile" depends="resource-src, aidl">
175     <javac encoding="ascii" target="1.5" debug="true" extdirs=""
176            destdir="${out-classes}"
177            bootclasspathref="android.target.classpath">
178       <src path="${source-folder}" />
179       <src path="${gen-folder}" />
180       <classpath>
181         <fileset dir="${external-libs-folder}" includes="*.jar"/>
182         <!-- yeah, want to not use this mechanism above -->
183         <pathelement path="../core/core.jar"/>
184         <pathelement path="${main-out-classes}"/>
185       </classpath>
186     </javac>
187
188     <unzip src="../core/core.jar" dest="${out-classes}" overwrite="true"/>
189
190     <antcall target="optimize"/>
191   </target>
192
193   <target name="optimize" unless="no-optimize">
194     <mkdir dir="optimized"/>
195     <property name="libraryjars.path" refid="android.target.classpath"/>
196     <java jar="${WTK-home}/bin/proguard.jar" fork="true" failonerror="true">
197       <jvmarg value="-Dmaximum.inlined.code.length=48"/>
198       <arg value="-injars ${out-classes}"/>
199       <arg value="-outjars optimized"/>
200       <arg value="-libraryjars ${libraryjars.path}"/>
201       <arg value="-keep class com.google.zxing.client.android.*Activity"/>
202       <arg value="-keep class com.google.zxing.client.android.ViewfinderView { public * ; }"/>
203       <arg value="-keep class com.google.zxing.client.android.book.SearchBookContents* { public * ; }"/>
204       <arg value="-target 5"/>
205       <arg value="-optimizationpasses 4"/>
206       <arg value="-dontshrink"/>
207       <arg value="-dontobfuscate"/>
208       <arg value="-dontskipnonpubliclibraryclasses"/>
209       <arg value="-verbose"/>
210       <arg value="-dump proguard-dump.txt"/>
211     </java>
212     <delete dir="${out-classes}"/>
213     <move file="optimized" tofile="${out-classes}"/>
214   </target>
215
216   <!-- Convert this project's .class files into .dex files. -->
217   <target name="dex" depends="compile">
218     <echo>Converting compiled files and external libraries into ${out-folder}/${dex-file}...</echo>
219     <apply executable="${dx}" failonerror="true" parallel="true">
220       <arg value="-JXmx256M"/>
221       <arg value="--dex" />
222       <arg value="--output=${intermediate-dex-location}" />
223       <arg path="${out-classes-location}" />
224       <fileset dir="${external-libs-folder}" includes="*.jar"/>
225     </apply>
226   </target>
227
228   <!-- Put the project's resources into the output package file
229   This actually can create multiple resource package in case
230   Some custom apk with specific configuration have been
231   declared in default.properties.
232   -->
233   <target name="package-resources">
234     <echo>Packaging resources</echo>
235     <aaptexec executable="${aapt}"
236               command="package"
237               manifest="AndroidManifest.xml"
238               resources="${resource-folder}"
239               assets="${asset-folder}"
240               androidjar="${android-jar}"
241               outfolder="${out-folder}"
242               basename="${ant.project.name}" />
243   </target>
244
245   <!--
246   Getting an error like this?
247
248    [apply] UNEXPECTED TOP-LEVEL EXCEPTION:
249    [apply] com.android.dx.cf.code.SimException: local variable type
250    mismatch: attempt to set or access a value of type int using a local
251    variable of type com.google.zxing.qrcode.decoder.Version. This is
252    symptomatic of .class transformation tools that ignore local variable
253    information.
254
255   Build core/ with the 'build-no-debug' target. It's a long story.
256   -->
257
258   <!-- Package the application and sign it with a debug key.
259   This is the default target when building. It is used for debug. -->
260   <target name="debug" depends="dex, package-resources">
261     <apkbuilder
262         outfolder="${out-folder}"
263         basename="${ant.project.name}"
264         signed="true"
265         verbose="false">
266       <file path="${intermediate-dex}" />
267       <sourcefolder path="${source-folder}" />
268       <jarfolder path="${external-libs-folder}" />
269       <nativefolder path="${native-libs-folder}" />
270     </apkbuilder>
271   </target>
272
273   <!-- Package the application without signing it.
274   This allows for the application to be signed later with an official publishing key. -->
275   <target name="release" depends="dex, package-resources">
276     <apkbuilder
277         outfolder="${out-folder}"
278         basename="${ant.project.name}"
279         signed="false"
280         verbose="false">
281       <file path="${intermediate-dex}" />
282       <sourcefolder path="${source-folder}" />
283       <jarfolder path="${external-libs-folder}" />
284       <nativefolder path="${native-libs-folder}" />
285     </apkbuilder>
286     <echo>All generated packages need to be signed with jarsigner before they are published.</echo>
287   </target>
288
289   <!-- Install the package on the default emulator -->
290   <target name="install" depends="debug">
291     <echo>Installing ${out-debug-package} onto default emulator...</echo>
292     <exec executable="${adb}" failonerror="true">
293       <arg value="install" />
294       <arg path="${out-debug-package}" />
295     </exec>
296   </target>
297
298   <target name="reinstall" depends="debug">
299     <echo>Installing ${out-debug-package} onto default emulator...</echo>
300     <exec executable="${adb}" failonerror="true">
301       <arg value="install" />
302       <arg value="-r" />
303       <arg path="${out-debug-package}" />
304     </exec>
305   </target>
306
307   <!-- Uinstall the package from the default emulator -->
308   <target name="uninstall">
309     <echo>Uninstalling ${application-package} from the default emulator...</echo>
310     <exec executable="${adb}" failonerror="true">
311       <arg value="uninstall" />
312       <arg value="${application-package}" />
313     </exec>
314   </target>
315
316   <target name="help">
317     <echo>Android Ant Build. Available targets:</echo>
318     <echo>   help:      Displays this help.</echo>
319     <echo>   debug:     Builds the application and sign it with a debug key.</echo>
320     <echo>   release:   Builds the application. The generated apk file must be</echo>
321     <echo>              signed before it is published.</echo>
322     <echo>   install:   Installs the debug package onto a running emulator or</echo>
323     <echo>              device. This can only be used if the application has </echo>
324     <echo>              not yet been installed.</echo>
325     <echo>   reinstall: Installs the debug package on a running emulator or</echo>
326     <echo>              device that already has the application.</echo>
327     <echo>              The signatures must match.</echo>
328     <echo>   uninstall: uninstall the application from a running emulator or</echo>
329     <echo>              device.</echo>
330   </target>
331
332   <target name="clean">
333     <delete dir="${out-folder}"/>
334     <delete dir="${gen-folder}"/>
335   </target>
336 </project>