Last active
January 18, 2019 12:49
-
-
Save qingjoin/6ec8935f6dc9b6b0ca78 to your computer and use it in GitHub Desktop.
Unity3d通过Jenkins自动集成Xcode工程, 然后用Xcode工程通过Jenkins自动编译生成iOS 的ipa 安装包
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
如果Mac 上没有安装brew。先安装:ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" | |
首先安装jenkins #: brew install jenkins brew 官网:http://brew.sh 或直接从Jenkins下载:http://jenkins-ci.org | |
本地Unity生成Xcode工程设置: | |
首先请先安装两个插件: Manage Jenkins--> Manage Plugins --> Available -->Xcode integration && Unity3d plugin | |
本地Unity项目 | |
第一步:新建一个item | |
1 New item --> item name --> Build a free-style software project | |
第二步:添加一个项目 | |
1 Source Code Management --> None (注意如果选择本地。要把Unity工程拷贝到Jenkins的工作目录下类似于/Users/qingyun/.jenkins/jobs/ProjectName/workspace 。 这里要拷贝的对象为Unity工程里面Library 、Assets 同级的路径,把这里所有的文件拷贝把workspace下) | |
第三步:添加Unity 项目 | |
1 Add build step | |
2 Unity3d installation name .选择设置好的unity(如果开始没设置,那么回到Jenkins主界面,设置Unity) | |
设置Unity插件如果已设置可以忽略这里:1Manage Jenkins -> Configure System -->Unity3d -->name(随便起) && | |
Installation directory:/Applications/Unity/Unity.app (Unity的安装地址) | |
3 Editor command line arguments 输入脚本:-quit -batchmode -executeMethod PerformBuild.CommandLineBuild | |
PerformBuild.CommandLineBuild 的意思是执行脚本里的CommandLineBuild 方法。 | |
注意BuildProject.cs 这个脚本一定要放到Unity工程下面的Assets-->Editor下面。BuildProject.cs参考代码如 | |
BuildProject.cs | |
//////////////////////////////////////////////////////////////////////////////////////////// | |
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() | |
{ | |
return "build/iPhone"; | |
} | |
[UnityEditor.MenuItem("Project Cos/Resources/Command Line Build Step")] | |
static void CommandLineBuild () | |
{ | |
Debug.Log("Command line build\n------------------\n------------------"); | |
string[] scenes = GetBuildScenes(); | |
string path = GetBuildPath(); | |
if(scenes == null || scenes.Length==0 || path == null) | |
//return; | |
Debug.Log(string.Format("Path: \"{0}\"", path)); | |
for(int i=0; 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() | |
{ | |
return "build/android"; | |
} | |
} | |
//////////////////////////////////////////////////////////////////////////////////////////// | |
第四步:save编译运行。 如果编译成功那么会在WorkSpace/build/下生成iPhone文件。这个文件里的内容就是刚生成的xcode 项目。 | |
那么接下来设置本地的Xcode 工程。 | |
本地Unity生成的Xcode自动编译ipa具体设置: | |
第一步:新建一个item | |
1 New item --> item name --> Build a free-style software project | |
第二步:添加Xcode 项目设置(Add Build step选择Xcode) | |
1 Source Code Management-->None --> Add build step -->Xcode | |
第三步:设置Xcode | |
1 Target (Xcode的target) | |
2 选择settings -- >Clean before build 选择Yes (Pack application and build .ipa不要选择。因为Unity不支持) | |
3 Code sigining settings.. (如果本地的Xcode 工程里面的证书都设置好了。就不用填了。) | |
4 Advanced build settings (其它都不用填。找到Xcode Project Directory 这个一定要注意了。这个地址是本地xcode 项目里面.xcodeproj的有效地址) | |
第四步:添加shell 脚本命令(Add Build Step 选择 Execute shell) | |
1 Command : | |
xcrun -sdk iphoneos PackageApplication -v /Users/chenqing/.jenkins/jobs/TestLocalUnity/workspace/build/iPhone/build/ProductName.app -o /Users/chenqing/.jenkins/jobs/TestLocalUnity/workspace/build/iPhone/TestLocal.ipa | |
//修改相应目录。 TestLocal.ipa 是编译生成的ipa 文件 | |
第五步: save -->Build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment