Jenkins中的Android打包任务设计

Jenkins持续集成Unity游戏项目

Jenkins的安装部署和配置

Jenkins中的Android打包任务设计

Jenkins中的iOS打包任务设计

Jenkins中的测试任务设计 #Jenkins中的Android打包任务设计 #实现界面 实现界面 #Unity项目的结构

打包结构

Untiy代码管理中分支是上线的版本,所以主要以它为版本进行分析。 Unity导出时候分三个版本,官网,第三方,腾讯。以宏来控制版本,和脚本删除不需要的脚本 由于使用的是Jenkins全部是命令行出包,Unity打包脚本如下

1static void ExportGYTProject_Online() 2 { 3 getCMDArgs(); 4 string[] NeedToDel = { 5 "Assets/Resources/DaBao", 6 "Assets/Resources/Audio", 7 "Assets/Resources/BackgroundPrefabs", 8 "Assets/Resources/BattleBackground", 9 "Assets/Resources/Maps"}; 10 doDelWithRelativePath(NeedToDel); 11 _LanguageBar.ToTraditionForAntBuild(); 12 PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, "XXXX"); 13 ExportAndroidProject(ExportPath); 14 } 15 static void getCMDArgs() { 16 foreach (string arg in System.Environment.GetCommandLineArgs()){ 17 if (arg.StartsWith("-ExportPath")){ 18 ExportPath = arg.Split('=')[1].Trim('"'); 19 }else if (arg.StartsWith("-UseWeTest")) { 20 UseWeTest = arg.Split('=')[1].Trim('"').Equals("true"); 21 Debug.Log(UseWeTest); 22; } 23 Debug.Log(arg); 24 } 25 if (ExportPath.Equals("")){ 26 throw new NullReferenceException("缺少-ExportPath参数"); 27 }else{ 28 Debug.Log("导出路径:" + ExportPath); 29 } 30 }

代码中ExportGYTProject_Online为需要调用Unity的CMD命令,getCMDArgs为对进行传入Unity命令行的命令解析

System.Environment.GetCommandLineArgs() //获取命令行参数

导出Android的工程至指定目录 #Android工程区分 ##官网的Android模板 都是只需要修改Mainfast.xml中channelid的参数就可以,所以官网的Android模板只有一个,每次通过Ant来修改channelid然后直接执行Ant release即可,并移动到指定目录

