本文主要涉及一下幾個(gè)方面的內(nèi)容:
1妓忍、xcodebuild的介紹
2磷账、使用xcodebuild打包生成Ad-hoc的ipa文件
3缝裁、將打包好的文件上傳到測(cè)試平臺(tái)
3荣瑟、將過(guò)程腳本化
xcodebuild簡(jiǎn)介
xcodebuild 是蘋果自己發(fā)布的自動(dòng)構(gòu)建的工具治拿,Xcode的Command Line Tools自帶該工具,一般不需要我們手動(dòng)安裝笆焰。在Xcode8以前還可以使用xctool來(lái)實(shí)現(xiàn)忍啤,但是xctool在Xcode8以后不再支持build功能,F(xiàn)acebook團(tuán)隊(duì)推薦轉(zhuǎn)回官方的xcodebuild仙辟,坑爹的我還花了一段時(shí)間研究。
我們需要在目標(biāo)工程目錄下執(zhí)行 xcodebuild 命令鳄梅,xcodebuild -help可查看相關(guān)的說(shuō)明叠国,里面的說(shuō)明十分詳細(xì)。
xcodebuild打包生成
打包ipa我們主要用到以下幾條命令:
- xcodebuild clean -project $projectname -scheme $schemeName
清理工程,避免出現(xiàn)一些奇怪的錯(cuò)誤- xcodebuild archive -project $projectname -scheme $schemeName -configuration $configuration -archivePath
生成Archive文件- xcodebuild -exportArchive -archivePath $archivePath -exportPath $exportPath -exportOptionsPlist $exportOptionsPlist
從Archive文件導(dǎo)出ipa
-project:項(xiàng)目名稱戴尸,如果工程目錄里面里面有多個(gè)工程粟焊,必須指定,如果項(xiàng)目使用了cocoapods孙蒙,此處應(yīng)該使用-workspace,即
xcodebuild archive -workspace $projectname -scheme $schemeName -configuration $configuration -archivePath
-archivePath:Archive文件導(dǎo)出目的路徑
-exportPath:ipa文件導(dǎo)出路徑’
-scheme:指定scheme
-configuration:指定版本release或者debug
以上兩個(gè)可以通過(guò)-xcodebuild -list查看可用值
-exportOptionsPlist:打包的相關(guān)配置參數(shù)项棠,該參數(shù)是一個(gè).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>enterprise</string>
<key>compileBitcode</key>
<false/>
</dict>
</plist>
對(duì)于大部分情況我們只需要指定這兩個(gè)參數(shù)挎峦,更多詳細(xì)的可參照xcodebuild -help里面的說(shuō)明香追。
此外,-list, -showBuildSettings, -showsdks 的參數(shù)可以查看項(xiàng)目或者工程的信息坦胶。
上傳到測(cè)試平臺(tái)
本人使用的是fir透典,下載安裝命令行客戶端
fir publish filePath(ipa文件路勁)
如果使用的是其他的發(fā)布平臺(tái)晴楔,將上傳腳本替換成對(duì)應(yīng)平臺(tái)的即可
過(guò)程腳本化
#!/bin/sh
#項(xiàng)目路徑
projectfile=/Users/my/Desktop/PackDemo
#工程文件路徑
project=PackDemo.xcworkspace
#scheme名稱
scheme=PackDemo
#target名稱
target=PackDemo
#編譯版本
configuration=Release
#archive文件路徑
archivePath=~/desktop/打包/$target/$target.xcarchive
#ipa包導(dǎo)出路徑
exportPath=~/desktop/打包/$target
#打包配置文件路徑
exportOptionsPlist=$projectfile/exportOptionsPlist.plist
#上傳時(shí),ipa包路勁
publishPath=$exportPath/$target.ipa
#進(jìn)入項(xiàng)目所在文件
cd $projectfile
# 清理工程
xcodebuild clean -workspace $project -scheme $scheme -configuration $configuration
#上傳fir
function upload
{
fir publish $publishPath
rm -r $archivePath
}
#導(dǎo)出ipa文件,會(huì)在$exportPath路徑生成ipa文件
function export
{
xcodebuild -exportArchive -archivePath $archivePath -exportPath $exportPath -exportOptionsPlist $exportOptionsPlist
if [ $? -eq 1 ]
then
echo "ipa導(dǎo)出失敗"
read
else
clear
echo "ipa導(dǎo)出成功"
# upload
fi
}
#archive項(xiàng)目峭咒,會(huì)在$archivePath路徑生成PackDemo.xcarchive文件
function archive
{
xcodebuild archive -workspace $project -scheme $scheme -configuration $configuration -archivePath $archivePath
if [ $? -eq 1 ]
then
echo "編譯失敗"
read
else
clear
echo "編譯成功"
export
fi
}
#開始執(zhí)行
archive
到此完成了自動(dòng)化打包腳本税弃,本人習(xí)慣為每個(gè)項(xiàng)目都生成一個(gè)對(duì)應(yīng)的腳本,里面寫好打包的工程配置,內(nèi)容都基本相同凑队,只需要修改對(duì)應(yīng)的路徑參數(shù)即可则果,每次需要打新的測(cè)試包,只需打開對(duì)應(yīng)的腳本文件即可漩氨。
另外西壮,Application Loader命令行可以讓我們通過(guò)腳本上傳App Store,詳細(xì)的教程請(qǐng)參考蘋果文檔https://itunesconnect.apple.com/docs/UsingApplicationLoader.pdf