Hudson是一款持续集成引擎,架构在Subversion等版本控制工具上,依靠构建工具对项目进行集成构建,并且可以根据用户需求提供相应的反馈,比如发邮件,总的来说是比较实用的。
这几天在老师的要求下使用了Hudson,在纯JAVA项目的情况下使用MAVEN配置起来还算简单,无奈项目的客户端是Android平台的,在纠结了N天后还是配置不成功,最后改用Ant, 整个过程还是比较简单,除了build.xml的编写~~
注:下面的讲述是在Hudson配置好的情况下实现的,换句话说你可以试试你的JAVA项目能否正确被Hudson持续集成
步骤:
1)首先按常理新建一个Android;
2)接着在该项目上右击,新建一个build.xml(名字可以随便取,这个在Hudson可以选择构件所使用的项目文件),然后将下面这段代码放入文件
这几天在老师的要求下使用了Hudson,在纯JAVA项目的情况下使用MAVEN配置起来还算简单,无奈项目的客户端是Android平台的,在纠结了N天后还是配置不成功,最后改用Ant, 整个过程还是比较简单,除了build.xml的编写~~
注:下面的讲述是在Hudson配置好的情况下实现的,换句话说你可以试试你的JAVA项目能否正确被Hudson持续集成
步骤:
1)首先按常理新建一个Android;
2)接着在该项目上右击,新建一个build.xml(名字可以随便取,这个在Hudson可以选择构件所使用的项目文件),然后将下面这段代码放入文件
1
<?
xml version="1.0" encoding="UTF-8"
?>
2 <!-- 步骤:
3 第一.生成R.java
4 第二.JAVAC编译JAVA文件
5 第三.批处理生成classes.dex
6 第四.aapt打包资源
7 第五.apkbuilder包资源和类文件为APK文件
8 第六.jarsinger 对APK进行签名 -->
9 <!-- 此处的项目名需修改为你的项目名 -->
10
11 < project name ="SEOA_Client" basedir ="." default ="debug" >
12
13 <!-- 此处应用系统的环境变量 -->
14
15 < property environment ="env" />
16
17 <!-- SDK Locations -->
18
19 <!-- 获取SDK的安装目录,注意在我的系统中环境变量的名称为ANDROID_SDK_HOME,你可以修改成你的环境变量名称 -->
20 <!-- 也可以直接指定路径,下面采用的就是这种方式 -->
21 < property name ="sdk2.2-folder" value ="F:\sdk\android-sdk-windows" />
22
23 <!-- 如若你使用的android版本不一样,可以在此处修改 -->
24 < property name ="sdk-folder" value ="${sdk2.2-folder}/platforms/android-8" />
25
26 < property name ="android.aidl" value ="${sdk-folder}/framework.aidl" />
27 < property name ="sdk-tools" value ="${sdk-folder}/tools" />
28 < property name ="android-tools" value ="${sdk2.2-folder}/tools" />
29
30
31 < property name ="verbose" value ="false" />
32
33 <!-- 配置使用到的库,只要保证路径正确,不需修改 -->
34
35 < path id ="android.antlibs" >
36 < pathelement location ="${env.ANDROID_SDK_HOME}/tools/lib/anttasks.jar" />
37 < pathelement location ="${env.ANDROID_SDK_HOME}/tools/lib/sdklib.jar" />
38 < pathelement location ="${env.ANDROID_SDK_HOME}/tools/lib/androidprefs.jar" />
39 </ path >
40
41
42 <!-- step 1.generate R.java by aapt 2.compile java to class by javac 3.generate classes.dex by dx.bat -->
43 <!-- 4.package resources by aapt 5. package resource and classes.dex by apkbuilder.bat 6.sign apk by jarsinger -->
44
45 <!-- 配置在整个过程中使用到的Tools,不需修改 -->
46 < property name ="aapt" value ="${sdk-tools}/aapt.exe" />
47 < property name ="dx" value ="${sdk-tools}/dx.bat" />
48 < property name ="apk-builder" value ="${android-tools}/apkbuilder.bat" />
49 < property name ="aidl" value ="${sdk-tools}/aidl.exe" />
50 < property name ="adb" value ="${android-tools}/adb.exe" />
51 < property name ="android-jar" value ="${sdk-folder}/android.jar" />
52 < property name ="jarsigner" value ="${env.JAVA_HOME}/bin/jarsigner.exe" />
53
54 <!-- Android项目使用到所有库,这个地方需修改 -->
55 < path id ="android.libraries.jars" >
56 < pathelement location ="${android-jar}" />
57 < pathelement location ="${basedir}/lib/commons-pool-1.5.4.jar" />
58 </ path >
59
60
61 <!-- Application Package Name,包名需修改 -->
62 < property name ="application-package" value ="com.android.ant" />
63
64 <!-- 以下都不需要修改 -->
65 < property name ="useragent" value ="byAndroidWeb" />
66 < property name ="version" value ="1.02" />
67 <!-- The intermediates directory -->
68
69 <!-- Eclipse uses "bin" for its own output, so we do the same. -->
70 < property name ="outdir-bin" value ="bin" />
71 < property name ="outdir-gen" value ="gen" />
72 <!-- source directories -->
73 < property name ="resource-dir" value ="res" />
74 < property name ="asset-dir" value ="assets" />
75 < property name ="srcdir" value ="src" />
76 < property name ="srcdir-ospath" value ="${basedir}/${srcdir}" />
77 < property name ="external-libs" value ="lib" />
78 < property name ="external-libs-ospath" value ="${basedir}/${external-libs}" />
79
80 <!-- dest directories -->
81 < property name ="des-resource-dir" value ="${outdir-bin}/res" />
82 < property name ="des-asset-dir" value ="${outdir-bin}/assets" />
83 < property name ="des-srcdir" value ="${outdir-bin}/src" />
84 < property name ="des-srcdir-ospath" value ="${basedir}/${outdir-bin}/${srcdir}" />
85 < property name ="des-external-libs" value ="${outdir-bin}/libs" />
86 < property name ="des-external-libs-ospath" value ="${basedir}/${outdir-bin}/${external-libs}" />
87
88 <!-- Output directories -->
89 < property name ="outdir-classes" value ="${outdir-bin}/src" />
90 < property name ="outdir-obfuscate-classes" value ="${outdir-bin}" />
91 < property name ="outdir-obfuscate-classes-ospath" value ="${basedir}/${outdir-obfuscate-classes}" />
92
93 <!-- Intermediate files -->
94 < property name ="dex-file" value ="classes.dex" />
95 < property name ="intermediate-dex" value ="${outdir-bin}/${dex-file}" />
96 < property name ="intermediate-dex-ospath" value ="${basedir}/${intermediate-dex}" />
97
98 <!-- The final package file to generate -->
99 < property name ="resources-package" value ="${outdir-bin}/${ant.project.name}" />
100 < property name ="resources-package-ospath" value ="${basedir}/${resources-package}" />
101 < property name ="out-debug-package" value ="${outdir-bin}/${ant.project.name}-debug.apk" />
102 < property name ="out-debug-package-ospath" value ="${basedir}/${out-debug-package}" />
103 < property name ="out-unsigned-package" value ="${outdir-bin}/${ant.project.name}-unsigned.apk" />
104 < property name ="out-unsigned-package-ospath" value ="${basedir}/${out-unsigned-package}" />
105 < property name ="out-signed-package" value ="${useragent}\${ant.project.name}.apk" />
106 < property name ="out-signed-package-ospath" value ="${basedir}\${out-signed-package}" />
107
108
109 <!-- init -->
110 < target name ="init" >
111 < echo >Creating all output directories </ echo >
112 < delete dir ="${outdir-bin}" />
113 < mkdir dir ="${outdir-bin}" />
114 < mkdir dir ="${outdir-classes}" />
115 </ target >
116
117 <!-- copy original strings and modify useragent -->
118 < target name ="copy" depends ="init" >
119 < echo >copy files to output folder </ echo >
120 </ target >
121
122
123 <!-- Generate the R.java file for this project's resources. -->
124
125 < target name ="resource-src" depends ="copy" >
126 < echo >Generating R.java / Manifest.java from the resources
</
echo
>
127 < echo >${aapt} </ echo >
128 < exec executable ="${aapt}" failonerror ="true" >
129 < arg value ="package" />
130 < arg value ="-m" />
131 < arg value ="-J" />
132 < arg value ="${outdir-gen}" />
133 < arg value ="-M" />
134 < arg value ="AndroidManifest.xml" />
135 < arg value ="-S" />
136 < arg value ="${resource-dir}" />
137 < arg value ="-I" />
138
139 < arg value ="${android-jar}" />
140 </ exec >
141 </ target >
142
143
144 <!-- Generate java classes from .aidl files. -->
145 < target name ="aidl" depends ="copy" >
146 < echo >Compiling aidl files into Java classes
</
echo
>
147 < apply executable ="${aidl}" failonerror ="true" >
148 < arg value ="-p${android.aidl}" />
149 < arg value ="-I${srcdir}" />
150 < fileset dir ="${srcdir}" >
151 < include name ="**/*.aidl" />
152 </ fileset >
153 </ apply >
154 </ target >
155
156 <!-- Compile this project's .java files into .class files. -->
157 < target name ="compile" depends ="copy, resource-src, aidl" >
158 < javac encoding ="ascii" target ="1.6" debug ="true" extdirs ="" srcdir ="." destdir ="${outdir-classes}" bootclasspathref ="android.libraries.jars" >
159 < classpath >
160 < fileset dir ="${external-libs}" includes ="*.jar" />
161 </ classpath >
162 </ javac >
163 </ target >
164
165 <!-- Convert this project's .class files into .dex files. -->
166 < target name ="dex" depends ="compile" >
167 < echo >Converting compiled files and external libraries into ${outdir}/${dex-file}
</
echo
>
168 < apply executable ="${dx}" failonerror ="true" parallel ="false" >
169 < arg value ="--dex" />
170
171 < arg value ="--output=${intermediate-dex-ospath}" />
172 < arg path ="${outdir-obfuscate-classes-ospath}" />
173 < fileset dir ="${external-libs}" includes ="*.jar" />
174 </ apply >
175 </ target >
176
177 <!-- Put the project's resources into the output package file. -->
178 < target name ="package-res-and-assets" >
179 < echo >Packaging resources and assets
</
echo
>
180 < exec executable ="${aapt}" failonerror ="true" >
181 < arg value ="package" />
182 < arg value ="-f" />
183 < arg value ="-M" />
184 < arg value ="AndroidManifest.xml" />
185 < arg value ="-S" />
186 < arg value ="${resource-dir}" />
187 < arg value ="-A" />
188 < arg value ="${asset-dir}" />
189 < arg value ="-I" />
190 < arg value ="${android-jar}" />
191 < arg value ="-F" />
192 < arg value ="${resources-package}" />
193 </ exec >
194 </ target >
195
196 <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
197 < target name ="package-res-no-assets" >
198 < echo >Packaging resources
</
echo
>
199 < exec executable ="${aapt}" failonerror ="true" >
200 < arg value ="package" />
201 < arg value ="-f" />
202 < arg value ="-M" />
203 < arg value ="AndroidManifest.xml" />
204 < arg value ="-S" />
205 < arg value ="${resource-dir}" />
206 <!-- No assets directory -->
207 < arg value ="-I" />
208 < arg value ="${android-jar}" />
209 < arg value ="-F" />
210 < arg value ="${resources-package}" />
211 </ exec >
212 </ target >
213
214 <!-- Invoke the proper target depending on whether or not
215 an assets directory is present. -->
216 <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
217 only when the assets dir exists. -->
218 < target name ="package-res" >
219 < available file ="${asset-dir}" type ="dir" property ="res-target" value ="and-assets" />
220 < property name ="res-target" value ="no-assets" />
221 < antcall target ="package-res-${res-target}" />
222 </ target >
223
224 <!-- Package the application and sign it with a debug key.
225 This is the default target when building. It is used for debug. -->
226 < target name ="debug" depends ="dex, package-res" >
227 < echo >Packaging ${out-debug-package}, and signing it with a debug key
</
echo
>
228 < exec executable ="${apk-builder}" failonerror ="false" >
229 < arg value ="${out-debug-package-ospath}" />
230 < arg value ="-z" />
231 < arg value ="${resources-package-ospath}" />
232 < arg value ="-f" />
233 < arg value ="${intermediate-dex-ospath}" />
234 < arg value ="-rf" />
235 < arg value ="${srcdir-ospath}" />
236 < arg value ="-rj" />
237 < arg value ="${external-libs-ospath}" />
238 </ exec >
239 </ target >
240
241 <!-- Package the application without signing it.
242 This allows for the application to be signed later with an official publishing key. -->
243 < target name ="package" depends ="dex, package-res" >
244 < echo >Packaging ${out-unsigned-package} for release
</
echo
>
245 < exec executable ="${apk-builder}" failonerror ="true" >
246 < arg value ="${out-unsigned-package-ospath}" />
247 < arg value ="-u" />
248 < arg value ="-z" />
249 < arg value ="${resources-package-ospath}" />
250 < arg value ="-f" />
251 < arg value ="${intermediate-dex-ospath}" />
252 < arg value ="-rf" />
253 < arg value ="${srcdir-ospath}" />
254 < arg value ="-rj" />
255
256 < arg value ="${external-libs-ospath}" />
257 </ exec >
258 < echo >It will need to be signed with jarsigner before being published. </ echo >
259 </ target >
260
261 < target name ="jarsigner" depends ="package" >
262 < echo >Packaging ${out-unsigned-package} for release
</
echo
>
263 < exec executable ="${jarsigner}" failonerror ="true" >
264 < arg value ="-verbose" />
265 < arg value ="-storepass" />
266 < arg value ="byread002" />
267 < arg value ="-keypass" />
268 < arg value ="byread002" />
269 < arg value ="-keystore" />
270 < arg value ="bbyread.keystore" />
271 < arg value ="-signedjar" />
272 < arg value ="${out-signed-package-ospath}" />
273 < arg value ="${out-unsigned-package-ospath}" />
274 < arg value ="byread" />
275 </ exec >
276 </ target >
277
278 < target name ="release" depends ="jarsigner" >
279 < echo >release for release
</
echo
>
280 </ target >
281
282 <!-- Install the package on the default emulator -->
283 < target name ="install" depends ="debug" >
284 < echo >Installing ${out-debug-package} onto default emulator
</
echo
>
285 < exec executable ="${adb}" failonerror ="true" >
286 < arg value ="install" />
287 < arg value ="${out-debug-package}" />
288 </ exec >
289 </ target >
290
291 < target name ="reinstall" depends ="debug" >
292 < echo >Installing ${out-debug-package} onto default emulator
</
echo
>
293 < exec executable ="${adb}" failonerror ="true" >
294 < arg value ="install" />
295 < arg value ="-r" />
296
297 < arg value ="${out-debug-package}" />
298 </ exec >
299 </ target >
300
301 <!-- Uinstall the package from the default emulator -->
302 < target name ="uninstall" >
303 < echo >Uninstalling ${application-package} from the default emulator
</
echo
>
304 < exec executable ="${adb}" failonerror ="true" >
305 < arg value ="uninstall" />
306 < arg value ="${application-package}" />
307 </ exec >
308 </ target >
310 </ project >
代码比较长,里面有部分需要修改的地方,比如包的名字,比如安装在服务器上的SDK的路径等,大家可以按照文字描述慢慢修改,之后就可以将项目提交,在Hudson上建立一个自由风格的项目,选择使用Ant作为构建工具,选择build.xml作为构件文件,构建中很可能出现各种问题,大家可以根据Hudson的命令行输出对build.xml文件进行修改,具体做法目前我还不是很了解,例如: failοnerrοr="true" ,我曾经把true改为false就跳过一个错误,大家尽量摸索一下吧
2 <!-- 步骤:
3 第一.生成R.java
4 第二.JAVAC编译JAVA文件
5 第三.批处理生成classes.dex
6 第四.aapt打包资源
7 第五.apkbuilder包资源和类文件为APK文件
8 第六.jarsinger 对APK进行签名 -->
9 <!-- 此处的项目名需修改为你的项目名 -->
10
11 < project name ="SEOA_Client" basedir ="." default ="debug" >
12
13 <!-- 此处应用系统的环境变量 -->
14
15 < property environment ="env" />
16
17 <!-- SDK Locations -->
18
19 <!-- 获取SDK的安装目录,注意在我的系统中环境变量的名称为ANDROID_SDK_HOME,你可以修改成你的环境变量名称 -->
20 <!-- 也可以直接指定路径,下面采用的就是这种方式 -->
21 < property name ="sdk2.2-folder" value ="F:\sdk\android-sdk-windows" />
22
23 <!-- 如若你使用的android版本不一样,可以在此处修改 -->
24 < property name ="sdk-folder" value ="${sdk2.2-folder}/platforms/android-8" />
25
26 < property name ="android.aidl" value ="${sdk-folder}/framework.aidl" />
27 < property name ="sdk-tools" value ="${sdk-folder}/tools" />
28 < property name ="android-tools" value ="${sdk2.2-folder}/tools" />
29
30
31 < property name ="verbose" value ="false" />
32
33 <!-- 配置使用到的库,只要保证路径正确,不需修改 -->
34
35 < path id ="android.antlibs" >
36 < pathelement location ="${env.ANDROID_SDK_HOME}/tools/lib/anttasks.jar" />
37 < pathelement location ="${env.ANDROID_SDK_HOME}/tools/lib/sdklib.jar" />
38 < pathelement location ="${env.ANDROID_SDK_HOME}/tools/lib/androidprefs.jar" />
39 </ path >
40
41
42 <!-- step 1.generate R.java by aapt 2.compile java to class by javac 3.generate classes.dex by dx.bat -->
43 <!-- 4.package resources by aapt 5. package resource and classes.dex by apkbuilder.bat 6.sign apk by jarsinger -->
44
45 <!-- 配置在整个过程中使用到的Tools,不需修改 -->
46 < property name ="aapt" value ="${sdk-tools}/aapt.exe" />
47 < property name ="dx" value ="${sdk-tools}/dx.bat" />
48 < property name ="apk-builder" value ="${android-tools}/apkbuilder.bat" />
49 < property name ="aidl" value ="${sdk-tools}/aidl.exe" />
50 < property name ="adb" value ="${android-tools}/adb.exe" />
51 < property name ="android-jar" value ="${sdk-folder}/android.jar" />
52 < property name ="jarsigner" value ="${env.JAVA_HOME}/bin/jarsigner.exe" />
53
54 <!-- Android项目使用到所有库,这个地方需修改 -->
55 < path id ="android.libraries.jars" >
56 < pathelement location ="${android-jar}" />
57 < pathelement location ="${basedir}/lib/commons-pool-1.5.4.jar" />
58 </ path >
59
60
61 <!-- Application Package Name,包名需修改 -->
62 < property name ="application-package" value ="com.android.ant" />
63
64 <!-- 以下都不需要修改 -->
65 < property name ="useragent" value ="byAndroidWeb" />
66 < property name ="version" value ="1.02" />
67 <!-- The intermediates directory -->
68
69 <!-- Eclipse uses "bin" for its own output, so we do the same. -->
70 < property name ="outdir-bin" value ="bin" />
71 < property name ="outdir-gen" value ="gen" />
72 <!-- source directories -->
73 < property name ="resource-dir" value ="res" />
74 < property name ="asset-dir" value ="assets" />
75 < property name ="srcdir" value ="src" />
76 < property name ="srcdir-ospath" value ="${basedir}/${srcdir}" />
77 < property name ="external-libs" value ="lib" />
78 < property name ="external-libs-ospath" value ="${basedir}/${external-libs}" />
79
80 <!-- dest directories -->
81 < property name ="des-resource-dir" value ="${outdir-bin}/res" />
82 < property name ="des-asset-dir" value ="${outdir-bin}/assets" />
83 < property name ="des-srcdir" value ="${outdir-bin}/src" />
84 < property name ="des-srcdir-ospath" value ="${basedir}/${outdir-bin}/${srcdir}" />
85 < property name ="des-external-libs" value ="${outdir-bin}/libs" />
86 < property name ="des-external-libs-ospath" value ="${basedir}/${outdir-bin}/${external-libs}" />
87
88 <!-- Output directories -->
89 < property name ="outdir-classes" value ="${outdir-bin}/src" />
90 < property name ="outdir-obfuscate-classes" value ="${outdir-bin}" />
91 < property name ="outdir-obfuscate-classes-ospath" value ="${basedir}/${outdir-obfuscate-classes}" />
92
93 <!-- Intermediate files -->
94 < property name ="dex-file" value ="classes.dex" />
95 < property name ="intermediate-dex" value ="${outdir-bin}/${dex-file}" />
96 < property name ="intermediate-dex-ospath" value ="${basedir}/${intermediate-dex}" />
97
98 <!-- The final package file to generate -->
99 < property name ="resources-package" value ="${outdir-bin}/${ant.project.name}" />
100 < property name ="resources-package-ospath" value ="${basedir}/${resources-package}" />
101 < property name ="out-debug-package" value ="${outdir-bin}/${ant.project.name}-debug.apk" />
102 < property name ="out-debug-package-ospath" value ="${basedir}/${out-debug-package}" />
103 < property name ="out-unsigned-package" value ="${outdir-bin}/${ant.project.name}-unsigned.apk" />
104 < property name ="out-unsigned-package-ospath" value ="${basedir}/${out-unsigned-package}" />
105 < property name ="out-signed-package" value ="${useragent}\${ant.project.name}.apk" />
106 < property name ="out-signed-package-ospath" value ="${basedir}\${out-signed-package}" />
107
108
109 <!-- init -->
110 < target name ="init" >
111 < echo >Creating all output directories </ echo >
112 < delete dir ="${outdir-bin}" />
113 < mkdir dir ="${outdir-bin}" />
114 < mkdir dir ="${outdir-classes}" />
115 </ target >
116
117 <!-- copy original strings and modify useragent -->
118 < target name ="copy" depends ="init" >
119 < echo >copy files to output folder </ echo >
120 </ target >
121
122
123 <!-- Generate the R.java file for this project's resources. -->
124
125 < target name ="resource-src" depends ="copy" >
126 < echo >Generating R.java / Manifest.java from the resources
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
127 < echo >${aapt} </ echo >
128 < exec executable ="${aapt}" failonerror ="true" >
129 < arg value ="package" />
130 < arg value ="-m" />
131 < arg value ="-J" />
132 < arg value ="${outdir-gen}" />
133 < arg value ="-M" />
134 < arg value ="AndroidManifest.xml" />
135 < arg value ="-S" />
136 < arg value ="${resource-dir}" />
137 < arg value ="-I" />
138
139 < arg value ="${android-jar}" />
140 </ exec >
141 </ target >
142
143
144 <!-- Generate java classes from .aidl files. -->
145 < target name ="aidl" depends ="copy" >
146 < echo >Compiling aidl files into Java classes
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
147 < apply executable ="${aidl}" failonerror ="true" >
148 < arg value ="-p${android.aidl}" />
149 < arg value ="-I${srcdir}" />
150 < fileset dir ="${srcdir}" >
151 < include name ="**/*.aidl" />
152 </ fileset >
153 </ apply >
154 </ target >
155
156 <!-- Compile this project's .java files into .class files. -->
157 < target name ="compile" depends ="copy, resource-src, aidl" >
158 < javac encoding ="ascii" target ="1.6" debug ="true" extdirs ="" srcdir ="." destdir ="${outdir-classes}" bootclasspathref ="android.libraries.jars" >
159 < classpath >
160 < fileset dir ="${external-libs}" includes ="*.jar" />
161 </ classpath >
162 </ javac >
163 </ target >
164
165 <!-- Convert this project's .class files into .dex files. -->
166 < target name ="dex" depends ="compile" >
167 < echo >Converting compiled files and external libraries into ${outdir}/${dex-file}
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
168 < apply executable ="${dx}" failonerror ="true" parallel ="false" >
169 < arg value ="--dex" />
170
171 < arg value ="--output=${intermediate-dex-ospath}" />
172 < arg path ="${outdir-obfuscate-classes-ospath}" />
173 < fileset dir ="${external-libs}" includes ="*.jar" />
174 </ apply >
175 </ target >
176
177 <!-- Put the project's resources into the output package file. -->
178 < target name ="package-res-and-assets" >
179 < echo >Packaging resources and assets
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
180 < exec executable ="${aapt}" failonerror ="true" >
181 < arg value ="package" />
182 < arg value ="-f" />
183 < arg value ="-M" />
184 < arg value ="AndroidManifest.xml" />
185 < arg value ="-S" />
186 < arg value ="${resource-dir}" />
187 < arg value ="-A" />
188 < arg value ="${asset-dir}" />
189 < arg value ="-I" />
190 < arg value ="${android-jar}" />
191 < arg value ="-F" />
192 < arg value ="${resources-package}" />
193 </ exec >
194 </ target >
195
196 <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
197 < target name ="package-res-no-assets" >
198 < echo >Packaging resources
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
199 < exec executable ="${aapt}" failonerror ="true" >
200 < arg value ="package" />
201 < arg value ="-f" />
202 < arg value ="-M" />
203 < arg value ="AndroidManifest.xml" />
204 < arg value ="-S" />
205 < arg value ="${resource-dir}" />
206 <!-- No assets directory -->
207 < arg value ="-I" />
208 < arg value ="${android-jar}" />
209 < arg value ="-F" />
210 < arg value ="${resources-package}" />
211 </ exec >
212 </ target >
213
214 <!-- Invoke the proper target depending on whether or not
215 an assets directory is present. -->
216 <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
217 only when the assets dir exists. -->
218 < target name ="package-res" >
219 < available file ="${asset-dir}" type ="dir" property ="res-target" value ="and-assets" />
220 < property name ="res-target" value ="no-assets" />
221 < antcall target ="package-res-${res-target}" />
222 </ target >
223
224 <!-- Package the application and sign it with a debug key.
225 This is the default target when building. It is used for debug. -->
226 < target name ="debug" depends ="dex, package-res" >
227 < echo >Packaging ${out-debug-package}, and signing it with a debug key
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
228 < exec executable ="${apk-builder}" failonerror ="false" >
229 < arg value ="${out-debug-package-ospath}" />
230 < arg value ="-z" />
231 < arg value ="${resources-package-ospath}" />
232 < arg value ="-f" />
233 < arg value ="${intermediate-dex-ospath}" />
234 < arg value ="-rf" />
235 < arg value ="${srcdir-ospath}" />
236 < arg value ="-rj" />
237 < arg value ="${external-libs-ospath}" />
238 </ exec >
239 </ target >
240
241 <!-- Package the application without signing it.
242 This allows for the application to be signed later with an official publishing key. -->
243 < target name ="package" depends ="dex, package-res" >
244 < echo >Packaging ${out-unsigned-package} for release
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
245 < exec executable ="${apk-builder}" failonerror ="true" >
246 < arg value ="${out-unsigned-package-ospath}" />
247 < arg value ="-u" />
248 < arg value ="-z" />
249 < arg value ="${resources-package-ospath}" />
250 < arg value ="-f" />
251 < arg value ="${intermediate-dex-ospath}" />
252 < arg value ="-rf" />
253 < arg value ="${srcdir-ospath}" />
254 < arg value ="-rj" />
255
256 < arg value ="${external-libs-ospath}" />
257 </ exec >
258 < echo >It will need to be signed with jarsigner before being published. </ echo >
259 </ target >
260
261 < target name ="jarsigner" depends ="package" >
262 < echo >Packaging ${out-unsigned-package} for release
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
263 < exec executable ="${jarsigner}" failonerror ="true" >
264 < arg value ="-verbose" />
265 < arg value ="-storepass" />
266 < arg value ="byread002" />
267 < arg value ="-keypass" />
268 < arg value ="byread002" />
269 < arg value ="-keystore" />
270 < arg value ="bbyread.keystore" />
271 < arg value ="-signedjar" />
272 < arg value ="${out-signed-package-ospath}" />
273 < arg value ="${out-unsigned-package-ospath}" />
274 < arg value ="byread" />
275 </ exec >
276 </ target >
277
278 < target name ="release" depends ="jarsigner" >
279 < echo >release for release
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
280 </ target >
281
282 <!-- Install the package on the default emulator -->
283 < target name ="install" depends ="debug" >
284 < echo >Installing ${out-debug-package} onto default emulator
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
285 < exec executable ="${adb}" failonerror ="true" >
286 < arg value ="install" />
287 < arg value ="${out-debug-package}" />
288 </ exec >
289 </ target >
290
291 < target name ="reinstall" depends ="debug" >
292 < echo >Installing ${out-debug-package} onto default emulator
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
293 < exec executable ="${adb}" failonerror ="true" >
294 < arg value ="install" />
295 < arg value ="-r" />
296
297 < arg value ="${out-debug-package}" />
298 </ exec >
299 </ target >
300
301 <!-- Uinstall the package from the default emulator -->
302 < target name ="uninstall" >
303 < echo >Uninstalling ${application-package} from the default emulator
![](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
304 < exec executable ="${adb}" failonerror ="true" >
305 < arg value ="uninstall" />
306 < arg value ="${application-package}" />
307 </ exec >
308 </ target >
310 </ project >