題記
xcode升級8.3后發現之前所用的xcode自動打包基本無法使用,因此在網上零碎找到些資料,將之前的腳本簡化。此次腳本是基於xcode證書配置進行打包(之前是指定描述文件、相對繁瑣)。因此代碼較為簡單使用。
xcodebuild
自動打包是基於xcodebuild工具進行打包(xcode本身也是基於此打包)。在終端我們可以通過 man xcodebuild 指令查看了解xcodebuild工具

接着通過xcodebuild --help可直接得到其使用示例

非cocoapods管理項目,只需要對單個工程進行打包處理,使用如下方法
xcodebuild [-project <projectname>] -scheme <schemeName> [-destination <destinationspecifier>]... [-configuration <configurationname>] [-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]] [-showBuildSettings] [<buildsetting>=<value>]... [<buildaction>]...
由於筆者使用cocoapods管理第三方庫,因此直接使用進行打包
xcodebuild -workspace <workspacename> -scheme <schemeName> [-destination <destinationspecifier>]... [-configuration <configurationname>] [-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]] [-showBuildSettings] [<buildsetting>=<value>]... [<buildaction>]...
當打包完成后只需要對壓縮包解壓即可得到對應的ipa安裝包
xcodebuild -exportArchive -archivePath <xcarchivepath> -exportPath <destinationpath> -exportOptionsPlist <plistpath>
主要代碼
#清理工程
xcodebuild clean -configuration ${development_mode} -quiet || exit
#編譯工程
xcodebuild archive -workspace ${project_name}.xcworkspace -scheme ${scheme_name} -configuration ${development_mode} -archivePath build/${project_name}.xcarchive -quiet || exit
#打包
xcodebuild -exportArchive -archivePath build/${project_name}.xcarchive -configuration ${development_mode} -exportPath ${exportFilePath} -exportOptionsPlist ${exportOptionsPlistPath} -quiet || exit
//todo ..應用上傳分發操作
參數說明
cleaen 清理工程
quiet 不輸出警告或錯誤
exit 命令未完成退出shell腳本
projectname 工程名
workspacename 工程名
schemeName 一般也為工程名(個人理解為應用調起標示)
configuration 打包模式(Debug/Release)
exportOptionsPlist ipa導出方式(分為app-store、ad-hoc、enterprise、development)
此項由plist文件構成的字典key:method, value:development(上述四個其中一個)
自動打包文件
自動打包腳本已上傳至github有需要的朋友可自行下載自動打包腳本文件鏈接
上述如有不妥之處請指正參考鏈接
