aboutsummaryrefslogtreecommitdiffstats
path: root/build.xml
blob: 00f81fd700239c89aa68f970b338e45e6e171b45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<?xml version="1.0" encoding="UTF-8"?>
<project name="ConnectBot" default="help">

    <!-- The local.properties file is created and updated by the 'android' tool.
         It contain the path to the SDK. It should *NOT* be checked in in Version
         Control Systems. -->
    <property file="local.properties"/>

    <!-- The build.properties file can be created by you and is never touched
         by the 'android' tool. This is the place to change some of the default property values
         used by the Ant rules.
         Here are some properties you may want to change/update:

         application-package
             the name of your application package as defined in the manifest. Used by the
             'uninstall' rule.
         source-folder
             the name of the source folder. Default is 'src'.
         out-folder
             the name of the output folder. Default is 'bin'.

         Properties related to the SDK location or the project target should be updated
          using the 'android' tool with the 'update' action.

         This file is an integral part of the build system for your application and
         should be checked in in Version Control Systems.

         -->
    <property file="build.properties"/>

    <!-- The default.properties file is created and updated by the 'android' tool, as well
         as ADT.
         This file is an integral part of the build system for your application and
         should be checked in in Version Control Systems. -->
    <property file="default.properties"/>

    <!-- Custom Android task to deal with the project target, and import the proper rules.
         This requires ant 1.6.0 or above. -->
    <path id="android.antlibs">
        <pathelement path="${sdk-location}/tools/lib/anttasks.jar" />
        <pathelement path="${sdk-location}/tools/lib/sdklib.jar" />
        <pathelement path="${sdk-location}/tools/lib/androidprefs.jar" />
        <pathelement path="${sdk-location}/tools/lib/apkbuilder.jar" />
        <pathelement path="${sdk-location}/tools/lib/jarutils.jar" />
    </path>

    <taskdef name="setup"
        classname="com.android.ant.SetupTask"
        classpathref="android.antlibs"/>

    <!-- Execute the Android Setup task that will setup some properties specific to the target,
         and import the rules files.
         To customize the rules, copy/paste them below the task, and disable import by setting
         the import attribute to false:
            <setup import="false" />

         This will ensure that the properties are setup correctly but that your customized
         targets are used.
    -->
    <setup import="false" />

    <!-- Custom tasks -->
    <taskdef name="aaptexec"
        classname="com.android.ant.AaptExecLoopTask"
        classpathref="android.antlibs"/>

    <taskdef name="apkbuilder"
        classname="com.android.ant.ApkBuilderTask"
        classpathref="android.antlibs"/>

    <!-- Properties -->

    <property name="android-tools" value="${sdk-location}/tools" />

    <!-- Input directories -->
    <property name="source-folder" value="src" />
    <property name="gen-folder" value="gen" />
    <property name="resource-folder" value="res" />
    <property name="asset-folder" value="assets" />
    <property name="source-location" value="${basedir}/${source-folder}" />

    <!-- folder for the 3rd party java libraries -->
    <property name="external-libs-folder" value="libs" />

    <!-- folder for the native libraries -->
    <property name="native-libs-folder" value="libs" />

    <!-- Output directories -->
    <property name="gen-folder" value="gen" />
    <property name="out-folder" value="bin" />
    <property name="out-classes" value="${out-folder}/classes" />
    <property name="out-classes-location" value="${basedir}/${out-classes}"/>
    <!-- out folders for a parent project if this project is an instrumentation project -->
    <property name="main-out-folder" value="../${out-folder}" />
    <property name="main-out-classes" value="${main-out-folder}/classes"/>

    <!-- Intermediate files -->
    <property name="dex-file" value="classes.dex" />
    <property name="intermediate-dex" value="${out-folder}/${dex-file}" />
    <!-- dx does not properly support incorrect / or \ based on the platform
         and Ant cannot convert them because the parameter is not a valid path.
         Because of this we have to compute different paths depending on the platform. -->
    <condition property="intermediate-dex-location"
            value="${basedir}\${intermediate-dex}"
            else="${basedir}/${intermediate-dex}" >
        <os family="windows"/>
    </condition>

    <!-- The final package file to generate -->
    <property name="out-debug-package" value="${out-folder}/${ant.project.name}-debug.apk"/>

    <!-- Tools -->
    <condition property="exe" value=".exe" else=""><os family="windows"/></condition>
    <property name="adb" value="${android-tools}/adb${exe}"/>

    <!-- rules -->

    <!-- Create the output directories if they don't exist yet. -->
    <target name="dirs">
        <echo>Creating output directories if needed...</echo>
        <mkdir dir="${resource-folder}" />
        <mkdir dir="${external-libs-folder}" />
        <mkdir dir="${gen-folder}" />
        <mkdir dir="${out-folder}" />
        <mkdir dir="${out-classes}" />
    </target>

    <!-- Generate the R.java file for this project's resources. -->
    <target name="resource-src" depends="dirs, update-version">
        <echo>Generating R.java / Manifest.java from the resources...</echo>
        <exec executable="${aapt}" failonerror="true">
            <arg value="package" />
            <arg value="-m" />
            <arg value="-J" />
            <arg path="${gen-folder}" />
            <arg value="-M" />
            <arg path="AndroidManifest.xml" />
            <arg value="-S" />
            <arg path="${resource-folder}" />
            <arg value="-I" />
            <arg path="${android-jar}" />
        </exec>
    </target>

    <!-- Generate java classes from .aidl files. -->
    <target name="aidl" depends="dirs">
        <echo>Compiling aidl files into Java classes...</echo>
        <apply executable="${aidl}" failonerror="true">
            <arg value="-p${android-aidl}" />
            <arg value="-I${source-folder}" />
            <arg value="-o${gen-folder}" />
            <fileset dir="${source-folder}">
                <include name="**/*.aidl"/>
            </fileset>
        </apply>
    </target>

    <!-- Compile this project's .java files into .class files. -->
    <target name="compile" depends="resource-src, aidl">
        <javac encoding="utf8" target="1.5" debug="true" extdirs=""
                destdir="${out-classes}"
                bootclasspathref="android.target.classpath">
            <src path="${source-folder}" />
            <src path="${gen-folder}" />
            <classpath>
                <fileset dir="${external-libs-folder}" includes="*.jar"/>
                <pathelement path="${main-out-classes}"/>
            </classpath>
         </javac>
    </target>

    <!-- Convert this project's .class files into .dex files. -->
    <target name="dex" depends="compile">
        <echo>Converting compiled files and external libraries into ${out-folder}/${dex-file}...</echo>
        <apply executable="${dx}" failonerror="true" parallel="true">
            <arg value="--dex" />
            <arg value="--output=${intermediate-dex-location}" />
            <arg path="${out-classes-location}" />
            <fileset dir="${external-libs-folder}" includes="*.jar"/>
        </apply>
    </target>

    <!-- Put the project's resources into the output package file
         This actually can create multiple resource package in case
         Some custom apk with specific configuration have been
         declared in default.properties.
         -->
    <target name="package-resources">
        <echo>Packaging resources</echo>
        <aaptexec executable="${aapt}"
                command="package"
                manifest="AndroidManifest.xml"
                resources="${resource-folder}"
                assets="${asset-folder}"
                androidjar="${android-jar}"
                outfolder="${out-folder}"
                basename="${ant.project.name}" />
    </target>

    <!-- Package the application and sign it with a debug key.
         This is the default target when building. It is used for debug. -->
    <target name="debug" depends="dex, package-resources">
        <apkbuilder
                outfolder="${out-folder}"
                basename="${ant.project.name}"
                signed="true"
                verbose="false">
            <file path="${intermediate-dex}" />
            <sourcefolder path="${source-folder}" />
            <jarfolder path="${external-libs-folder}" />
            <nativefolder path="${native-libs-folder}" />
        </apkbuilder>
    </target>

    <!-- Package the application without signing it.
         This allows for the application to be signed later with an official publishing key. -->
    <target name="release" depends="dex, package-resources">
        <apkbuilder
                outfolder="${out-folder}"
                basename="${ant.project.name}"
                signed="false"
                verbose="false">
            <file path="${intermediate-dex}" />
            <sourcefolder path="${source-folder}" />
            <jarfolder path="${external-libs-folder}" />
            <nativefolder path="${native-libs-folder}" />
        </apkbuilder>
        <echo>All generated packages need to be signed with jarsigner before they are published.</echo>
    </target>

    <!-- Install the package on the default emulator -->
    <target name="install" depends="debug">
        <echo>Installing ${out-debug-package} onto default emulator...</echo>
        <exec executable="${adb}" failonerror="true">
            <arg value="install" />
            <arg path="${out-debug-package}" />
        </exec>
    </target>

    <target name="reinstall" depends="debug">
        <echo>Installing ${out-debug-package} onto default emulator...</echo>
        <exec executable="${adb}" failonerror="true">
            <arg value="install" />
            <arg value="-r" />
            <arg path="${out-debug-package}" />
        </exec>
    </target>

    <!-- Uinstall the package from the default emulator -->
    <target name="uninstall">
        <echo>Uninstalling ${application-package} from the default emulator...</echo>
        <exec executable="${adb}" failonerror="true">
            <arg value="uninstall" />
            <arg path="${application-package}" />
        </exec>
    </target>

    <target name="help">
        <!-- displays starts at col 13
              |13                                                              80| -->
        <echo>Android Ant Build. Available targets:</echo>
        <echo>   help:      Displays this help.</echo>
        <echo>   debug:     Builds the application and sign it with a debug key.</echo>
        <echo>   release:   Builds the application. The generated apk file must be</echo>
        <echo>              signed before it is published.</echo>
        <echo>   install:   Installs the debug package onto a running emulator or</echo>
        <echo>              device. This can only be used if the application has </echo>
        <echo>              not yet been installed.</echo>
        <echo>   reinstall: Installs the debug package on a running emulator or</echo>
        <echo>              device that already has the application.</echo>
        <echo>              The signatures must match.</echo>
        <echo>   uninstall: uninstall the application from a running emulator or</echo>
        <echo>              device.</echo>
    </target>

    <target name="update-version" description="Updates the Version.java file with current SVN revision">
        <echo>Updating strings.xml with SVN revision and build date...</echo>
        <property name="revision" value="HEAD"/>
        <tstamp>
            <format property="build.date" pattern="yyyy.MM.dd" />
        </tstamp>

        <!-- Get the version name from the android manifest, will en up in property ${manifest.android:versionName} -->
        <xmlproperty file="${basedir}/AndroidManifest.xml" collapseAttributes="true"/>

        <!-- find out svn.revision of HEAD, need svn.exe installed on local machine will en up in property ${Revision} -->
        <exec executable="svn" output="svnlog.out">
            <arg line="info -r ${revision}"/>
        </exec>

        <loadproperties srcFile="svnlog.out">
            <filterchain>
                <linecontains>
                    <contains value="Revision"/>
                </linecontains>
            </filterchain>
        </loadproperties>

        <delete file="svnlog.out"/>

        <replaceregexp file="${resource-folder}/values/strings.xml" encoding="utf8" match='(\x3Cstring name="msg_version">)[^\x3C]*(\x3C/string>)'
            replace='\1${ant.project.name} ${manifest.android:versionName} (r${Revision} ${build.date})\2' />

        <echo>Updated "msg_version" to: ${ant.project.name} ${manifest.android:versionName} (r${Revision} ${build.date})</echo>
    </target>

    <target name="clean"
        description="Clean up the result of the build process">
        <delete dir="${out-folder}"/>
        <delete dir="${gen-folder}"/>
        <exec executable="ant" failonerror="true">
            <arg value="-f" />
            <arg value="tests/build.xml" />
            <arg value="clean"/>
        </exec>
    </target>

    <target name="tests" depends="reinstall">
        <echo>Building and installing tests...</echo>
        <exec executable="ant" failonerror="true">
            <arg value="-f" />
            <arg value="tests/build.xml" />
            <arg value="reinstall"/>
        </exec>
        <echo>Running test cases...</echo>
        <exec executable="${adb}">
            <arg value="shell" />
            <arg value="am" />
            <arg value="instrument" />
            <arg value="-w" />
            <arg value="${application-package}.tests/android.test.InstrumentationTestRunner" />
            <redirector outputproperty="test.results"/>
        </exec>
        <fail message="Some unit tests failed:${line.separator}${test.results}">
            <condition>
                <contains string="${test.results}" substring="FAILURES"/>
            </condition>
        </fail>
    </target>
</project>