forked from calabash/calabash-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
196 lines (163 loc) · 7.2 KB
/
build.xml
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
<?xml version="1.0" encoding="utf-8"?>
<project name="" default="test" basedir=".">
<description>
Bits and pices plucked out of $ANDROID_HOME/tools/ant/build.xml
</description>
<property name="adb.device.arg" value="" />
<property environment="env"/>
<property file="build.properties"/>
<property name="staging.dir" location="staging"/>
<property name="bin.dir" location="bin"/>
<property name="test.app" location="${bin.dir}/Test.apk"/>
<property name="test.app.aapt" location="${bin.dir}/Test_aapt.apk"/>
<property name="dex.file" location="${bin.dir}/classes.dex"/>
<property name="test.app.unsigned" location="${bin.dir}/Test_unsigned.apk"/>
<property name="test.app.signed" location="${bin.dir}/Test.apk"/>
<!-- Windows support -->
<condition property="bat" value=".bat" else=""><os family="windows" /></condition>
<property name="dx" location="${env.ANDROID_HOME}/platform-tools/dx${bat}" />
<property name="apkbuilder" location="${env.ANDROID_HOME}/tools/apkbuilder${bat}" />
<property name="android.lib" location="${env.ANDROID_HOME}/platforms/android-4/android.jar"/>
<path id="android.antlibs">
<pathelement path="${env.ANDROID_HOME}/tools/lib/anttasks.jar" />
</path>
<taskdef name="xpath" classname="com.android.ant.XPathTask" classpathref="android.antlibs"/>
<taskdef name="aapt" classname="com.android.ant.AaptExecTask" classpathref="android.antlibs" />
<taskdef name="apkbuilder" classname="com.android.ant.ApkBuilderTask" classpathref="android.antlibs" />
<uptodate property="test.app.upto.date" targetfile="${test.app.signed}" >
<srcfiles dir= "instrumentation_backend/" includes="**/*"/>
<srcfiles file="build.properties/"/>
</uptodate>
<path id="jar.libs.ref">
<fileset dir="${staging.dir}/libs/" includes="*.jar" />
</path>
<path id="cucumber.path">
<fileset dir="cucumber/" includes="*.jar" />
</path>
<path id="android.target.classpath">
<fileset dir="${env.ANDROID_HOME}/platforms/android-8/" includes="*.jar"/>
</path>
<target name="test" description="Run test features">
<exec executable="cucumber">
<env key="PACKAGE_NAME" value="${tested.package_name}" />
<env key="TEST_PACKAGE_NAME" value="${tested.package_name}.test" />
<env key="APP_PATH" value="${tested.project.apk}" />
<env key="TEST_APP_PATH" value="bin/Test.apk" />
<env key="TEST_SERVER_PORT" value="34777" />
<env key="ADB_DEVICE_ARG" value="${adb.device.arg}" />
<arg value="features" />
</exec>
</target>
<target name="-init" unless="test.app.upto.date">
<mkdir dir="${staging.dir}"/>
<mkdir dir="${bin.dir}"/>
</target>
<target name="stage" unless="test.app.upto.date">
<antcall target="clean"/>
<antcall target="-init"/>
<antcall target="-prepare.manifest"/>
<antcall target="-prepare.testserver"/>
</target>
<target name="-prepare.manifest" description="Makes sure the manifest matches the tested application by looking at its manifest file">
<copy file="AndroidManifest.xml" todir="${staging.dir}"/>
<replace file="${staging.dir}/AndroidManifest.xml" token="#TESTED_APP_PACKAGE#" value="${tested.package_name}"/>
</target>
<target name="-prepare.testserver" description="Makes sure the testserver matches the tested application by looking at its manifest file">
<copy todir="${staging.dir}">
<fileset dir="instrumentation_backend"/>
</copy>
<replace file="${staging.dir}/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java" token="#ACTIVITY_PACKAGE#" value="${tested.package_name}"/>
<replace file="${staging.dir}/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java" token="#ACTIVITY_QUALIFIED_NAME#" value="${tested.main_activity}"/>
<exec executable="${env.ANDROID_HOME}/platform-tools/aapt" failonerror="true" output="${staging.dir}/assets/ids.txt">
<arg value="dump" />
<arg value="resources" />
<arg file="${tested.project.apk}" />
</exec>
</target>
<target name="compile" depends="stage" unless="test.app.upto.date">
<javac
srcdir="${staging.dir}/src"
destdir="${bin.dir}"
verbose="${verbose}"
bootclasspathref="android.target.classpath"
classpath="${extensible.classpath}"
classpathref="jar.libs.ref">
</javac>
</target>
<target name="package" depends="compile, -aapt, -dex, -apk, -sign" unless="test.app.upto.date">
</target>
<target name="install.test" description="Install the test server">
<antcall target="package"/>
<echo message="Installing test"/>
<antcall target="-install.helper">
<param name="apk.to.install" value="${test.app}"/>
</antcall>
</target>
<target name="install.app" description="Install the app under test">
<antcall target="-install.helper">
<param name="apk.to.install" value="${tested.project.apk}"/>
</antcall>
</target>
<target name="clean" description="clean up">
<delete dir="${staging.dir}"/>
<delete dir="${bin.dir}"/>
</target>
<target name="-install.helper" description="Helper to install apk file">
<!-- Make sure path to apk is absolute -->
<property name="apk.full.path" location="${apk.to.install}"/>
<echo message="Installing:${apk.to.install}"/>
<exec executable="${env.ANDROID_HOME}/platform-tools/adb" failonerror="true">
<arg line="${adb.device.arg} install -r ${apk.full.path}" />
</exec>
</target>
<target name="-aapt" unless="test.app.upto.date">
<exec executable="${env.ANDROID_HOME}/platform-tools/aapt" failonerror="yes">
<arg value="package" />
<arg value="-f" />
<arg value="-M" />
<arg file="${staging.dir}/AndroidManifest.xml" />
<arg value="-F" />
<arg file="${test.app.aapt}" />
<arg value="-I" />
<arg path="${android.lib}" />
<arg value="-A" />
<arg path="${staging.dir}/assets" />
<arg value="-m" />
<arg value="-J" />
<arg path="gen" />
</exec>
</target>
<target name="-dex" depends ="-stage.libs" unless="test.app.upto.date">
<exec executable="${dx}" failonerror="yes">
<arg value="--dex" />
<arg value="--output" />
<arg file="${dex.file}" />
<arg path="${bin.dir}" />
</exec>
</target>
<target name="-stage.libs">
<copy todir="${bin.dir}/libs">
<fileset dir="instrumentation_backend/libs"/>
</copy>
</target>
<target name="-apk" unless="test.app.upto.date">
<exec executable="${apkbuilder}" failonerror="yes">
<arg file="${test.app.unsigned}" />
<arg value="-u" />
<arg value="-z" />
<arg file="${test.app.aapt}" />
<arg value="-f" />
<arg file="${dex.file}" />
</exec>
</target>
<target name ="-sign" unless="test.app.upto.date">
<signjar
jar="${test.app.unsigned}"
signedjar="${test.app.signed}"
keystore="${key.store}"
storepass="${key.store.password}"
alias="${key.alias}"
keypass="${key.alias.password}"
verbose="false"/>
</target>
</project>