1<?xml version="1.0" encoding="UTF-8"?> 2<project name="custom_rules" > 3 <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> 4 <property name="_APKPATH" value=""/> 5 <property name="_game_channelid" value=""/> 6 <target name="BuildAPK"> 7 <antcall target="BuildAPK_All"/> 8 <antcall target="BuildAPK_Alone"/> 9 </target> 10 <target name="BuildAPK_Alone" if="${isBuildAlone}"> 11 <foreach list="${channelList}" target="UpdateChannelid" param="channel_id" delimiter=","> 12 13 </foreach> 14 </target> 15 <target name="UpdateChannelid"> 16 <propertyregex property="_temp_game_channelid" 17 input="${channel_id}" 18 regexp="&quot;?(.*)###" 19 select="\1" 20 casesensitive="false" /> 21 <echo message="${_temp_game_channelid}"/> 22 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 23 <regexp pattern="android:name=&quot;game_channelid&quot; android:value=&quot;(.*?)&quot;"/> 24 <substitution expression="android:name=&quot;game_channelid&quot; android:value=&quot;${_temp_game_channelid}&quot;" /> 25 <fileset dir="" 26 includes="AndroidManifest.xml" /> 27 </replaceregexp> 28 <echo message="${channel_id}"/> 29 <propertyregex property="_temp_platform_channel_id" 30 input="${channel_id}" 31 regexp="###(.*[^&quot;])" 32 select="\1" 33 casesensitive="false" /> 34 <echo message="${_temp_platform_channel_id}"/> 35 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 36 <regexp pattern="android:name=&quot;platform_channel_id&quot; android:value=&quot;(.*?)&quot;"/> 37 <substitution expression="android:name=&quot;platform_channel_id&quot; android:value=&quot;${_temp_platform_channel_id}&quot;" /> 38 <fileset dir="" 39 includes="AndroidManifest.xml" /> 40 </replaceregexp> 41 <antcall target="release"/> 42 <copy 43 file="${out.absolute.dir}/${ant.project.name}-release-unsigned.apk" 44 tofile="${APKPATH}/${ant.project.name}-v${VERSIONNAME}-${_temp_game_channelid}-${_temp_platform_channel_id}-unsigned.apk" /> 45 </target> 46 <target name="BuildAPK_All" unless="${isBuildAlone}"> 47 <var name="_game_channelid" value="${game_channelid}"/> 48 <antcall target="BuildGW"/> 49 <var name="_game_channelid" value="${CPSgame_channelid}"/> 50 <antcall target="BuildCPS"/> 51 </target> 52 53 <target name="BuildCPS"> 54 <echo message="${VERSIONNAME}/${VERSIONCODE}"/> 55 <echo message="打包官网CPS版本!" /> 56 <antcall target="UpdateVersionName"/> 57 <antcall target="UpdateVersionCode"/> 58 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 59 <regexp pattern="android:name=&quot;game_channelid&quot; android:value=&quot;(.*?)&quot;"/> 60 <substitution expression="android:name=&quot;game_channelid&quot; android:value=&quot;${CPSgame_channelid}&quot;" /> 61 <fileset dir="" 62 includes="AndroidManifest.xml" /> 63 </replaceregexp> 64 <var name="_APKPATH" value="${APKPATH}"/> 65 <foreach list="${CPSplatform_channel_idList}" target="Updateplatform_channel_idForMu" param="channel_id" delimiter=","> 66 67 </foreach> 68 </target> 69 70 <target name="BuildGW"> 71 <echo message="${VERSIONNAME}/${VERSIONCODE}"/> 72 <echo message="打包官网多渠道版本!" /> 73 <antcall target="UpdateVersionName"/> 74 <antcall target="UpdateVersionCode"/> 75 <antcall target="Updategame_channelid"/> 76 <var name="_APKPATH" value="${APKPATH}"/> 77 <foreach list="${platform_channel_idList}" target="Updateplatform_channel_idForMu" param="channel_id" delimiter=","> 78 79 </foreach> 80 </target> 81 82 <target name="UpdateVersionName"> 83 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 84 <regexp pattern="android:versionName=&quot;(.*?)&quot;"/> 85 <substitution expression="android:versionName=&quot;${VERSIONNAME}&quot;" /> 86 <fileset dir="" 87 includes="AndroidManifest.xml" /> 88 </replaceregexp> 89 </target> 90 91 <target name="UpdateVersionCode"> 92 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 93 <regexp pattern="android:versionCode=&quot;(.*?)&quot;"/> 94 <substitution expression="android:versionCode=&quot;${VERSIONCODE}&quot;" /> 95 <fileset dir="" 96 includes="AndroidManifest.xml" /> 97 </replaceregexp> 98 </target> 99 100 <target name="Updategame_channelid"> 101 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 102 <regexp pattern="android:name=&quot;game_channelid&quot; android:value=&quot;(.*?)&quot;"/> 103 <substitution expression="android:name=&quot;game_channelid&quot; android:value=&quot;${game_channelid}&quot;" /> 104 <fileset dir="" 105 includes="AndroidManifest.xml" /> 106 </replaceregexp> 107 </target> 108 109 110 <target name="Updateplatform_channel_idForMu"> <!-- 多渠道循环 --> 111 <echo message="${_APKPATH}"/> 112 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 113 <regexp pattern="android:name=&quot;platform_channel_id&quot; android:value=&quot;(.*?)&quot;"/> 114 <substitution expression="android:name=&quot;platform_channel_id&quot; android:value=&quot;${channel_id}&quot;" /> 115 <fileset dir="" 116 includes="AndroidManifest.xml" /> 117 </replaceregexp> 118 <antcall target="release"/> 119 <copy 120 file="${out.absolute.dir}/${ant.project.name}-release-unsigned.apk" 121 tofile="${APKPATH}/${ant.project.name}-v${VERSIONNAME}-${_game_channelid}-${channel_id}-unsigned.apk" /> 122 </target> 123</project>

