Unity3d+Jenkins 自动编译iOS、Android版本
1、在Unity3d中, 创建导出 iOS、Android 项目脚本 PerformBuild.cs ,放在Editor目录下(必须),如下:
using UnityEditor;
using System.IO;
using System.Collections;
using UnityEngine;
using System.Collections.Generic; class PerformBuild
{
static string[] GetBuildScenes()
{
List<string> names = new List<string>(); foreach(EditorBuildSettingsScene e in EditorBuildSettings.scenes)
{
if(e==null)
continue; if(e.enabled)
names.Add(e.path);
}
return names.ToArray();
} static string GetBuildPath()
{
string dirPath = Application.dataPath +"/../../../build/iPhone";
if(!System.IO.Directory.Exists(dirPath)){
System.IO.Directory.CreateDirectory(dirPath);
}
return dirPath;
} [UnityEditor.MenuItem("Tools/PerformBuild/Test Command Line Build iPhone Step")]
static void CommandLineBuild ()
{
Debug.Log("Command line build\n------------------\n------------------"); string[] scenes = GetBuildScenes();
string path = GetBuildPath();
if(scenes == null || scenes.Length== || path == null)
return; Debug.Log(string.Format("Path: \"{0}\"", path));
for(int i=; i<scenes.Length; ++i)
{
Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
} Debug.Log("Starting Build!");
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.iPhone, BuildOptions.None);
} static string GetBuildPathAndroid()
{
string dirPath = Application.dataPath +"/../../../build/android";
if(!System.IO.Directory.Exists(dirPath)){
System.IO.Directory.CreateDirectory(dirPath);
}
return dirPath;
} [UnityEditor.MenuItem("Tools/PerformBuild/Test Command Line Build Step Android")]
static void CommandLineBuildAndroid ()
{
Debug.Log("Command line build android version\n------------------\n------------------"); string[] scenes = GetBuildScenes();
string path = GetBuildPathAndroid();
if(scenes == null || scenes.Length== || path == null)
return; Debug.Log(string.Format("Path: \"{0}\"", path));
for(int i=; i<scenes.Length; ++i)
{
Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
} Debug.Log("Starting Android Build!");
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.None);
}
}
完成之后在Tools菜单下 会有 测试菜单 ,可以试一下是否可以成功导出项目。
2、创建Jenkins配置文件 build.xml 和 参数文件 settings.properties
build.xml 如下:(有其他需求,编辑此文件即可)
<?xml version="1.0" encoding="UTF-8"?>
<project name="wx_client" default="main" basedir=".">
<property environment="env"/>
<property name="RAW_BUILD_NUMBER" value="${env.BUILD_NUMBER}"/>
<script language="javascript"><![CDATA[
var buildNum = parseInt(project.getProperty("RAW_BUILD_NUMBER"))
var minorBuildNumber = buildNum % 100;
var majorBuildNumber = (Math.floor(buildNum / 100)) % 100;
var uberBuildNumber = (Math.floor(buildNum / 10000)) % 100;
project.setProperty("minorBuildNumber", minorBuildNumber);
project.setProperty("majorBuildNumber", majorBuildNumber);
project.setProperty("uberBuildNumber", uberBuildNumber);
]]></script>
<property name="VERSION_STRING" value="${uberBuildNumber}.${majorBuildNumber}.${minorBuildNumber}"/>
<property file="settings.properties"/>
<property name="dev.dir.absolute" location="${dev.dir}"/>
<tstamp>
<format property="TODAY_STAMP" pattern="yyyy_MM_dd" locale="en,US"/>
</tstamp>
<tstamp>
<format property="MONTH_STAMP" pattern="M" locale="en,US"/>
</tstamp>
<property name="VERSION_NUM" value="${uberBuildNumber}.${majorBuildNumber}.${minorBuildNumber}"/>
<property name="VERSION_STRING" value="honorbound_${VERSION_NUM}"/> <target name="main" depends="ios, android, zipDsym" /> <target name="android" depends="compile-android" /> <target name="ios" depends="compile-ios" /> <target name="clean">
<echo message="Cleaning Build Space"/>
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
</target> <target name="compile-ios" depends="clean"> <echo message="Compiling unity project for version ${VERSION_STRING}"/> <echo message="${unity.bin} -projectPath ${dev.dir.absolute} -executeMethod PerformBuild.CommandLineBuild -batchmode -quit"/>
<exec executable="${unity.bin}" failonerror="true">
<arg line="-projectPath ${dev.dir.absolute}"/>
<arg line="-executeMethod PerformBuild.CommandLineBuild"/>
<arg line="-batchmode"/>
<arg line="-quit"/>
</exec> <replace file="${build.dir}/iPhone/Info.plist" preservelastmodified="true">
<replacefilter token="999.999.999" value="${VERSION_NUM}" />
</replace> <exec executable="${security.bin}" failonerror="true">
<arg value="unlock-keychain"/>
<arg line="-p ${keychain.password}"/>
</exec> <echo message="Building ${build.dir}/iPhone/Unity-iPhone.xcodeproj/ Sym Root ${build.dir}/iPhone/"/>
<exec executable="${xcode.bin}" failonerror="true">
<arg line="-project ${build.dir}/iPhone/Unity-iPhone.xcodeproj/"/>
<arg line="PROVISIONING_PROFILE=${provisioning.guid}"/>
<arg line="-sdk iphoneos"/>
<arg line='CODE_SIGN_IDENTITY="${codesign.identity}"'/>
<arg line='GCC_GENERATE_DEBUGGING_SYMBOLS=YES'/>
<arg line='DEBUG_INFORMATION_FORMAT=dwarf-with-dsym'/>
<arg line='DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT=YES'/>
<arg line='DEBUGGING_SYMBOLS=YES'/> <arg line="-configuration Release"/>
</exec> <exec executable="${xcrun.bin}" failonerror="true">
<arg line="-sdk iphoneos"/>
<arg line="PackageApplication"/>
<arg line="-v ${build.dir}/iPhone/build/${APP_NAME}.app"/>
<arg line="-o ${build.dir}/iPhone/build/${APP_NAME}.ipa"/>
</exec> <copy file="${build.dir}/iPhone/build/${APP_NAME}.ipa" tofile="${ios.build.deploy.folder}/${VERSION_STRING}.ipa"/> </target> <target name="compile-android" depends="clean"> <echo message="Compiling unity project for android version ${VERSION_STRING}"/> <echo message="${unity.bin} -projectPath ${dev.dir.absolute} -executeMethod PerformBuild.CommandLineBuildAndroid -batchmode -quit"/>
<exec executable="${unity.bin}" failonerror="true">
<arg line="-projectPath ${dev.dir.absolute}"/>
<arg line="-executeMethod PerformBuild.CommandLineBuildAndroid"/>
<arg line="-batchmode"/>
<arg line="-quit"/>
</exec> <copy file="${build.dir}/android" tofile="${android.build.deploy.folder}/${VERSION_STRING}.apk"/>
<exec executable="curl" dir="${android.build.deploy.folder}">
<arg line="--form file=@${VERSION_STRING}.apk '${BUILD_URL}/save_file.php?appname=${APP_NAME}'" />
</exec>
</target> <target name="zipDsym">
<echo message="Zipping dSym"/>
<exec executable="zip" dir="${build.dir}/iPhone/build" failonerror="true">
<arg value="-r"/>
<arg value="${APP_NAME}.app.dSYM.zip"/>
<arg value="${APP_NAME}.app.dSYM"/>
</exec>
</target> </project>
settings.properties 如下: (注意把下面该改成自己项目的改一下)
注:xcode5 去 /Users/<home>/Library/MobileDevice/Provisioning Profiles 目录找证书GUID
unity.bin = /Applications/Unity/Unity.app/Contents/MacOS/Unity
xcode.bin = /usr/bin/xcodebuild
xcrun.bin = /usr/bin/xcrun
security.bin = /usr/bin/security
provisioning.guid = SOME-GUID-GOES-HERE(证书GUID)
codesign.identity = iPhone Distribution: Joe Developer
build.dir = ../UnityClient/build (PerformBuild到的目录)
dev.dir = ../UnityClient/ (Unity3d项目目录)
keychain.password = Woohoo
APP_NAME=honorbound
ios.build.deploy.folder = /Users/Shared/Jenkins/builds/ios
android.build.deploy.folder = /Users/Shared/Jenkins/builds/android
(最后两个是打包好的ipa 和 apk 要放到的地方)
3、打开Jenkins,按如下步骤新建一个Job:
3.1、

