aboutsummaryrefslogtreecommitdiff
path: root/files/ant/uibuild.xml
blob: 788ca7774ebdaec2f6c08993e6925b408c42f4c1 (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
<?xml version="1.0" encoding="UTF-8"?>
<project name="android_rules" default="debug">

    <!--
        This build file is imported by the project build file. It contains
        all the targets and tasks necessary to build Android projects, be they
        regular projects, library projects, or test projects.

        At the beginning of the file is a list of properties that can be overridden
        by adding them to your ant.properties (properties are immutable, so their
        first definition sticks and is never changed).

        Follows:
        - custom task definitions,
        - more properties (do not override those unless the whole build system is modified).
        - macros used throughout the build,
        - base build targets,
        - debug-specific build targets,
        - release-specific build targets,
        - instrument-specific build targets,
        - test project-specific build targets,
        - install targets,
        - help target
    -->

    <!-- ******************************************************* -->
    <!-- **************** Overridable Properties *************** -->
    <!-- ******************************************************* -->

    <!-- You can override these values in your build.xml or ant.properties.
         Overriding any other properties may result in broken build. -->

    <!-- Tells adb which device to target. You can change this from the command line
         by invoking "ant -Dadb.device.arg=-d" for device "ant -Dadb.device.arg=-e" for
         the emulator. -->
    <property name="adb.device.arg" value="" />

    <!-- filename only of the output file. Cannot be a path -->
    <property name="out.filename" value="${ant.project.name}.jar" />

    <!-- compilation options -->
    <property name="java.encoding" value="UTF-8" />
    <property name="java.target" value="1.5" />
    <property name="java.source" value="1.5" />
    <property name="java.compilerargs" value="" />

    <!-- Verbosity -->
    <property name="verbose" value="false" />

    <!-- ******************************************************* -->
    <!-- ********************* Custom Tasks ******************** -->
    <!-- ******************************************************* -->

    <!-- jar file from where the tasks are loaded -->
    <path id="android.antlibs">
        <pathelement path="${sdk.dir}/tools/lib/ant-tasks.jar" />
    </path>

    <!-- Custom tasks -->
    <taskdef resource="anttasks.properties" classpathref="android.antlibs" />

    <!-- Emma configuration -->
    <property name="emma.dir" value="${sdk.dir}/tools/lib" />
    <path id="emma.lib">
        <pathelement location="${emma.dir}/emma.jar" />
        <pathelement location="${emma.dir}/emma_ant.jar" />
    </path>
    <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
    <!-- End of emma configuration -->


    <!-- ******************************************************* -->
    <!-- ******************* Other Properties ****************** -->
    <!-- ******************************************************* -->
    <!-- overriding these properties may break the build
         unless the whole file is updated -->

    <!-- Input directories -->
    <property name="source.dir" value="src" />
    <property name="source.absolute.dir" location="${source.dir}" />
    <property name="jar.libs.dir" value="libs" />
    <property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />

    <!-- Output directories -->
    <property name="out.dir" value="bin" />
    <property name="out.absolute.dir" location="${out.dir}" />
    <property name="out.classes.absolute.dir" location="${out.dir}/classes" />

    <property name="out.file" value="${out.absolute.dir}/${out.filename}" />

    <!-- tools location -->
    <property name="android.tools.dir" location="${sdk.dir}/tools" />
    <property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" />
    <condition property="exe" value=".exe" else=""><os family="windows" /></condition>
    <condition property="bat" value=".bat" else=""><os family="windows" /></condition>
    <property name="adb" location="${android.platform.tools.dir}/adb${exe}" />

    <!-- Intermediate files -->
    <property name="dex.file.name" value="classes.dex" />
    <property name="intermediate.dex.file" location="${out.absolute.dir}/${dex.file.name}" />
    <property name="resource.package.file.name" value="${ant.project.name}.ap_" />

    <!-- whether we need to fork javac.
         This is only needed on Windows when running Java < 7 -->
    <condition else="false" property="need.javac.fork">
        <and>
            <matches pattern="1\.[56]" string="${java.specification.version}"/>
            <not>
                <os family="unix"/>
            </not>
        </and>
    </condition>

    <macrodef name="run-tests-helper">
        <attribute name="emma.enabled" default="false" />
        <element name="extra-instrument-args" optional="yes" />
        <sequential>
            <echo level="info">Running tests ...</echo>
            <exec executable="${adb}" failonerror="true">
                <arg line="${adb.device.arg}" />
                <arg value="shell" />
                <arg value="am" />
                <arg value="instrument" />
                <arg value="-w" />
                <arg value="-e" />
                <arg value="coverage" />
                <arg value="@{emma.enabled}" />
                <extra-instrument-args />
                <arg value="${project.app.package}/${test.runner}" />
            </exec>
        </sequential>
    </macrodef>

    <!-- ******************************************************* -->
    <!-- ******************** Build Targets ******************** -->
    <!-- ******************************************************* -->

    <!-- Basic Ant + SDK check -->
    <target name="-check-env">
        <checkenv />
    </target>

    <!-- empty default pre-clean target. Create a similar target in
         your build.xml and it'll be called instead of this one. -->
    <target name="-pre-clean"/>

    <!-- clean target -->
    <target name="clean" depends="-check-env, -pre-clean"
            description="Removes output files created by other targets.">
        <delete dir="${out.absolute.dir}" verbose="${verbose}" />
    </target>

    <!-- Pre build setup -->
    <target name="-build-setup" depends="-check-env">
        <getbuildtools name="android.build.tools.dir" />
        <property name="dx" location="${android.build.tools.dir}/dx${bat}" />

        <echo level="info">Resolving Build Target for ${ant.project.name}...</echo>
        <!-- load project properties, resolve Android target, library dependencies
             and set some properties with the results.
             All property names are passed as parameters ending in -Out -->
        <getuitarget compileClassPathOut="project.target.class.path" />

        <echo level="info">----------</echo>
        <echo level="info">Creating output directories if needed...</echo>
        <mkdir dir="${out.absolute.dir}" />
        <mkdir dir="${out.classes.absolute.dir}" />

    </target>

    <!-- empty default pre-compile target. Create a similar target in
         your build.xml and it'll be called instead of this one. -->
    <target name="-pre-compile"/>

    <!-- Compiles this project's .java files into .class files. -->
    <target name="compile" depends="-build-setup, -pre-compile">
        <javac encoding="${java.encoding}"
                source="${java.source}" target="${java.target}"
                debug="true" extdirs="" includeantruntime="false"
                destdir="${out.classes.absolute.dir}"
                bootclasspathref="project.target.class.path"
                verbose="${verbose}"
                fork="${need.javac.fork}">
            <src path="${source.absolute.dir}" />
            <compilerarg line="${java.compilerargs}" />
        </javac>
    </target>

    <!-- empty default post-compile target. Create a similar target in
         your build.xml and it'll be called instead of this one. -->
    <target name="-post-compile"/>

    <!-- Converts this project's .class files into .dex files -->
    <target name="-dex" depends="compile, -post-compile">
        <dex executable="${dx}"
                output="${intermediate.dex.file}"
                nolocals="@{nolocals}"
                verbose="${verbose}">
            <path path="${out.classes.absolute.dir}"/>
        </dex>
    </target>

    <!-- empty default post-dex target. Create a similar target in
         your build.xml and it'll be called instead of this one. -->
    <target name="-post-dex"/>

    <target name="-jar" depends="-dex, -post-dex" >
        <jar destfile="${out.file}">
            <fileset file="${intermediate.dex.file}" />
        </jar>
    </target>

    <!-- empty default post-jar target. Create a similar target in
         your build.xml and it'll be called instead of this one. -->
    <target name="-post-jar"/>

    <target name="build" depends="-jar, -post-jar" />

    <target name="install" description="Install the test package">
         <exec executable="${adb}" failonerror="true">
            <arg line="${adb.device.arg}" />
            <arg value="push" />
            <arg value="${out.file}" />
            <arg value="/data/local/tmp" />
        </exec>
    </target>

    <target name="test" description="Runs tests">
        <!-- todo: fix this -->
        <fail message="Launching tests from Ant not supported yet" />

         <exec executable="${adb}" failonerror="true">
            <arg line="${adb.device.arg}" />
            <arg value="shell" />
            <arg value="uiautomator" />
            <arg value="runtest" />
            <arg value="${out.filename}" />
            <arg value="-e" />
            <arg value="class" />
            <arg value="com.android.uiautomator.samples.skeleton.DemoTestCase" />
        </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>   clean:     Removes output files created by other targets.</echo>
        <echo>   build:     Builds the test library.</echo>
        <echo>   install:   Installs the library on a connected device or</echo>
        <echo>              emulator.</echo>
        <echo>   test:      Runs the tests.</echo>
        <echo></echo>
        <echo>It is possible to mix targets. For instance:</echo>
        <echo>   ant build install test</echo>
        <echo>This will build, install and run the test in a single command.</echo>
    </target>

</project>