基于Jenkins + Ant + Tomcat 的安卓客户端可持续化构建及发布下载

一. Jenkins 可持续化构建环境请参考 文章 http://my.oschina.net/long0419/blog/183299

二. 基于搭好可持续构建环境完成基础上 ,使用Ant 来编写安卓持续化构建环境 (未使用gradle 原理一样)

1、首先要去官网下载ANT代码。

ANT官网下载地址

2、下载ANT循环打包JAR包。

ANT循环JAR包下载地址

网盘下载地址

3、解压得到其中的ant-contrib-1.0b3.jar文件待用。

做完以上3步,ANT多渠道打包所需要的软件就准备完毕了,接下来就是环境配置了(略去)。

4. 打包过程 总共需要编辑4个文件,分别为build.xml、local.properties、customrules.xml、ant.properties. 同时准备好自己的签名文件:androidkey.keystore。

1、编辑local.properties文件内容,主要是配置SDK路径及项目路径

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
#SDK的路径地址
sdk.dir=E:\\Android\\android-studio\\sdk  
#项目路径地址
project.dir=F:\\Android\\sourceCode\\Test

2、编辑ant.properties,主要是配置ANT打包的数据

#项目包名
application.package=com.ecloud.test  
#项目名称
ant.project.name=test  
#项目编码,这里需要注意自己工程的编码格式,需要保证编码格式一致(可不使用)
#java.encoding=utf-8   
#编译中间文件生成目录
out.absolute.dir=F:/Test/compile  
#最终APK生成文件目录
gos.path=F:/Test/test-code1-20140523  
#签名文件全路径
key.store=F:/Test/Test/android_key.keystore 
#签名文件密码
key.store.password=111111  
#别名,这里要注意如果你签名文件的别名为中文,需要和我这个一样转成16进制,不然签名的时候会报错,转码可以用【UltraEdit工具】(自行百度下载)来做。
key.alias=\u5BB9\u6613\u901B  
#别名密码
key.alias.password=111111  
#软件版本号
app_version=1.0.0
#需要打包的渠道名,注意‘,’分格
market_channels=Gfan,3G,360,AndMarket,AnZi

3、编辑custom_rules.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules" >
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" >
        <classpath>
        <!--注意这里要和你拷贝的那个JAR文件相同-->
            <pathelement location="lib/ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>
    <target name="deploy" >
        <foreach
            delimiter=","
            list="${market_channels}"
            param="channel"
            target="modify_manifest" >
        </foreach>
    </target>
    <target name="modify_manifest" >
       <replaceregexp flags="g" byline="false">  
       <regexp pattern="android:value=&quot;(.*)&quot; android:name=&quot;UMENG_CHANNEL&quot;" />  
         <substitution expression="android:value=&quot;{channel}&quot; android:name=&quot;UMENG_CHANNEL&quot;" />  
           <fileset
                dir=""
                includes="AndroidManifest.xml" />
        </replaceregexp>
        <property
            name="out.final.file"
            location="${apk.dir}/${ant.project.name}_${channel}.apk" />
        <antcall target="clean" />
        <antcall target="debug" />
    </target>
</project>

4、编辑最终的build.xml文件,这个是才是循环打包的重点

