Unity 自动打包 Part2—构建IPA文件

目录

1.介绍

2.Unity代码

3. ipa打包脚本—build.sh

4.打包脚本推荐

5.Feature 2017.5.13 打包上传

6.邮件通知


1.介绍

文章介绍的是unity打包xcode工程完毕后,开启terminal执行打包脚本。

xcode 8.1+,unity5.5+ , 脚本适用于mac系统。

2.Unity代码

  打包完毕最后,调用Buildipa()。

public static string ProjectPath(){
	string currentDir = Application.dataPath;
	int index = currentDir.LastIndexOf ("/");
	currentDir = currentDir.Remove (index);
	index = currentDir.LastIndexOf ("/");
	currentDir = currentDir.Remove (index);
	return currentDir;
}
public static string XcodePath(){
	return ProjectPath () + "/Unity_IOS";//'Unity_IOS'替换为你的xcode工程导出的文件夹名称
}

/*
此代码的功能: 打开terminal,执行buildios.sh
"osascript" 是apple script,osascript可以主动打开一个terminal,并且在终端显示构建IPA的Log
当然你也可以直接调用shell,下方有例子。我不用shell是因为shell是在后台执行,我看不到详细Log
*/
public void Buildipa() {
    Process myCustomProcess = new Process();
	myCustomProcess.StartInfo.FileName = "osascript";
	myCustomProcess.StartInfo.Arguments = string.Format ("-e 'tell application \"Terminal\" \n activate \n do script \"cd {0} && sh {1} {2}\" \n end tell'",Application.dataPath + "/_PlatformAssets/", "buildios.sh", XCodeProjectMod.XcodePath ());
	myCustomProcess.StartInfo.UseShellExecute = false;
	myCustomProcess.StartInfo.RedirectStandardOutput = false;
	myCustomProcess.Start();
	myCustomProcess.WaitForExit ();
}

 

//打开shell (不推荐)
Process myCustomProcess = new Process();
myCustomProcess.StartInfo.FileName = "/bin/sh";
myCustomProcess.StartInfo.Arguments = Application.dataPath + "/_PlatformAssets/buildios.sh" + " " + XCodeProjectMod.XcodePath() + " " + "test";
myCustomProcess.StartInfo.UseShellExecute = false;
myCustomProcess.StartInfo.RedirectStandardOutput = false;
myCustomProcess.Start();
myCustomProcess.WaitForExit ();

 

3. ipa打包脚本—buildios.sh

echo "Start Building"
#project_path="xxxxxxxxx"
project_path=$1
scheme_name="Unity-iPhone" 
export_plist=${project_path}/exportArgs.plist
project_name="Unity-iPhone.xcodeproj"
build_output_dir="build"
configuration="Release"
archivePath=${build_output_dir}/${scheme_name}.xcarchive

cd $project_path

echo "Clean Xcode"

xcodebuild clean

xcodebuild archive -project "${project_name}" -scheme "${scheme_name}" -configuration "$configuration" -archivePath "${archivePath}"

#xcrun obsoleted
#xcrun -sdk iphoneos PackageApplication -v ${build_path}/Release-iphoneos/rok.app -o ${build_path}/${ipa_name}.ipa

xcodebuild -exportArchive -archivePath "${archivePath}" -exportOptionsPlist "${export_plist}" -exportPath "${build_output_dir}"

open ${project_path}

echo "Successfully exported and signed the ipa file"

#python emailPy.py "$result"

 文章参考http://liumh.com/2015/11/25/ios-auto-archive-ipa/

 exportArgs.plist 文件是导出ipa 必要文件(可自行查阅资料,下方是plist文件,请自行创建一个plist文件)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>method</key>
	<string>development</string>
	<key>compileBitcode</key>
	<string>NO</string>
</dict>
</plist>

  Xcode9 此配置有变化 链接跳转 点击打开链接

 

4.打包脚本推荐

fastlane

 

5.Feature 2017.5.13 打包上传

打包完毕ipa后,上传至bugly,上传至蒲公英同理。

1是上传新包,2是覆盖包

1> result=$(curl --insecure -F "file=@文件ipa位置" -F "app_id=你的bugly项目appid" -F "pid=2" -F "secret=1" -F "title="helloworld" https://api.bugly.qq.com/beta/apiv1/exp?app_key=你的appkey)
2> result=$(curl --insecure -X 'PUT' -F "file=@文件ipa位置" -F "exp_id=你已经上传的包的id,就是点击项目,url后面的串" https://api.bugly.qq.com/beta/apiv1/exp?app_key=你的appkey)

在打包ipa shell脚本添加: python emailPy.py "$result" ,请看Part-3 发送邮件通知。

 

 

6. 下一步 邮件通知

Unity 全自动打包 Part3—上传Bugly 邮件通知

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值