forked from calabash/calabash-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
192 lines (163 loc) · 6.96 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
<?xml version="1.0" encoding="utf-8"?>
<project name="" default="test" basedir=".">
<description>
Bits and pieces 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"/>
<property name="calabashjs.dir" location="instrumentation_backend/calabash-js/src"/>
<!-- 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" />
<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" depends="package">
<exec executable="cucumber${bat}">
<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="-check.preconditions">
<available file="${tested.project.apk}" property="tested.apk.found" />
<fail unless="tested.apk.found" message="Tested apk: '${tested.project.apk}' could not be found"/>
<available file="${calabashjs.dir}" type="dir" property="doesCalabashJsExist" />
<fail unless="doesCalabashJsExist">
${calabashjs.dir} does not exist.
Try running:
git submodule init
git submodule update
</fail>
</target>
<target name="-init" depends="-check.preconditions">
<uptodate property="test.app.upto.date" targetfile="${test.app.signed}" >
<srcfiles dir= "instrumentation_backend/" includes="**/*"/>
<srcfiles file="build.properties"/>
</uptodate>
</target>
<target name="-stage">
<mkdir dir="${staging.dir}"/>
<mkdir dir="${bin.dir}"/>
<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>
<copy todir="${staging.dir}/assets">
<fileset dir="${calabashjs.dir}"/>
</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">
<antcall target="-stage" />
<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="-init" unless="test.app.upto.date">
<antcall target="-compile" />
<antcall target="-aapt" />
<antcall target="-dex" />
<antcall target="-apk" />
<antcall target="-sign" />
</target>
<target name="clean" description="clean up">
<delete dir="${staging.dir}"/>
<delete dir="${bin.dir}"/>
</target>
<target name="-aapt">
<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">
<antcall target="-stage.libs"/>
<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">
<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">
<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>