-
Notifications
You must be signed in to change notification settings - Fork 2
/
android_rules.xml
285 lines (253 loc) · 10.8 KB
/
android_rules.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
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
<?xml version="1.0" encoding="UTF-8"?>
<project name="android_rules" default="debug">
<!--
This rules file is meant to be imported by the custom Ant task:
com.android.ant.AndroidInitTask
The following properties are put in place by the importing task:
android-jar, android-aidl, aapt, aidl, and dx
Additionnaly, the task sets up the following classpath reference:
android.target.classpath
This is used by the compiler task as the boot classpath.
-->
<!-- 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}" />
<property name="scala.home" value="/usr/local/scala-2.7.5.final/" />
<property name="scala-android.jar" value="${scala.home}/lib/scala-android.jar" />
<property name="scala-library.jar" value="${scala.home}/lib/scala-library.jar" />
<!-- create scala ant tasks -->
<taskdef resource="scala/tools/ant/antlib.xml">
<classpath>
<pathelement location="${scala.home}/lib/scala-compiler.jar" />
<pathelement location="${scala-library.jar}" />
</classpath>
</taskdef>
<property name="proguard.out.jar" value="${out-folder}/classes.opt.jar" />
<path id="proguard.classpath">
<pathelement location="/usr/share/java/ant-proguard.jar" />
<pathelement location="/usr/share/java/proguard.jar" />
</path>
<!-- create proguard taks -->
<taskdef resource="proguard/ant/task.properties">
<classpath>
<path refid="proguard.classpath" />
</classpath>
</taskdef>
<!-- rules -->
<target name="clean">
<delete quiet="true" verbose="false">
<fileset dir="${out-classes}" />
<fileset dir="${gen-folder}" />
</delete>
</target>
<!-- 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">
<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="ascii" 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>
<!-- build scala files -->
<scalac
encoding="ascii"
target="jvm-1.5"
addparams="-g:vars"
srcdir="${source-folder}"
extdirs=""
destdir="${out-classes}"
bootclasspathref="android.target.classpath">
<include name="**/*.scala" />
<classpath>
<fileset dir="${external-libs-folder}" includes="*.jar" />
<pathelement path="${main-out-classes}" />
<pathelement path="${scala-android.jar}" />
<pathelement path="${scala-library.jar}" />
</classpath>
</scalac>
</target>
<!-- Convert this project's .class files into .dex files. -->
<target name="dex" depends="proguard">
<echo>Converting compiled files and external libraries into ${out-folder}/${dex-file}...</echo>
<apply executable="${dx}" failonerror="true" parallel="true">
<arg value="-JXmx512M" />
<arg value="--dex" />
<arg value="--output=${intermediate-dex-location}" />
<!--
<arg path="${out-classes-location}" />
<fileset file="${scala-android.jar}"/>
-->
<fileset file="${proguard.out.jar}" />
<fileset dir="${external-libs-folder}" includes="*.jar" />
</apply>
</target>
<!-- optimize using proguard -->
<target name="proguard" depends="compile">
<proguard warn="false" optimize="false" obfuscate="false">
<!--
-injars ${out-classes-location}:${external-libs-folder}/*.jar:${scala-android.jar}(!META-INF/MANIFEST.MF,!library.properties):${scala-library.jar}(!META-INF/MANIFEST.MF,!library.properties)
-outjars ${proguard.out.jar}
-->
<injar>
<pathelement location="${out-classes-location}" />
</injar>
<injar filter="!META-INF/MANIFEST.MF,!*.properties">
<pathelement location="${scala-library.jar}" />
</injar>
<injar>
<fileset dir="${external-libs-folder}" includes="*.jar" />
</injar>
<outjar>
<pathelement location="${proguard.out.jar}" />
</outjar>
-libraryjars ${android-jar}
-keep public class * extends android.app.Activity
</proguard>
</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>
</project>