博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在Hudson中,使用ant自动对安卓项目编译打包apk
阅读量:7174 次
发布时间:2019-06-29

本文共 3866 字,大约阅读时间需要 12 分钟。

      本文对如何在hudson中配置ant编译打包apk进行说明,主要包括build.xml文件的编写、环境的配置、在Hudson中创建任务。

一、为安卓项目创建build.xml文件

1、打开cmd进入sdk目录下的tools目录,输入: android.bat list target  来查询我们现有的版本list有哪些。如下图:

途中用红框圈出的 id 与蓝框圈出的版本号对应关系,下面需要用到。

2、打开安卓项目工程下的 project.properties 文件,查看target 版本号,如下图:

3、使用命令 android update project -n WebviewSession -t 19 -p E:\Lenovocw\▲技术解决方案\安卓Webview的Session传递\WebviewSession 在工程下生成build.xml文件,如下图所示:

-n 对应的是项目名称

-t  就是我们之前查询的SDK版本对应的ID,大家根据自己的项目版本做出选择即可,我这个是android 4.4.2 所以用ID 19
-p 就是生成的路径

此时,项目中自动生成了 build.xml 和 local.properties 2个文件

查看在 build.xml 文件可以发现,build.xml 文件读取了local.properties 和 ant.properties 2个配置文件,最后引用了 sdk 下面的 build.xml 文件。

如果我们需要在订制自己的target,需要用到一些配置参数,我们把它放到 local.properties 中即可,生成的 local.properties 文件中已自动指定了我们的sdk目录。

4、配置签名证书的信息,让 ant 为我们自动打包并使用我们 配置的证书进行签名

在项目工程下添加 ant.properties 文件,配置我们的证书信息,如下图所示:

至此,我们可以对android 项目进行ant 打包了。

如果我们项目引用了外部jar包,使用Ant Build构建项目时出现的"crunch" 错误,如下:

-code-gen:[mergemanifest] Found Deleted Target File[mergemanifest] Merging AndroidManifest files into one.[mergemanifest] Manifest merger disabled. Using project manifest only.     [echo] Handling aidl files...     [aidl] No AIDL files to compile.     [echo] ----------     [echo] Handling RenderScript files...     [echo] ----------     [echo] Handling Resources...     [aapt] Generating resource IDs...     [aapt] invalid resource directory name: F:\workspace\Zlib\bin\res/crunch  BUILD FAILEDD:\Android\sdk\tools\ant\build.xml:601: The following error occurred while executing this line:D:\Android\sdk\tools\ant\build.xml:653: The following error occurred while executing this line:D:\Android\sdk\tools\ant\build.xml:698: null returned: 1
出现以上编译错误,解决办法如下:
方法1:在系统tool/ant/build.xml文件中赋值<property name="aapt.ignore.assets" value="crunch" />
方法2:在自己项目build文件中添加<property name="aapt.ignore.assets" value="!.svn:!.git:\x3Cdir\x3E_*:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~:crunch" />

不想去修改sdk内部的build.xml 文件,所以我在项目中生成的 build.xml 文件使用了方法2做了配置。

下面是我的项目下 build.xml 的代码,提供参考。

二、在服务器上配置android-sdk环境(我用的是linux系统,window是开发环境不再单独说明,使用是一样的)

下载 Linux 版本的 android-sdk ,上传到服务器上,解压缩包后的目录结构如下所示:

android-sdk-linux

 - tools

- android

- ant

- apps

- ddms

- draw9patch

- emulator

- emulator64-arm

- emulator64-mips

- emulator64-x86

- emulator-arm

- emulator-mips

- emulator-x86

- hierarchyviewer

- jobb

- lib

- lint

- mksdcard

- monitor

- monkeyrunner

- NOTICE.txt

- proguard

- screenshot2

- source.properties

- support

- templates

- traceview

- uiautomatorviewer

 - platform-tools

- adb

- api

- dmtracedump

- etc1tool

- fastboot

- hprof-conv

- NOTICE.txt

- source.properties

- sqlite3

- systrace

 - platforms

- android-19

 - build-tools

- 20.0.0

三、在Hudson中创建任务(至于怎么安装hudson,这里就不做赘述了)

1、在hudson中新建一个任务,输入ProjectName,一般我们勾选“Use custom workspace”使用自己的工作空间目录,如下图:

2、配置SVN信息,hudson会根据我们配置的SVN信息帮我们从svn中更新代码,如下图所示:

3、我们可以根据需要勾选Build perodically Schedule,这个是交给hudson自动帮我们在指定的时间内执行这个任务,如下图所示:

     关于表达式的配置可以点击后面的问号查看简单的说明,输入的内容可以是多行的。

4、配置ant 

     选择已经安装的ant,指定build.xml中需要执行的targets,指定build.xml 文件(. 开头是相对路径,也可以使用绝对路径),然后可以在Properties中输入我们需要在build.xml文件中需要的变量,用key=value的格式编写,每行写一个键值对。

5、点击底部的保存按钮保存任务。

--------------------------------------------

备注:

如果在Linux上使用ant编译打包apk的时候,出现下面的错误:

/usr/local/android-sdk-linux/tools/ant/build.xml:698: Execute failed: java.io.IOException: Cannot run program "/usr/local/android-sdk-linux/build-tools/22.0.0/aapt": error=2, No such file or directory

解决方案详见:http://blog.csdn.net/catoop/article/details/47157631

你可能感兴趣的文章
Android数据缓存(转)
查看>>
用 windows GDI 实现软光栅化渲染器--gdi3d(开源)
查看>>
Jenkins快速上手
查看>>
Android 工程目录结构简介
查看>>
HashMap、HashTable、LinkedHashMap和TreeMap用法和区别
查看>>
ubuntu解决arm-linux-gcc no such file的问题
查看>>
Activity设置singleTask无法通过Intent获取值的问题
查看>>
python之模块copy,了解概念即可
查看>>
还是回文(dp)
查看>>
oracle创建表
查看>>
解决 Eclipse build workspace 慢,validation javascript 更慢的问题
查看>>
jquery ajax验证用户名是否存在(后台spring mvc)
查看>>
WPF控件--利用Winform库中的NotifyIcon实现托盘小程序
查看>>
动物统计加强版(贪心,字典序)
查看>>
LeetCode - 15. 3Sum
查看>>
Hadoop 之 MapReduce 框架演变详解
查看>>
linux下获取硬盘使用情况
查看>>
最少拦截系统(杭电1257)(DP)+(贪心)
查看>>
java.lang.OutOfMemoryError: Java heap space
查看>>
Mybatis拦截器介绍及分页插件
查看>>