ed41d61e967b510b3f28530ac3ccbb0e9ea8f646
[zxing.git] / androidtest / 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="ZXingTest" 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         <pathelement path="${main-out-classes}"/>
183       </classpath>
184     </javac>
185   </target>
186
187   <!-- Convert this project's .class files into .dex files. -->
188   <target name="dex" depends="compile">
189     <echo>Converting compiled files and external libraries into ${out-folder}/${dex-file}...</echo>
190     <apply executable="${dx}" failonerror="true" parallel="true">
191       <arg value="-JXmx256M"/>
192       <arg value="--dex" />
193       <arg value="--output=${intermediate-dex-location}" />
194       <arg path="${out-classes-location}" />
195       <fileset dir="${external-libs-folder}" includes="*.jar"/>
196     </apply>
197   </target>
198
199   <!-- Put the project's resources into the output package file
200   This actually can create multiple resource package in case
201   Some custom apk with specific configuration have been
202   declared in default.properties.
203   -->
204   <target name="package-resources">
205     <echo>Packaging resources</echo>
206     <aaptexec executable="${aapt}"
207               command="package"
208               manifest="AndroidManifest.xml"
209               resources="${resource-folder}"
210               assets="${asset-folder}"
211               androidjar="${android-jar}"
212               outfolder="${out-folder}"
213               basename="${ant.project.name}" />
214   </target>
215
216   <!-- Package the application and sign it with a debug key.
217   This is the default target when building. It is used for debug. -->
218   <target name="debug" depends="dex, package-resources">
219     <apkbuilder
220         outfolder="${out-folder}"
221         basename="${ant.project.name}"
222         signed="true"
223         verbose="false">
224       <file path="${intermediate-dex}" />
225       <sourcefolder path="${source-folder}" />
226       <jarfolder path="${external-libs-folder}" />
227       <nativefolder path="${native-libs-folder}" />
228     </apkbuilder>
229   </target>
230
231   <!-- Package the application without signing it.
232   This allows for the application to be signed later with an official publishing key. -->
233   <target name="release" depends="dex, package-resources">
234     <apkbuilder
235         outfolder="${out-folder}"
236         basename="${ant.project.name}"
237         signed="false"
238         verbose="false">
239       <file path="${intermediate-dex}" />
240       <sourcefolder path="${source-folder}" />
241       <jarfolder path="${external-libs-folder}" />
242       <nativefolder path="${native-libs-folder}" />
243     </apkbuilder>
244     <echo>All generated packages need to be signed with jarsigner before they are published.</echo>
245   </target>
246
247   <!-- Install the package on the default emulator -->
248   <target name="install" depends="debug">
249     <echo>Installing ${out-debug-package} onto default emulator...</echo>
250     <exec executable="${adb}" failonerror="true">
251       <arg value="install" />
252       <arg path="${out-debug-package}" />
253     </exec>
254   </target>
255
256   <target name="reinstall" depends="debug">
257     <echo>Installing ${out-debug-package} onto default emulator...</echo>
258     <exec executable="${adb}" failonerror="true">
259       <arg value="install" />
260       <arg value="-r" />
261       <arg path="${out-debug-package}" />
262     </exec>
263   </target>
264
265   <!-- Uinstall the package from the default emulator -->
266   <target name="uninstall">
267     <echo>Uninstalling ${application-package} from the default emulator...</echo>
268     <exec executable="${adb}" failonerror="true">
269       <arg value="uninstall" />
270       <arg value="${application-package}" />
271     </exec>
272   </target>
273
274   <target name="help">
275     <echo>Android Ant Build. Available targets:</echo>
276     <echo>   help:      Displays this help.</echo>
277     <echo>   debug:     Builds the application and sign it with a debug key.</echo>
278     <echo>   release:   Builds the application. The generated apk file must be</echo>
279     <echo>              signed before it is published.</echo>
280     <echo>   install:   Installs the debug package onto a running emulator or</echo>
281     <echo>              device. This can only be used if the application has </echo>
282     <echo>              not yet been installed.</echo>
283     <echo>   reinstall: Installs the debug package on a running emulator or</echo>
284     <echo>              device that already has the application.</echo>
285     <echo>              The signatures must match.</echo>
286     <echo>   uninstall: uninstall the application from a running emulator or</echo>
287     <echo>              device.</echo>
288   </target>
289
290   <target name="clean">
291     <delete dir="${out-folder}"/>
292     <delete dir="${gen-folder}"/>
293   </target>
294 </project>