|
@ -0,0 +1,366 @@
|
|
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
<project name="apkTargets" default="zipalign" basedir=".">
|
|
3
|
<record name="D:\123\build.log" loglevel="info" append="no" action="start" />
|
|
4
|
|
|
5
|
<!-- 根据本地环境设置变量 -->
|
|
6
|
<property name="app.source.path" value="D:\quickStart\111\ipu-client" />
|
|
7
|
<property name="jdk.home" value="C:\Program Files (x86)\Java\jdk1.6.0_10" />
|
|
8
|
<property name="sdk.home" value="D:\Android\sdk" />
|
|
9
|
<property name="ant.path" value="D:\Program Files\apache-ant-1.9.4\lib" />
|
|
10
|
|
|
11
|
<!-- 如果依赖library,设置library的路径 -->
|
|
12
|
<property name="library-1" value="D:\quickStart\111\wade-mobile-common"/>
|
|
13
|
<property name="library-1-libs" value="${library-1}/libs"/>
|
|
14
|
|
|
15
|
<property name="library-2" value="D:\quickStart\111\wade-mobile-lib"/>
|
|
16
|
<property name="library-2-libs" value="${library-2}/libs"/>
|
|
17
|
<!--
|
|
18
|
1. 在Target- aapt_gererateR 中添加library
|
|
19
|
2. 在Target- compile 中添加library
|
|
20
|
3. 在Target- dex 中添加library
|
|
21
|
4. 在Target- aapt-package-res 中添加library
|
|
22
|
5. 在Target- apkbuilder 中添加library
|
|
23
|
-->
|
|
24
|
|
|
25
|
<!-- app名字,编译版本 -->
|
|
26
|
<property name="appname" value="ipu-client" />
|
|
27
|
<property name="target" value="android-19" />
|
|
28
|
<property name="android_version" value="4.4" />
|
|
29
|
|
|
30
|
<!-- 设置SDK地路径 -->
|
|
31
|
<property name="bin.dir" value="${jdk.home}/bin" />
|
|
32
|
<property name="sdk.folder" value="${sdk.home}/platforms/${target}" />
|
|
33
|
<property name="apk.tools" value="${sdk.home}/tools" />
|
|
34
|
<property name="android.tools" value="${sdk.home}/build-tools/19.1.0" />
|
|
35
|
|
|
36
|
<!-- 设置密钥的存储路径 -->
|
|
37
|
<property name="key.store" value="${app.source.path}/shelomi.keystore" />
|
|
38
|
<property name="key.alias" value="mykey" />
|
|
39
|
<property name="key.store.password" value="1234567890" />
|
|
40
|
<property name="key.alias.password" value="1234567890" />
|
|
41
|
|
|
42
|
<property name="output.dir" value="out" />
|
|
43
|
|
|
44
|
<!-- 导入ant指令(If)需要用到第三方jar包ant-contrib.jar -->
|
|
45
|
<!-- <path id="ant.contrib.lib">
|
|
46
|
<fileset dir="${ant.path}">
|
|
47
|
<include name="ant-contrib.jar" />
|
|
48
|
</fileset>
|
|
49
|
</path>
|
|
50
|
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
|
|
51
|
<classpath refid="ant.contrib.lib" />
|
|
52
|
</taskdef> -->
|
|
53
|
|
|
54
|
<!-- 识别编译环境 -->
|
|
55
|
<condition property="exe" value=".exe" else=""><os family="windows" /></condition>
|
|
56
|
<condition property="bat" value=".bat" else=""><os family="windows" /></condition>
|
|
57
|
|
|
58
|
<!-- Tools -->
|
|
59
|
<property name="jarsigner" value="${jdk.home}/bin/jarsigner${exe}" />
|
|
60
|
<property name="aapt" value="${android.tools}/aapt${exe}" />
|
|
61
|
<property name="zipalign" value="${android.tools}/zipalign${exe}" />
|
|
62
|
<property name="aidl" value="${android.tools}/aidl${exe}" />
|
|
63
|
<property name="dx" value="${android.tools}/dx${bat}" />
|
|
64
|
<property name="apk-builder" value="${apk.tools}/apkbuilder${bat}" />
|
|
65
|
|
|
66
|
<property name="android-jar" value="${sdk.folder}/android.jar" />
|
|
67
|
<property name="annotations-jar" value="${sdk.home}/tools/support/annotations.jar" />
|
|
68
|
|
|
69
|
<property name="android-framework" value="${sdk.folder}/framework.aidl" />
|
|
70
|
<property name="proguard-home" value="${sdk.home}/tools/proguard/lib" />
|
|
71
|
|
|
72
|
<!-- some file directory exclude "bin" file, because "bin" file will be changed each loop -->
|
|
73
|
<property name="outdir-gen" value="gen" />
|
|
74
|
<property name="resource-dir" value="res" />
|
|
75
|
<property name="asset-dir" value="assets" />
|
|
76
|
<property name="manifest-xml" value="AndroidManifest.xml" />
|
|
77
|
|
|
78
|
<property name="srcdir" value="src" />
|
|
79
|
<property name="srcdir-ospath" value="${basedir}/${srcdir}" />
|
|
80
|
|
|
81
|
<property name="external-libs" value="libs" />
|
|
82
|
<property name="external-libs-ospath" value="${basedir}/${external-libs}" />
|
|
83
|
|
|
84
|
<property name="outdir" value="bin" />
|
|
85
|
<property name="outdir-classes" value="${outdir}/classes" />
|
|
86
|
<property name="outdir-classes-ospath" value="${basedir}/${outdir-classes}" />
|
|
87
|
|
|
88
|
<property name="dex-file" value="classes.dex" />
|
|
89
|
<property name="intermediate-dex" value="${outdir}/${appname}/${dex-file}" />
|
|
90
|
<property name="intermediate-dex-ospath" value="${basedir}/${intermediate-dex}" />
|
|
91
|
|
|
92
|
<!-- The final package file to generate -->
|
|
93
|
<property name="resources-package" value="${outdir}/${appname}/${appname}.ap_" />
|
|
94
|
<property name="resources-package-ospath" value="${basedir}/${resources-package}" />
|
|
95
|
|
|
96
|
<!-- The final apk file to generate when use the debug key -->
|
|
97
|
<property name="out-debug-package" value="${outdir}/${appname}-debug.apk" />
|
|
98
|
<property name="out-debug-package-ospath" value="${basedir}/${out-debug-package}" />
|
|
99
|
|
|
100
|
<property name="out-unsigned-package" value="${outdir}/${appname}/${appname}-unsigned.apk" />
|
|
101
|
<property name="out-unsigned-package-ospath" value="${basedir}/${out-unsigned-package}" />
|
|
102
|
|
|
103
|
<property name="out-signed-package" value="${outdir}/${appname}/${appname}-signed.apk" />
|
|
104
|
<property name="out-signed-package-ospath" value="${basedir}/${out-signed-package}" />
|
|
105
|
|
|
106
|
<property name="zipalign-package-ospath" value="${basedir}/${output.dir}/${appname}_for_android_${android_version}_${output.dir}.apk" />
|
|
107
|
|
|
108
|
|
|
109
|
<!--1 初始化-->
|
|
110
|
<target name="init">
|
|
111
|
<delete dir="${outdir-gen}" />
|
|
112
|
<delete dir="${outdir}" />
|
|
113
|
<delete file="${basedir}/proguardMapping.txt" />
|
|
114
|
|
|
115
|
<mkdir dir="${outdir-gen}" />
|
|
116
|
<mkdir dir="${outdir-classes}" />
|
|
117
|
<mkdir dir="${outdir}/${appname}" />
|
|
118
|
<mkdir dir="${basedir}/${output.dir}" />
|
|
119
|
</target>
|
|
120
|
|
|
121
|
<!--2 生成R文件和Manifest.java-->
|
|
122
|
<target name="aapt_gererateR" depends="init">
|
|
123
|
<exec executable="${aapt}" failonerror="true">
|
|
124
|
<arg value="package" />
|
|
125
|
<arg value="-m" />
|
|
126
|
<arg value="-J" />
|
|
127
|
<arg value="${outdir-gen}" />
|
|
128
|
<arg value="-M" />
|
|
129
|
<arg value="${manifest-xml}" />
|
|
130
|
<arg value="-S" />
|
|
131
|
<arg value="${resource-dir}" />
|
|
132
|
<!-- 同时需要调用Library的res -->
|
|
133
|
<arg value="-S" />
|
|
134
|
<arg value="${library-1}/${resource-dir}" /><!-- 注意点:同时需要调用Library的res-->
|
|
135
|
|
|
136
|
<arg value="-S" />
|
|
137
|
<arg value="${library-2}/${resource-dir}" />
|
|
138
|
|
|
139
|
<arg value="-I" />
|
|
140
|
<arg value="${android-jar}" />
|
|
141
|
<arg value="--auto-add-overlay" /> <!-- 这个重要,覆盖资源,不然报错-->
|
|
142
|
</exec>
|
|
143
|
<!-- 编译Libray1 的R文件 -->
|
|
144
|
<exec executable="${aapt}" failonerror="true">
|
|
145
|
<arg value="package" />
|
|
146
|
<arg value="-m" />
|
|
147
|
<arg value="--non-constant-id" /> <!-- 加了这个参数-->
|
|
148
|
<arg value="--auto-add-overlay" />
|
|
149
|
<arg value="-J" />
|
|
150
|
<arg value="gen" />
|
|
151
|
<arg value="-M" />
|
|
152
|
<arg value="${library-1}/${manifest-xml}" /> <!-- 库应用的manifest-->
|
|
153
|
<arg value="-S" />
|
|
154
|
<arg value="res" />
|
|
155
|
<arg value="-S" />
|
|
156
|
<arg value="${library-1}/${resource-dir}" />
|
|
157
|
<arg value="-I" />
|
|
158
|
<arg value="${android-jar}" />
|
|
159
|
</exec>
|
|
160
|
|
|
161
|
<!-- 编译Libray2 的R文件 -->
|
|
162
|
<exec executable="${aapt}" failonerror="true">
|
|
163
|
<arg value="package" />
|
|
164
|
<arg value="-m" />
|
|
165
|
<arg value="--non-constant-id" /> <!-- 加了这个参数-->
|
|
166
|
<arg value="--auto-add-overlay" />
|
|
167
|
<arg value="-J" />
|
|
168
|
<arg value="gen" />
|
|
169
|
<arg value="-M" />
|
|
170
|
<arg value="${library-2}/${manifest-xml}" /> <!-- 库应用的manifest-->
|
|
171
|
<arg value="-S" />
|
|
172
|
<arg value="res" />
|
|
173
|
<arg value="-S" />
|
|
174
|
<arg value="${library-2}/${resource-dir}" />
|
|
175
|
<arg value="-I" />
|
|
176
|
<arg value="${android-jar}" />
|
|
177
|
</exec>
|
|
178
|
</target>
|
|
179
|
|
|
180
|
<!--3 生成aidl对应的java文件-->
|
|
181
|
<target name="aidl" depends="aapt_gererateR">
|
|
182
|
<apply executable="${aidl}" failonerror="true">
|
|
183
|
<arg value="-p${android-framework}" />
|
|
184
|
<arg value="-I${srcdir}" />
|
|
185
|
<arg value="-o${outdir-gen}" />
|
|
186
|
<fileset dir="${srcdir}">
|
|
187
|
<include name="**/*.aidl" />
|
|
188
|
</fileset>
|
|
189
|
</apply>
|
|
190
|
</target>
|
|
191
|
|
|
192
|
<!--4 编译java文件为class文件-->
|
|
193
|
<target name="compile" depends="aidl">
|
|
194
|
<path id="project.libs">
|
|
195
|
<fileset dir="${external-libs}">
|
|
196
|
<include name="*.so" />
|
|
197
|
<include name="**/*.so" />
|
|
198
|
<include name="*/*.so" />
|
|
199
|
<include name="**/*.jar" />
|
|
200
|
<include name="*.jar" />
|
|
201
|
</fileset>
|
|
202
|
</path>
|
|
203
|
|
|
204
|
<path id="library-1.libs">
|
|
205
|
<fileset dir="${library-1-libs}">
|
|
206
|
<include name="*.so" />
|
|
207
|
<include name="**/*.so" />
|
|
208
|
<include name="*/*.so" />
|
|
209
|
<include name="**/*.jar" />
|
|
210
|
<include name="*.jar" />
|
|
211
|
</fileset>
|
|
212
|
</path>
|
|
213
|
|
|
214
|
<path id="library-2.libs">
|
|
215
|
<fileset dir="${library-2-libs}">
|
|
216
|
<include name="*.so" />
|
|
217
|
<include name="**/*.so" />
|
|
218
|
<include name="*/*.so" />
|
|
219
|
<include name="**/*.jar" />
|
|
220
|
<include name="*.jar" />
|
|
221
|
</fileset>
|
|
222
|
</path>
|
|
223
|
|
|
224
|
<javac debug="true" extdirs="" srcdir="." includeantruntime="on"
|
|
225
|
destdir="${outdir-classes}" bootclasspath="${android-jar}" encoding="UTF-8">
|
|
226
|
<compilerarg line="-encoding UTF-8 " />
|
|
227
|
<src path="${library-1}/${srcdir}" /><!-- Library1的src文件 -->
|
|
228
|
<src path="${library-2}/${srcdir}" /><!-- Library2的src文件 -->
|
|
229
|
<src path="${srcdir}" />
|
|
230
|
<src path="${outdir-gen}" />
|
|
231
|
<!-- jar文件 -->
|
|
232
|
<classpath refid="library-1.libs" />
|
|
233
|
<classpath refid="library-2.libs" />
|
|
234
|
<classpath refid="project.libs" />
|
|
235
|
</javac>
|
|
236
|
</target>
|
|
237
|
|
|
238
|
<!--5 混淆-->
|
|
239
|
<target name="obfuscate" depends="compile">
|
|
240
|
<jar basedir="${outdir-classes}" destfile="temp.jar" />
|
|
241
|
|
|
242
|
<java jar="${proguard-home}/proguard.jar" fork="true" failonerror="true">
|
|
243
|
<jvmarg value="-Dmaximum.inlined.code.length=32" />
|
|
244
|
<arg value="-injars temp.jar" />
|
|
245
|
<arg value="-outjars optimized.jar" />
|
|
246
|
<arg value="-libraryjars '${annotations-jar}'" />
|
|
247
|
<arg value="-libraryjars '${android-jar}'" />
|
|
248
|
<arg value="@proguard-project.txt" />
|
|
249
|
</java>
|
|
250
|
<delete file="temp.jar" />
|
|
251
|
<delete dir="${outdir-classes}" />
|
|
252
|
<mkdir dir="${outdir-classes}" />
|
|
253
|
<unzip src="optimized.jar" dest="${outdir-classes}" />
|
|
254
|
<delete file="optimized.jar" />
|
|
255
|
</target>
|
|
256
|
|
|
257
|
<!--6 把class文件转换为dex文件-->
|
|
258
|
<target name="dex" depends="compile">
|
|
259
|
<echo>Packaging dex...</echo>
|
|
260
|
<apply executable="${dx}" failonerror="true" parallel="true">
|
|
261
|
<arg value="--dex" />
|
|
262
|
<arg value="--output=${intermediate-dex-ospath}" />
|
|
263
|
<arg path="${outdir-classes-ospath}" />
|
|
264
|
<arg path="${external-libs-ospath}" />
|
|
265
|
|
|
266
|
<fileset dir="${external-libs}" />
|
|
267
|
<!-- Library1 -->
|
|
268
|
<fileset dir="${library-1-libs}" />
|
|
269
|
<!-- Library2 -->
|
|
270
|
<fileset dir="${library-2-libs}" />
|
|
271
|
</apply>
|
|
272
|
</target>
|
|
273
|
|
|
274
|
<!--7 aapt打包资源-->
|
|
275
|
<target name="aapt-package-res" depends="dex">
|
|
276
|
<echo>Packaging resources and assets...</echo>
|
|
277
|
<exec executable="${aapt}" failonerror="true">
|
|
278
|
<arg value="package" />
|
|
279
|
<arg value="-f" />
|
|
280
|
<arg value="-M" />
|
|
281
|
<arg value="${manifest-xml}" />
|
|
282
|
<arg value="-S" />
|
|
283
|
<arg value="${resource-dir}" />
|
|
284
|
|
|
285
|
<arg value="-S" />
|
|
286
|
<arg value="${library-1}/${resource-dir}" /><!-- 包含Library的资源 -->
|
|
287
|
|
|
288
|
<arg value="-S" />
|
|
289
|
<arg value="${library-2}/${resource-dir}" /><!-- 包含Library2的资源 -->
|
|
290
|
|
|
291
|
<arg value="-A" />
|
|
292
|
<arg value="${asset-dir}" /><!-- assets文件 -->
|
|
293
|
|
|
294
|
<arg value="-I" />
|
|
295
|
<arg value="${android-jar}" />
|
|
296
|
<arg value="-F" />
|
|
297
|
<arg value="${resources-package}" /><!-- 输出资源压缩包 -->
|
|
298
|
<arg value="--auto-add-overlay" /> <!-- 这个重要,覆盖资源,不然报错-->
|
|
299
|
</exec>
|
|
300
|
</target>
|
|
301
|
|
|
302
|
<!--8 apkbuilder打包成apk文件-->
|
|
303
|
<target name="apkbuilder" depends="aapt-package-res">
|
|
304
|
<echo>${out-unsigned-package-ospath}</echo>
|
|
305
|
<exec executable="${apk-builder}" failonerror="true">
|
|
306
|
<arg value="${out-unsigned-package-ospath}" /><!-- 输出 -->
|
|
307
|
<arg value="-u" /><!-- 创建未签名的包 -->
|
|
308
|
<arg value="-z" /><!-- 资源压缩包 -->
|
|
309
|
<arg value="${resources-package-ospath}" />
|
|
310
|
<arg value="-f" /><!-- dex文件 -->
|
|
311
|
<arg value="${intermediate-dex-ospath}" />
|
|
312
|
|
|
313
|
<arg value="-rf" /><!-- Adds the java resources found in that folder -->
|
|
314
|
<arg value="${srcdir-ospath}" />
|
|
315
|
|
|
316
|
<arg value="-nf" /><!-- add native libraries -->
|
|
317
|
<arg value="${external-libs-ospath}" />
|
|
318
|
<arg value="-nf" />
|
|
319
|
<arg value="${library-1-libs}" />
|
|
320
|
<arg value="-nf" />
|
|
321
|
<arg value="${library-2-libs}" />
|
|
322
|
|
|
323
|
<arg value="-rj" /><!-- Adds the java resources found in the jar file(s) -->
|
|
324
|
<arg value="${basedir}/${external-libs}" />
|
|
325
|
<arg value="-rj" />
|
|
326
|
<arg value="${library-1-libs}" />
|
|
327
|
<arg value="-rj" />
|
|
328
|
<arg value="${library-2-libs}" />
|
|
329
|
</exec>
|
|
330
|
</target>
|
|
331
|
|
|
332
|
<!--9 签名apk文件-->
|
|
333
|
<target name="jarsigner" depends="apkbuilder">
|
|
334
|
<exec executable="${jarsigner}" failonerror="true">
|
|
335
|
<arg value="-verbose" />
|
|
336
|
<arg value="-keystore" />
|
|
337
|
<arg value="${key.store}" />
|
|
338
|
<arg value="-storepass" />
|
|
339
|
<arg value="${key.store.password}" />
|
|
340
|
<arg value="-keypass" />
|
|
341
|
<arg value="${key.alias.password}" />
|
|
342
|
<arg value="-signedjar" />
|
|
343
|
<arg value="${out-signed-package-ospath}" />
|
|
344
|
<arg value="${out-unsigned-package-ospath}" />
|
|
345
|
<arg value="${key.alias}" />
|
|
346
|
|
|
347
|
<arg value="-digestalg" />
|
|
348
|
<arg value="SHA1" />
|
|
349
|
<arg value="-sigalg" />
|
|
350
|
<arg value="MD5withRSA" />
|
|
351
|
</exec>
|
|
352
|
</target>
|
|
353
|
|
|
354
|
<!--10 对apk文件进行zipalign对齐-->
|
|
355
|
<target name="zipalign" depends="jarsigner">
|
|
356
|
<exec executable="${zipalign}" failonerror="true">
|
|
357
|
<arg value="-v" />
|
|
358
|
<arg value="-f" />
|
|
359
|
<arg value="4" />
|
|
360
|
<arg value="${out-signed-package-ospath}" />
|
|
361
|
<arg value="${zipalign-package-ospath}" />
|
|
362
|
</exec>
|
|
363
|
<echo>打包完成:${zipalign-package-ospath}</echo>
|
|
364
|
</target>
|
|
365
|
|
|
366
|
</project>
|