##第三方的Android模板 由于每个渠道都是需要接入指定的SDK。一开始考虑接入所有SDK,然后通过修改XML中的配置参数然后来调用不同SDK,然后发现部分SDK有冲突而且包会变得巨大无比,然后修改为每个渠道一个Android模板,然后在导出指定版本的Unity后,移动Assets下的目录到Android工程包,然后执行Ant release。

1<?xml version="1.0" encoding="UTF-8"?> 2<project name="custom_rules" > 3 <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> 4 <target name="BuildAPK"> 5 <antcall target="preBuildProject"/> 6 <echo message="${VERSIONNAME}/${VERSIONCODE}"/> 7 <antcall target="UpdateVersionName"/> 8 <antcall target="UpdateVersionCode"/> 9 <antcall target="Updateplatform_channel_id"/> 10 <antcall target="Updategame_channelid"/> 11 <antcall target="release"/> 12 <copy 13 file="${out.absolute.dir}/${ant.project.name}-release-unsigned.apk" 14 tofile="${APKPATH}/${ant.project.name}-v${VERSIONNAME}-${game_channelid}-${platform_channel_id}-unsigned.apk" /> 15 </target> 16 17 <target name="preBuildProject"> 18 <foreach target="preBuildSubProject" param="_path"> 19 <path> 20 <dirset dir=".." includes="/*"/> 21 </path> 22 </foreach> 23 </target> 24 <target name="UpdateVersionName"> 25 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 26 <regexp pattern="android:versionName=&quot;(.*?)&quot;"/> 27 <substitution expression="android:versionName=&quot;${VERSIONNAME}&quot;" /> 28 <fileset dir="" 29 includes="AndroidManifest.xml" /> 30 </replaceregexp> 31 </target> 32 <target name="UpdateVersionCode"> 33 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 34 <regexp pattern="android:versionCode=&quot;(.*?)&quot;"/> 35 <substitution expression="android:versionCode=&quot;${VERSIONCODE}&quot;" /> 36 <fileset dir="" 37 includes="AndroidManifest.xml" /> 38 </replaceregexp> 39 </target> 40 <target name="Updateplatform_channel_id"> 41 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 42 <regexp pattern="android:name=&quot;platform_channel_id&quot; android:value=&quot;(.*?)&quot;"/> 43 <substitution expression="android:name=&quot;platform_channel_id&quot; android:value=&quot;${platform_channel_id}&quot;" /> 44 <fileset dir="" 45 includes="AndroidManifest.xml" /> 46 </replaceregexp> 47 </target> 48 <target name="Updategame_channelid"> 49 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 50 <regexp pattern="android:name=&quot;game_channelid&quot; android:value=&quot;(.*?)&quot;"/> 51 <substitution expression="android:name=&quot;game_channelid&quot; android:value=&quot;${game_channelid}&quot;" /> 52 <fileset dir="" 53 includes="AndroidManifest.xml" /> 54 </replaceregexp> 55 </target> 56</project>

##腾讯的Android模板 由于比较奇特,所以单独抽取了出来进行打包。