<?xml version="1.0" encoding="UTF-8"?> <!-- 项目名称test,可用全局替换为当前项目名称 -->
    <project
        name="test"
        default="deploy" > <!-- The local.properties file is created and updated by the ‘android‘ tool.
         It contains the path to the SDK. It should *NOT* be checked into
         Version Control Systems. -->
    <property file="local.properties" /> <!-- The ant.properties file can be created by you. It is only edited by the
         ‘android‘ tool to add properties to it.
         This is the place to change some Ant specific build properties.
         Here are some properties you may want to change/update:
         source.dir
             The name of the source directory. Default is ‘src‘.
         out.dir
             The name of the output directory. Default is ‘bin‘.
         For other overridable properties, look at the beginning of the rules
         files in the SDK, at tools/ant/build.xml
         Properties related to the SDK location or the project target should
         be updated using the ‘android‘ tool with the ‘update‘ action.
         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems. -->
    <property file="ant.properties" />
    <property
        name="manifest.file"
        value="AndroidManifest.xml" >
    </property>
    <property
        name="bin.dir"
        value="bin" >
    </property>
    <property
        name="absolute-out"
        value="${project.dir}/${bin.dir}" >
    </property>
    <property
        name="absolute-file-manifest-out"
        value="${absolute-out}/${manifest.file}" >
    </property>
    <property
        name="absolute-file-manifest-src"
        value="${project.dir}/${manifest.file}" >
    </property> <!-- The project.properties file is created and updated by the ‘android‘
         tool, as well as ADT.
         This contains project specific properties such as project target, and library
         dependencies. Lower level build properties are stored in ant.properties
         (or in .classpath for Eclipse projects).
         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems. -->
    <loadproperties srcFile="project.properties" />
    <fail
        message="sdk.dir is missing. Make sure to generate local.properties using &apos;android update project&apos; or to inject it through an env var"
        unless="sdk.dir" /> <!-- extension targets. Uncomment the ones where you want to do custom work
     in between standard targets -->
    <!-- <target name="-pre-build">
    </target>
    <target name="-pre-compile">
    </target>
   
    <target name="-post-compile">
    </target> -->
    <!-- Import the actual build file.
         To customize existing targets, there are two options:
         - Customize only one target:
             - copy/paste the target into this file, *before* the
               <import> task.
             - customize it to your needs.
         - Customize the whole content of build.xml
             - copy/paste the content of the rules files (minus the top node)
               into this file, replacing the <import> task.
             - customize to your needs.
         ***********************
         ****** IMPORTANT ******
         ***********************
         In all cases you must update the value of version-tag below to read ‘custom‘ instead of an integer,
         in order to avoid having your file be overridden by tools such as "android update project" -->
    <!-- version-tag: 1 -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" >
<!---->
######注意这里的JAR包路径,要修改成自己的
        <classpath>
            <pathelement location="D:/Ant/lib/ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>
    <import file="${sdk.dir}/tools/ant/build.xml" />
    <target name="deploy" >
        <foreach
            delimiter=","
            list="${market_channels}"
            param="channel"
            target="modify_manifest" >
        </foreach>
    </target>   
<!-- -->
######这里就是修改渠道号的代码,我的渠道值设置的是SETTING_UMENG_CHANNEL_CHANNELID_VALUES你可以替换成你自己的
       <target name="modify_manifest" > <!-- <copy file="${absolute-file-manifest-src}" tofile="${absolute-file-manifest-out}" overwrite="true"/>
        <replace file="${absolute-file-manifest-out}" token="SETTING_UMENG_CHANNEL_CHANNELID_VALUES" value="${channel}" encoding="UTF8"/> -->
        
        <replaceregexp
            encoding="utf-8"
            file="AndroidManifest.xml"
            match="SETTING_UMENG_CHANNEL_CHANNELID_VALUES"
            replace="${channel}" /> <!-- <replaceregexp
            byline="false"
            flags="g" >
            <regexp pattern="android:name="UMENG_CHANNEL" android:value="(.*)" />
            <substitution expression="android:name="UMENG_CHANNEL" android:value="${channel}" />
           
            <fileset
                dir=""
                includes="AndroidManifest.xml" />
                        
        </replaceregexp> -->
        <!-- <property  name="out.release.file" value="${out.absolute.dir}/${channel}.apk"/> -->
        <antcall target="release" />
        <copy tofile="${gos.path}/test_${channel}.apk" >
            <fileset
                dir="${out.absolute.dir}/"
                includes="test-release.apk" />
        </copy>
        <delete includeEmptyDirs="true" >
            <fileset
                dir="${out.absolute.dir}"
                includes="**/*" />
        </delete>  
