使用Jenkins Build Android心得

本文详细介绍了如何在Windows7上部署Jenkins并构建Android应用。从Android的构建过程开始,包括aapt、aidl、Java编译、dex转换等步骤,然后逐步指导安装Jenkins、配置JDK和ANT,以及设置Jenkins插件和项目配置。最终通过Jenkins Job实现自动化构建和邮件通知。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android Build Process

http://developer.android.com/tools/building/index.html

 

The build processinvolves many tools and processes that generate intermediate files on the wayto producing an .apk.If you are developing in Eclipse, the complete build process is automaticallydone periodically as you develop and save your code changes. If you are usingother IDEs, this build process is done every time you run the generated Antbuild script for your project. It is useful, however, to understand what ishappening under the hood since much of the tools and processes are masked fromyou. The following diagram depicts the different tools and processes that areinvolved in a build:

The general process for a typicalbuild is outlined below:

·        The Android Asset Packaging Tool(aapt) takes your application resource files, such as the AndroidManifest.xml file and the XML files for your Activities, and compiles them.An R.java is also produced so you can reference your resources from yourJava code.

·        The aidl tool converts any .aidl interfaces that you have into Java interfaces.

·        All of your Java code, includingthe R.java and .aidl files, are compiled by the Java compiler and .class files areoutput.

·        The dex tool converts the .classfiles to Dalvik byte code. Any 3rd party libraries and .class files that youhave included in your project are also converted into .dex files so that they can be packaged into the final .apk file.

·        All non-compiled resources (suchas images), compiled resources, and the .dex files are sent to the apkbuildertool to be packaged into an .apk file.

·        Once the .apk is built, it must be signed with either a debug or release keybefore it can be installed to a device.

·        Finally, if the application isbeing signed in release mode, you must align the .apk with the zipalign tool. Aligning the final .apk decreases memory usage when the application is running on adevice.

 


Deploy Jenkins on Windows7

Install

Download Ant.

You can obtainit from the Apache Ant home page.

Download Android SDK

         http://developer.android.com/sdk/index.html

Download Jenkins

         http://jenkins-ci.org/

Download JDK

         http://www.oracle.com/us/downloads/index.html

建议安装顺序JDK, Android SDK, Ant, Jenkins

配置

JDK&ANT

         可以设置JDK和ANT的环境变量,也可以稍后在Jenkins系统管理页面制定。基本的安装和设定网上有很多教程,不再重复,可以访问127.0.0.1:8080之后才有点特殊。

        

Jenkins启动

         Start:        Jenkins.exe start

         Stop:         Jenkins.exe stop

         Restart:   Jenlins.exe restart

Jenkins配置

         因为需求是可以每天定时Build不同版本APK,并且可以将,APK,Build结果,静态代码分析等结果,发邮件通知相关人员。

         进入Jenkins-> 系统管理 -> 系统设置

         Jenkins Location

                   JenkinsURL 这个URL用于在邮件中生成有关的链接。最好指向一个域名。

                   SystemAdmin e-mail address 管理员的Email,这里一定要设置对,不然后面Mail Server设置时候测试可能失败。

        

         Subversion

                   建议选最新的

 

         邮件通知

                   指定好SMTP服务器地址,端口号,用户名,密码就可以。

 

Jenkins插件

         确认安装Subversion Plugin, Email-ext plugin。建议把FindBugs给装上。

 

项目配置

         给Project添加ANT支持。找到SDK中的android.bat在命令行下执行

android update project –p android-app –txxx

 

成功的话,尝试用 ant debug应该成功build

         添加了ANT之后,在项目目录下会多了一个build.xml。一般Android在Eclipse中创建的时候是不带这个ANT支持的,如果是这种情况,等创建Jenkins Job好,执行一次后,也就是SVN checkout 后,找到Project,再执行android update。

         添加签名信息:

         在build.xml相同目录下,新建一个ant.properties,里面填入如下内容,build时候会检测这个文件,读取里面keystore的设置。

                 

        

Jenkins Job

         在Jenkins 首页左边的选项中,选择“新建”,新建一个任务,选择“构建一个自由风格的软件项目”。

         源码管理:选择Subversion,输入ProjectSVN address. 以及验证信息。

         触发器:可以设置定时执行任务。

         构建:先添加一个InvokeAnt。Ant version 选择Default。Targets就是build.xml中的target。如果是build.xml是默认的,可以选择release, debug等。由于为了发多渠道的APK。这里自定义了Build.xml,所以Target也是自定义的releaseAll。具体Build.xml 后面再细说。

         如果还要执行自定的脚本,可以加在这里。例如,我这里加了一个自定义的jar。添加Execute Windows batch command,命令是“java –jarD:\misc\copy.jar”希望Build之后执行copy.jar,用来复制生成的APK到制定目录,并生成信息(APK的描述,下载链接等),写入一个文件,稍后把这些内容作为邮件的一部分。

 

构建后操作:添加一个EditableEmail Notification。用于构建后发邮件,特殊的是,邮件的内容,两部分,第一行是读取上面说的copy.jar生成的内容。第二行是邮件模板,这里用的是dd.groovy.template。

        

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值