|
@ -0,0 +1,312 @@
|
|
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
<project name="apkTargets" default="apkpackaging" basedir=".">
|
|
3
|
<!-- 指定配置文件 -->
|
|
4
|
<property file="build.properties" />
|
|
5
|
<record name="${log_file}" loglevel="info" append="no" action="start" />
|
|
6
|
<!-- 识别编译环境 -->
|
|
7
|
<condition property="exe" value=".exe" else=""><os family="windows" /></condition>
|
|
8
|
<condition property="bat" value=".bat" else=""><os family="windows" /></condition>
|
|
9
|
<!-- Android SDK Tools -->
|
|
10
|
|
|
11
|
<property name="zipalign" value="${android_tools}/zipalign${exe}" />
|
|
12
|
<property name="jarsigner" value="${jdk_home}/bin/jarsigner${exe}" />
|
|
13
|
|
|
14
|
<property name="android-target-dir" value="${android_sdk_home}/platforms/${android-target}" />
|
|
15
|
<property name="android-jar" value="${android-target-dir}/android.jar" />
|
|
16
|
<property name="android-framework" value="${android-target-dir}/framework.aidl" />
|
|
17
|
<property name="aapt" value="${android_tools}/aapt${exe}" />
|
|
18
|
<property name="dx" value="${android_tools}/dx${bat}" />
|
|
19
|
<property name="aidl" value="${android_tools}/aidl${exe}" />
|
|
20
|
<property name="proguard-jar" value="${android_sdk_home}/tools/proguard/lib/proguard.jar" />
|
|
21
|
<property name="annotations-jar" value="${android_sdk_home}/tools/support/annotations.jar" />
|
|
22
|
|
|
23
|
<!-- some file directory exclude "bin" file, because "bin" file will be changed each loop -->
|
|
24
|
<property name="gen-dir" value="gen" />
|
|
25
|
<property name="src-dir" value="src" />
|
|
26
|
<property name="libs-dir" value="libs" />
|
|
27
|
<property name="res-dir" value="res" />
|
|
28
|
<property name="asset-dir" value="assets" />
|
|
29
|
<property name="bin-dir" value="bin" />
|
|
30
|
<property name="manifest-xml" value="AndroidManifest.xml" />
|
|
31
|
<!-- 主工程各个目录 -->
|
|
32
|
<property name="host-gen" value="${project_home}/${gen-dir}" />
|
|
33
|
<property name="host-src" value="${project_home}/${src-dir}" />
|
|
34
|
<property name="host-libs" value="${project_home}/${libs-dir}" />
|
|
35
|
<property name="host-bin" value="${project_home}/${bin-dir}" />
|
|
36
|
<property name="host-classes" value="${host-bin}/classes" />
|
|
37
|
<property name="intermediate-dex" value="${project_home}/${bin-dir}/${app_name}/classes.dex" />
|
|
38
|
<!-- The final package file to generate -->
|
|
39
|
<property name="resources-package" value="${project_home}/${bin-dir}/${app_name}/${app_name}.ap_" />
|
|
40
|
<property name="out-unsigned-package" value="${project_home}/${bin-dir}/${app_name}/${app_name}-unsigned.apk" />
|
|
41
|
<property name="out-signed-package" value="${project_home}/${bin-dir}/${app_name}/${app_name}-signed.apk" />
|
|
42
|
<property name="zipalign-package" value="${output_path}/${app_name}_for_android_${android_version}.apk" />
|
|
43
|
|
|
44
|
<target name="apkpackaging" depends="init,aapt_gererateR,aidl,compile,obfuscate,dex-package,aapt-package-res,apk-builder,jar-signer,zipalign"/>
|
|
45
|
|
|
46
|
<!-- 初始化清空-->
|
|
47
|
<target name="init">
|
|
48
|
<delete dir="${host-gen}" />
|
|
49
|
<delete dir="${host-bin}" />
|
|
50
|
<delete file="${project_home}/proguardMapping.txt" />
|
|
51
|
|
|
52
|
<mkdir dir="${host-gen}" />
|
|
53
|
<mkdir dir="${host-bin}" />
|
|
54
|
<mkdir dir="${host-classes}" />
|
|
55
|
<mkdir dir="${host-bin}/${app_name}" />
|
|
56
|
<!-- <mkdir dir="${output_path}" /> -->
|
|
57
|
</target>
|
|
58
|
|
|
59
|
<!-- 生成R文件和Manifest.java -->
|
|
60
|
<target name="aapt_gererateR">
|
|
61
|
<exec executable="${aapt}" failonerror="true">
|
|
62
|
<arg value="package" />
|
|
63
|
<arg value="-m" />
|
|
64
|
<arg value="-J" />
|
|
65
|
<arg value="${host-gen}" />
|
|
66
|
<arg value="-M" />
|
|
67
|
<arg value="${project_home}/${manifest-xml}" />
|
|
68
|
<arg value="-S" />
|
|
69
|
<arg value="${project_home}/${res-dir}" />
|
|
70
|
<!-- 同时需要调用Library的res -->
|
|
71
|
<arg value="-S" />
|
|
72
|
<arg value="${library_1}/${res-dir}" /><!-- 注意点:同时需要调用Library的res-->
|
|
73
|
|
|
74
|
<!-- <arg value="-S" />
|
|
75
|
<arg value="${library_2}/${res-dir}" /> -->
|
|
76
|
|
|
77
|
<arg value="-I" />
|
|
78
|
<arg value="${android-jar}" />
|
|
79
|
<arg value="--auto-add-overlay" /> <!-- 这个重要,覆盖资源,不然报错-->
|
|
80
|
</exec>
|
|
81
|
<!-- 编译Libray1 的R文件 -->
|
|
82
|
<exec executable="${aapt}" failonerror="true">
|
|
83
|
<arg value="package" />
|
|
84
|
<arg value="-m" />
|
|
85
|
<arg value="--non-constant-id" /> <!-- 加了这个参数-->
|
|
86
|
<arg value="--auto-add-overlay" />
|
|
87
|
<arg value="-J" />
|
|
88
|
<arg value="gen" />
|
|
89
|
<arg value="-M" />
|
|
90
|
<arg value="${library_1}/${manifest-xml}" /> <!-- 库应用的manifest-->
|
|
91
|
<!-- <arg value="-S" />
|
|
92
|
<arg value="${library_1}/${res-dir}" /> -->
|
|
93
|
<arg value="-I" />
|
|
94
|
<arg value="${android-jar}" />
|
|
95
|
</exec>
|
|
96
|
|
|
97
|
<!-- 编译Libray2 的R文件 -->
|
|
98
|
<exec executable="${aapt}" failonerror="true">
|
|
99
|
<arg value="package" />
|
|
100
|
<arg value="-m" />
|
|
101
|
<arg value="--non-constant-id" /> <!-- 加了这个参数-->
|
|
102
|
<arg value="--auto-add-overlay" />
|
|
103
|
<arg value="-J" />
|
|
104
|
<arg value="gen" />
|
|
105
|
<arg value="-M" />
|
|
106
|
<arg value="${library_2}/${manifest-xml}" /> <!-- 库应用的manifest-->
|
|
107
|
<!-- <arg value="-S" />
|
|
108
|
<arg value="${library_2}/${res-dir}" /> -->
|
|
109
|
<arg value="-I" />
|
|
110
|
<arg value="${android-jar}" />
|
|
111
|
</exec>
|
|
112
|
</target>
|
|
113
|
|
|
114
|
<!-- 生成aidl对应的java文件 -->
|
|
115
|
<target name="aidl">
|
|
116
|
<apply executable="${aidl}" failonerror="true">
|
|
117
|
<arg value="-p${android-framework}" />
|
|
118
|
<arg value="-I${host-src}" />
|
|
119
|
<arg value="-o${host-gen}" />
|
|
120
|
<fileset dir="${host-src}">
|
|
121
|
<include name="**/*.aidl" />
|
|
122
|
</fileset>
|
|
123
|
</apply>
|
|
124
|
</target>
|
|
125
|
|
|
126
|
<!-- 编译java文件为class文件 -->
|
|
127
|
<target name="compile">
|
|
128
|
<path id="project.libs">
|
|
129
|
<fileset dir="${project_home}/${libs-dir}">
|
|
130
|
<include name="*.so" />
|
|
131
|
<include name="**/*.so" />
|
|
132
|
<include name="*/*.so" />
|
|
133
|
<include name="**/*.jar" />
|
|
134
|
<include name="*.jar" />
|
|
135
|
</fileset>
|
|
136
|
</path>
|
|
137
|
|
|
138
|
<path id="library1.libs">
|
|
139
|
<fileset dir="${library_1}/libs">
|
|
140
|
<include name="*.so" />
|
|
141
|
<include name="**/*.so" />
|
|
142
|
<include name="*/*.so" />
|
|
143
|
<include name="**/*.jar" />
|
|
144
|
<include name="*.jar" />
|
|
145
|
</fileset>
|
|
146
|
</path>
|
|
147
|
|
|
148
|
<path id="library2.libs">
|
|
149
|
<fileset dir="${library_2}/libs">
|
|
150
|
<include name="*.so" />
|
|
151
|
<include name="**/*.so" />
|
|
152
|
<include name="*/*.so" />
|
|
153
|
<include name="**/*.jar" />
|
|
154
|
<include name="*.jar" />
|
|
155
|
</fileset>
|
|
156
|
</path>
|
|
157
|
|
|
158
|
<javac debug="true" extdirs="" srcdir="." includeantruntime="on"
|
|
159
|
destdir="${host-classes}" bootclasspath="${android-jar}" encoding="UTF-8">
|
|
160
|
<compilerarg line="-encoding UTF-8 " />
|
|
161
|
<src path="${library_1}/${src-dir}" /><!-- Library1的src文件 -->
|
|
162
|
<src path="${library_2}/${src-dir}" /><!-- Library2的src文件 -->
|
|
163
|
<src path="${host-src}" />
|
|
164
|
<src path="${host-gen}" />
|
|
165
|
<!-- jar文件 -->
|
|
166
|
<classpath refid="library1.libs" />
|
|
167
|
<classpath refid="library2.libs" />
|
|
168
|
<classpath refid="project.libs" />
|
|
169
|
</javac>
|
|
170
|
</target>
|
|
171
|
|
|
172
|
<!-- 混淆 -->
|
|
173
|
<target name="obfuscate">
|
|
174
|
<jar basedir="${host-classes}" destfile="temp.jar" />
|
|
175
|
|
|
176
|
<java jar="${proguard-jar}" fork="true" failonerror="true">
|
|
177
|
<sysproperty key="file.encoding" value="UTF-8" />
|
|
178
|
<jvmarg value="-Dmaximum.inlined.code.length=32" />
|
|
179
|
<arg value="-injars temp.jar" />
|
|
180
|
<arg value="-outjars optimized.jar" />
|
|
181
|
<arg value="-libraryjars '${annotations-jar}'" />
|
|
182
|
<arg value="-libraryjars '${android-jar}'" />
|
|
183
|
<arg value="@${project_home}/proguard-project.txt" />
|
|
184
|
</java>
|
|
185
|
<delete file="temp.jar" />
|
|
186
|
<delete dir="${host-classes}" />
|
|
187
|
<mkdir dir="${host-classes}" />
|
|
188
|
<unzip src="optimized.jar" dest="${host-classes}" />
|
|
189
|
<delete file="optimized.jar" />
|
|
190
|
</target>
|
|
191
|
|
|
192
|
<!-- 打包dex文件 -->
|
|
193
|
<target name="dex-package">
|
|
194
|
<echo>Packaging dex...</echo>
|
|
195
|
<apply executable="${dx}" failonerror="true" parallel="true">
|
|
196
|
<arg value="--dex" />
|
|
197
|
<arg value="--output=${intermediate-dex}" />
|
|
198
|
<arg path="${host-classes}" />
|
|
199
|
<arg path="${host-libs}" />
|
|
200
|
|
|
201
|
<fileset dir="${project_home}/${libs-dir}" />
|
|
202
|
<!-- Library1 -->
|
|
203
|
<fileset dir="${library_1}/libs" />
|
|
204
|
<!-- Library2 -->
|
|
205
|
<fileset dir="${library_2}/libs" />
|
|
206
|
</apply>
|
|
207
|
</target>
|
|
208
|
|
|
209
|
<!-- aapt打包资源 -->
|
|
210
|
<target name="aapt-package-res">
|
|
211
|
<echo>Packaging resources and assets...</echo>
|
|
212
|
<exec executable="${aapt}" failonerror="true">
|
|
213
|
<arg value="package" />
|
|
214
|
<arg value="-f" />
|
|
215
|
<arg value="-M" />
|
|
216
|
<arg value="${project_home}/${manifest-xml}" />
|
|
217
|
<arg value="-S" />
|
|
218
|
<arg value="${project_home}/${res-dir}" />
|
|
219
|
|
|
220
|
<arg value="-S" />
|
|
221
|
<arg value="${library_1}/${res-dir}" /><!-- 包含Library的资源 -->
|
|
222
|
|
|
223
|
<!-- <arg value="-S" />
|
|
224
|
<arg value="${library_2}/${res-dir}" /> --><!-- 包含Library2的资源 -->
|
|
225
|
|
|
226
|
<arg value="-A" />
|
|
227
|
<arg value="${project_home}/${asset-dir}" /><!-- assets文件 -->
|
|
228
|
|
|
229
|
<arg value="-I" />
|
|
230
|
<arg value="${android-jar}" />
|
|
231
|
<arg value="-F" />
|
|
232
|
<arg value="${resources-package}" /><!-- 输出资源压缩包 -->
|
|
233
|
<arg value="--auto-add-overlay" /> <!-- 这个重要,覆盖资源,不然报错-->
|
|
234
|
</exec>
|
|
235
|
</target>
|
|
236
|
|
|
237
|
|
|
238
|
<!-- APK打包 -->
|
|
239
|
<target name="apk-builder">
|
|
240
|
<echo>Building apk...</echo>
|
|
241
|
<java classpath="${android_apk_tools}/lib/sdklib.jar" classname="com.android.sdklib.build.ApkBuilderMain" fork="true" failonerror="true">
|
|
242
|
<sysproperty key="file.encoding" value="UTF-8" />
|
|
243
|
<!-- 创建未签名的包 -->
|
|
244
|
<arg value="${out-unsigned-package}" />
|
|
245
|
<arg value="-u" />
|
|
246
|
<arg value="-z" />
|
|
247
|
<arg value="${resources-package}" />
|
|
248
|
<!-- dex中间文件 -->
|
|
249
|
<arg value="-f" />
|
|
250
|
<arg value="${intermediate-dex}" />
|
|
251
|
<!-- Adds the java resources found in that folder -->
|
|
252
|
<arg value="-rf" />
|
|
253
|
<arg value="${host-src}" />
|
|
254
|
<!-- add native libraries -->
|
|
255
|
<arg value="-nf" />
|
|
256
|
<arg value="${host-libs}" />
|
|
257
|
<arg value="-nf" />
|
|
258
|
<arg value="${library_1}/libs" />
|
|
259
|
<arg value="-nf" />
|
|
260
|
<arg value="${library_2}/libs" />
|
|
261
|
<!-- Adds the java resources found in the jar file(s) -->
|
|
262
|
<arg value="-rj" />
|
|
263
|
<arg value="${host-libs}" />
|
|
264
|
<arg value="-rj" />
|
|
265
|
<arg value="${library_1}/libs" />
|
|
266
|
<arg value="-rj" />
|
|
267
|
<arg value="${library_2}/libs" />
|
|
268
|
</java>
|
|
269
|
</target>
|
|
270
|
|
|
271
|
<!-- APK签名 -->
|
|
272
|
<target name="jar-signer">
|
|
273
|
<echo>Jar signer...</echo>
|
|
274
|
<exec executable="${jarsigner}" failonerror="true">
|
|
275
|
<!-- 打印详细日志 -->
|
|
276
|
<!-- <arg value="-verbose" /> -->
|
|
277
|
<!-- 签名信息 -->
|
|
278
|
<arg value="-keystore" />
|
|
279
|
<arg value="${key_store}" />
|
|
280
|
<arg value="-storepass" />
|
|
281
|
<arg value="${key_store_password}" />
|
|
282
|
<arg value="-keypass" />
|
|
283
|
<arg value="${key_alias_password}" />
|
|
284
|
<!-- 输出安装包 -->
|
|
285
|
<arg value="-signedjar" />
|
|
286
|
<arg value="${out-signed-package}" />
|
|
287
|
<arg value="${out-unsigned-package}" />
|
|
288
|
<arg value="${key_alias}" />
|
|
289
|
<!-- -->
|
|
290
|
<arg value="-digestalg" />
|
|
291
|
<arg value="SHA1" />
|
|
292
|
<arg value="-sigalg" />
|
|
293
|
<arg value="MD5withRSA" />
|
|
294
|
</exec>
|
|
295
|
</target>
|
|
296
|
|
|
297
|
<!-- 使用zipalign做优化,对apk文件进行对齐 -->
|
|
298
|
<target name="zipalign">
|
|
299
|
<echo>Zipalign optimizing...</echo>
|
|
300
|
<exec executable="${zipalign}" failonerror="true">
|
|
301
|
<!-- 打印详细日志 -->
|
|
302
|
<!-- <arg value="-v" /> -->
|
|
303
|
<arg value="-f" />
|
|
304
|
<arg value="4" />
|
|
305
|
<arg value="${out-signed-package}" />
|
|
306
|
<!-- arg value="${out-unsigned-package}" /> -->
|
|
307
|
<arg value="${zipalign-package}" />
|
|
308
|
</exec>
|
|
309
|
<echo>打包完成:${zipalign-package}</echo>
|
|
310
|
</target>
|
|
311
|
|
|
312
|
</project>
|