<!---->
######这里要将替换之后的渠道号值改成默认的值SETTING_UMENG_CHANNEL_CHANNELID_VALUES,不然下一个打包时将不会替换渠道号的值
        <replaceregexp
            encoding="utf-8"
            file="AndroidManifest.xml"
            match="${channel}"
            replace="SETTING_UMENG_CHANNEL_CHANNELID_VALUES" />
        <echo message="===========================" />
    </target>
   </project>

5、把以上4个文件拷贝到项目根目录下,目录结构如下

test--
    --src
    --res
    --libs
    --local.properties
    --custom_rules.xml
    --ant.properties
    --build.xml

6、打开CMD,然后CD到项目根路径下,运行ant deploy即可。注意在运行之前要注意先clean一下项目,不然可能会报错误,切记!!!!

BUILD FAILED
F:\Test\Test\build.xml:113: The following error occurred while executing this line:
F:\Test\Test\build.xml:139: The following error occurred while executing this line:

7、如果你看到BUILD SUCCESS,那么恭喜你,多渠道打包编译成功了,去输出目录查看一下APK文件吧!

错误说明:

a.提示如下

Android build failing with build.xml:479: SDK does not have any Build Tools installed

表示当前sdk 版本过低只需要在控制台中执行下命令行后更新安卓sdk版本即可

android update sdk -u

三 . 当已经构建完成后返回Jenkins 中进行后续配置 截图如下:

由于还使用了每天23点定时构建还需做如下配置

然后执行完把构建后的apk全部移动到web容器中 使用shell 脚本执行