3.2、找到 构建 -> 增加构建步骤 -> Invoke Ant

3.3、选择高级

3.4、输入 build File 路径 和 Properties 路径,然后保存job

4、现在就可以点击 立即构建 开始编译你的项目了,开始前请先退出Unity3d,否则会报错。
此外 iOS 需要MAC相关环境
参考资料:
1、http://blog.juiceboxmobile.com/2013/03/08/unity3d-ios-android-jenkins-autobuild/
2、https://gist.github.com/jmcguirk/5113641
3、http://docs.unity3d.com/Documentation/Manual/CommandLineArguments.html
Unity3d+Jenkins 自动编译iOS、Android版本的更多相关文章
- {转}Unity3d+Jenkins 自动编译iOS、Android版本(U3D远程自动打包工具)
http://www.cnblogs.com/yinghuochong/archive/2013/09/01/3294940.html
- 使用Jenkins自动编译 .net 项目
使用Jenkins自动编译我的.net 项目 1.Jenkins是什么? Jenkins是一个可扩展的持续集成的引擎,主要用于持续自动的构建.测试软件项目 监控一些定时执行的任务. 2.安装配 ...
- (转载)Ant自动编译打包android项目
1 Ant自动编译打包android项目 1.1 Ant安装 ant的安装比较简单,下载ant压缩包 http://ant.apache.org (最新的为1.9.3版本),下载之后将其解压 ...
- jenkins自动打IOS包(转发)
投稿文章,作者:一缕殇流化隐半边冰霜(@halfrost) 前言 众所周知,现在App的竞争已经到了用户体验为王,质量为上的白热化阶段.用户们都是很挑剔的.如果一个公司的推广团队好不容易砸了重金推广了 ...
- [CI] 使用Jenkins自动编译部署web应用
写在前面 初步接触持续集成自动化过程,本篇主要介绍基于Jenkins实现持续集成的方式,通过案例介绍线上自动编译及部署的配置过程 持续集成 持续集成是一种软件开发实践,即团队开发成员经常集成它们的工作 ...
- Android-Ant自动编译打包android项目 -- 2 ----签名与渠道包
上篇介绍了怎么使用ant自动编译打包现有的android项目,这篇将继续介绍如果如何在ant打包应用的时候加入签名信息以及自动打包渠道包. 1. 加入签名信息: 在项目的根目录下建一个ant.prop ...
- Android - Ant自动编译打包android项目 -- 1(转)
1. 背景: Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其当要将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我 ...
- Ant自动编译打包android项目(转载)
1.1 Ant安装 ant的安装比较简单,下载ant压缩包 http://ant.apache.org (最新的为1.9.3版本),下载之后将其解压到某个目录(本人解压到E:\Progra ...
- 使用Jenkins自动编译我的.net 项目
1.Jenkins是什么? Jenkins是一个可扩展的持续集成的引擎,主要用于持续自动的构建.测试软件项目 监控一些定时执行的任务. 2.安装配置 最新的Jenkins 安装包可以从这里下载:h ...
随机推荐
- ABAP 搜索帮助
当选择屏幕上的一个字段所参考的数据元素没有建立搜索帮助时,可以手工建立一个: 1.在se11创建一个搜索帮助ZAUTEST,需要输入: (1)描述: (2)选择方法:即搜索帮助显示字段所在的透明表: ...
- 转:Web App开发入门
WebApp与Native App有何区别呢? Native App: 1.开发成本非常大.一般使用的开发语言为JAVA.C++.Objective-C. 2.更新体验较差.同时也比较麻烦.每一次发布 ...
- 读书笔记2014第6本:《The Hunger Games》
以前从未读过一本完整的英文小说,所有就在今年的读书目标中增加了一本英文小说,但在头四个月内一直没有下定决定读哪一本.一次偶然从SUN的QQ空间中看到Mockingjay,说是不错的英文小说,好像已经是 ...
- UIView简单动画
UIView动态实现的效果有以下几种: 1.动态改变frame 2.动态改变color 3.动态改变alpha 4.动态改变bounds 首先,我们先看几种BasicView动画 #pragma ma ...
- JAVA基础学习day22--IO流四-对象序列化、管道流、RandomAccessFile、DataStream、ByteArrayStream、转换流的字符编码
一.对象序列化 1.1.对象序列化 被操作的对象需要实现Serializable接口 1.2.对象序列化流ObjectOutputStream与ObjectInputStream ObjectInpu ...
- UnityShader之顶点片段着色器Vertex and Fragment Shader【Shader资料】
顶点片段着色器 V&F Shader:英文全称Vertex and Fragment Shader,最强大的Shader类型,也是我们在使用ShaderLab中的重点部分,属于可编程管线,使用 ...
- 将tomcat源码导入eclipse
前言: 写完了socket小应用的原始版本,中间还有好多预想的功能没有实现,在写的过程中也发现了很多问题.因为前面有粗略的看过tomcat实现原理解析,知道tomcat其实也是纯java写的web服务 ...
- java网络---流
网络操作很大一部分功能就是输入和输出数据. 简单归纳就是上传和下载文件.文件也是数据的一种载体. java对数据的操作归并为流. 所以对于数据流的操作定义2个基本类. java.io.OutputSt ...
- [Weblogic]startWebLogic.cmd配置JAVA_OPTIONS无效的解决思路与方案
事情背景: 由于某个项目原因,需要在2个域的startWebLogic.cmd文件加入如下设置 set JAVA_OPTIONS=%JAVA_OPTIONS% -javaagent:"pat ...
- [PL/SQL工具]绿色版PLSQL工具登录时提示初始化失败,无法锁定OCI.dll错误
问题现象:使用绿色版PL/SQL工具进行登录时报如下截图错误: 问题描述:初始化失败,无法锁定oci.dll 解决方法:在PLSQL的菜单栏里依次选择 工具->首选项,在OCI库(自动检测为空) ...