1<?xml version="1.0" encoding="UTF-8"?> 2<project name="custom_rules" > 3 <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> 4 <target name="BuildAPK"> 5 <echo message="${VERSIONNAME}/${VERSIONCODE}"/> 6 <antcall target="UpdateVersionName"/> 7 <antcall target="UpdateVersionCode"/> 8 <antcall target="Updateplatform_channel_id"/> 9 <antcall target="Updategame_channelid"/> 10 <antcall target="release"/> 11 <copy 12 file="${out.absolute.dir}/${ant.project.name}-release-unsigned.apk" 13 tofile="${APKPATH}/${ant.project.name}-v${VERSIONNAME}-${game_channelid}-${platform_channel_id}-unsigned.apk" /> 14 </target> 15 <target name="UpdateVersionName"> 16 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 17 <regexp pattern="android:versionName=&quot;(.*?)&quot;"/> 18 <substitution expression="android:versionName=&quot;${VERSIONNAME}&quot;" /> 19 <fileset dir="" 20 includes="AndroidManifest.xml" /> 21 </replaceregexp> 22 </target> 23 24 <target name="UpdateVersionCode"> 25 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 26 <regexp pattern="android:versionCode=&quot;(.*?)&quot;"/> 27 <substitution expression="android:versionCode=&quot;${VERSIONCODE}&quot;" /> 28 <fileset dir="" 29 includes="AndroidManifest.xml" /> 30 </replaceregexp> 31 </target> 32 33 <target name="Updateplatform_channel_id"> 34 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 35 <regexp pattern="android:name=&quot;platform_channel_id&quot; android:value=&quot;(.*?)&quot;"/> 36 <substitution expression="android:name=&quot;platform_channel_id&quot; android:value=&quot;${platform_channel_id}&quot;" /> 37 <fileset dir="" 38 includes="AndroidManifest.xml" /> 39 </replaceregexp> 40 </target> 41 42 <target name="Updategame_channelid"> 43 <replaceregexp byline="false" encoding="UTF-8" flags="g"> 44 <regexp pattern="android:name=&quot;game_channelid&quot; android:value=&quot;(.*?)&quot;"/> 45 <substitution expression="android:name=&quot;game_channelid&quot; android:value=&quot;${game_channelid}&quot;" /> 46 <fileset dir="" 47 includes="AndroidManifest.xml" /> 48 </replaceregexp> 49 </target> 50 51</project>

#打包流程 打包流程 ##CheckOut 使用的是Jenkins的SVN自己输出但是这里有个特殊点我们的项目由于前期的历史问题主干与分支是同级目录,所以在使用获取SVN目录时候使用的是我自己的脚本如下: SVN目录 ##reBuildAndroidLib 由于是Unity导出时候分主工程和一个Lib在导入后需要重新应用Lib一开始使用的手工加上引用,但是后来发现Android命令可以直接引用,但是没来的及修改代码参考如下:

1import sys; 2import os; 3 4filePath = sys.argv[1] 5ShareSDKPath = sys.argv[2] 6file = open(filePath) 7count = 1; 8isNeedAdd = 1; 9while 1: 10 line = file.readline() 11 if not line: 12 break 13 if "ShareSDK" in line: 14 isNeedAdd = 0; 15 if "android.library.reference" in line: 16 count = count +1; 17file.close(); 18if isNeedAdd == 1: 19 file = open(filePath,'a'); 20 ShareSDKPath = ShareSDKPath.replace('\\','/').replace('//','/'); 21 file.write("\nandroid.library.reference.%d=%s" % (count,ShareSDKPath)); 22 file.close(); 23 //这个脚本只能作为参考因为有挺多问题了,但是由于懒得修改就一直在用,可以用Android命令来替代

##reBuildAndroid 这里的--tatget 3 是根据自己的本地Android来设置的,可以参考命令说明修改

1cd %1 2@call ant clean 3@call android update project -p ./ --subprojects --target 3

##BuildApk 代码上面已经给出 ##SignApk 采用python脚本,由于这个脚本不是我们提供的,所以不贴出脚本了,也比较简单的。根据不同渠道签名。 ##加固混淆包 采用python脚本,由于加固的提供方是公司购买的也不提供代码了,由于他们不支持curl所以都是网页提交的,这里的python脚本主要是直接进行模拟网页操作提交。 ##分析APK文件 使用的JAVA来实现。Java代码比较多,我就说下思路,或者有空我开个新的帖子说下Ant的扩展实现。 思路根据APK使用CMD命令来调用Android命令行工具获取返回值,然后进行输出。 ##QA测试 QA测试使用WeTest,在Jenkins的打包选项内可以进行设置是否集成Wetest,然后直接进行测试 ##发布 发布到百度云传给运营商,然后上线。

#总结 其实这些都已经非常的概括的来说明整个思路了,事实上每一步流程都可以开一个日志来说明是如何分析,有空我将会单独开日志来解释。感谢大家阅读,如果有兴趣可以添加我的QQ792667487来一起学习。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

Jenkins中的Android打包任务设计 - HelloWorld