cp ./tmp/diandi100-*.apk /home/test/apache-tomcat-7.0.52/webapps/filedownload/files
rm -rf ./tmp/*.*

三 .在web 容器中发布 然后提供下载

由于可以让在tomcat 中执行下载操作 首先可以在eclipse 中随意建立一个web 工程然后将tomcat conf 目录中的web.xml中的list 熟悉修改为true 即可 然后访问web工程目录如下显示 :

后续只需要根据需求下载对面版本安装测试

*-release.apk :签名优化版本

*-release-unaligned.apk :签名版本

*-release-unsigned.apk :未签名版本

时间: 2024-08-13 14:15:50

基于Jenkins + Ant + Tomcat 的安卓客户端可持续化构建及发布下载的相关文章

基于Bmob后台的AutoBank安卓客户端(实习最后两天)

前段时间完成了AutoBank的网站端 http://blog.csdn.net/jkxqj/article/details/42651295 昨天抽时间把老师要求的AutoBank安卓客户端做完了.听同学说Bmob对移动开发者很方便,于是试了一下,果然很好用. 客户端的源代码上传到CSDN的code仓库.https://code.csdn.net/acmjk/autobank_for_android/tree/master

jenkins+ant+jmeter接口自动化测试(持续构建)

使用badboy录制脚本,到处到jmeter后进行接口自动化,后来想着 可不可以用自动化来跑脚本呢,不用jmeter的图形界面呢, 选择了ant来进行构建,最后想到了用Jenkins来进行持续构建接口测试. 上一篇讲到了badboy录制jmeter脚本后,可以在jmeter进行回访, 其实也可以直接在jmeter进行录制脚本,我们打开jmeter, 打开我们的代理服务器,然后设置 设置后呢,我们点击启动,这样就可以启动代理服务器了,  我录的是手机,所以呢,我在cmd 输入ipconfig获取地

基于Jenkins和Koji的代码管理及构建系统

Summary Currently, we KVM team are maintaining the code repository of the virtualization software(such as QEMU, Libvirt, Kimchi, Linux, etc.) for PowerKVM development team and delivering corresponding RPM packages. We collect patches from mailing lis

Jenkins+svn+ant+tomcat持续集成

Jenkins是基于Java开发的一种持续集成工具,用于监控秩序重复的工作.通过Jenkins+svn+ant+tomcat整合,可以完成对系统源代码的下载更新,以及代码的自动编译打包和项目的自动部署工作,而且项目的自动构建与平台无关,可以定时操作,从而使得测试人员脱离开发人员. 1.Jenkins工作原理 Jenkins是一个管理者,定时从svn获取更新的代码,拷贝到自己的workspace,然后利用ant将源码编译并生成war包,拷贝到tomcat的webapp目录下,再调用tomcat启动

XMPP(二)-基于asmack+openfire的安卓客户端(仿QQ)的介绍以及个人心得

关于XMPP第一篇-openfire的搭建写完后,就一直在赶本篇所要介绍的这个基于asmack+openfire的安卓客户端,费了不少精力,因为有不少同学在还在焦急的等待着(自恋了呵呵),所以紧赶慢赶,现在算做出来了一个比较初级的版本,很多功能还不完善,不过先放出来,供大家一起参考研究,提出问题,共同学习,当然,该项目本人是会不断完善,增加新功能,甚至到后来的群组,有兴趣的话,大家可以继续关注^-^ 好了,接下来介绍下本项目实现的功能吧: 1.注册: 2.登录: 3.依昵称查找人员: 4.添加好

基于 Jenkins 快速搭建持续集成环境

持续集成是一种软件开发实践,对于提高软件开发效率并保障软件开发质量提供了理论基础.Jenkins 是一个开源软件项目,旨在提供一个开放易用的软件平台,使持续集成变成可能.本文正是从持续集成的基本概念入手,通过具体实例,介绍了如何基于 Jenkins 快速搭建持续集成环境. 持续集成概述 什么是持续集成 随着软件开发复杂度的不断提高,团队开发成员间如何更好地协同工作以确保软件开发的质量已经慢慢成为开发过程中不可回避的问题.尤其是近些年来,敏捷(Agile) 在软件工程领域越来越红火,如何能再不断变

基于Jenkins的自动构建系统开发_android总结

持续集成相关理论 1.1 极限编程的概述 1.1.1 极限编程的产生 2001年,为了解决许多公司的软件团队陷入不断增长的过程泥潭,一批业界专家一起概括出了一些可以让软件开发团队具有快速工作.响应变化能力的价值观和原则,他们称自己为敏捷联盟.敏捷开发过程的方法很多,主要有:SCRUM,Crystal,特征驱动软件开发(Feature Driven Development,简称FDD),自适应软件开发(Adaptive Software Development,简称ASD),以及最重要的极限编程(

基于jenkins搭建一个持续集成服务器

1 引言 1.1 编写目的 指导质量管理部,业务测试组同事进行Jenkins环境部署,通过Jenkins解决测试环境不可控,开发测试环境不一致等问题. 1.2 使用对象 质量管理部.基础研发部,集成部署部及EMT 目标受众: 本文的预期受众是从事持续交付或持续自动测试工作的软件工程师.要想按照本文中的步骤进行操作,您应该理解: 脚本开发. 软件开发流程. 1.3 持续集成概述 1.3.1 什么是持续集成 随着软件开发复杂度的不断提高,团队开发成员间如何更好地协同工作以确保软件开发的质量已经慢慢成

【源码】c#编写的安卓客户端与Windows服务器程序进行网络通信

用c#开发安卓程序 (xamarin.android)系列之三 源码(包含客户端与服务器端所有工程文件)    数据库文件 为了方便您测试,我临时搭建了一个服务器  您可以安装apk文件,直接测试  apk文件下载地址  (测试服务器将会运行至2015年3月1日) 通信框架为来自英国的NetworkComms2.3.1开源通信框架    序列化采用Protobuf.net开源框架 客户端界面如下:        服务器端程序界面: 服务器搭建在winserver2003 上,基于.net4.0.