iOS命令行自動(dòng)打包腳本
因?yàn)楣ぷ魃系男枰赡軙?huì)頻繁的打包ipa,于是參考了大佬們的資料后,整合了一份自動(dòng)打包的腳本。
需要用到的
這里用到了三樣?xùn)|西,xcodebuild, plistBuddy, shell。
plistBuddy
plistBuddy是Mac自帶的專門解析plist的小工具,由于不在默認(rèn)目錄里面,使用的時(shí)候需要在/usr/libexec/PlistBuddy 上使用
沒有接觸過的同學(xué)可以看這里 plistBuddy的簡單使用
xcodebuild
xcodebuild是xcode提供的一個(gè)不需要打開工程文件,直接打包的一個(gè)工具,也是打包的重要點(diǎn),詳情看這里。
使用方法
本腳本需要的參數(shù)有三個(gè)需要填寫,注意provision file需要放入文件夾
#工程名字(Target名字)
Project_Name="工程文件夾名稱"
#AppStore版本的Bundle ID
AppStoreBundleID="你的Bundle ID"
#provision file的名稱 (#########此文件需要與xxxx.xcodeproj同一個(gè)目錄#########)
MOBILE_PROVISION_NAME="Provision File,不需要帶后綴"
填寫完后,就可以利用plistBuddy與xcodebuild進(jìn)行打包了
provision file 數(shù)據(jù)轉(zhuǎn)換
#將描述文件放入目錄
MobileProvisionFile=./${MOBILE_PROVISION_NAME}.mobileprovision
#創(chuàng)建plist文件
/usr/libexec/plistbuddy -c Set: ./${MOBILE_PROVISION_NAME}.plist
#將描述文件轉(zhuǎn)換成plist
MobileProvisonPlist=./${MOBILE_PROVISION_NAME}.plist
#echo "MobileProvisonPlist = ${MobileProvisonPlist}"
security cms -D -i $MobileProvisionFile > $MobileProvisonPlist
獲取provision file 里面的信息
獲取信息的主要原因是xcodebuild需要獲取到證書的信息
#獲取開發(fā)者團(tuán)隊(duì)名稱
DEVELOPMENT_TEAM_NAME=`/usr/libexec/PlistBuddy -c "Print TeamName" $MobileProvisonPlist`
echo "DEVELOPMENT_TEAM_NAME 為 ${DEVELOPMENT_TEAM_NAME}"
#獲取團(tuán)隊(duì)ID
DEVELOPMENT_TEAM_ID=`/usr/libexec/PlistBuddy -c "Print TeamIdentifier:0" $MobileProvisonPlist`
echo "DEVELOPMENT_TEAM_ID 為 ${DEVELOPMENT_TEAM_ID}"
#拼接AppStore證書名#描述文件
APPSTORECODE_SIGN_IDENTITY="iPhone Distribution: ${DEVELOPMENT_TEAM_NAME} (${DEVELOPMENT_TEAM_ID})"
echo "APPSTORECODE_SIGN_IDENTITY 為 ${APPSTORECODE_SIGN_IDENTITY}"
#UUID
APPSTOREROVISIONING_PROFILE_NAME=`/usr/libexec/PlistBuddy -c "Print UUID" $MobileProvisonPlist`
echo "UUID 為 ${PROVISION_UUID}"
xcodebuild
之后就可以直接進(jìn)行打包了
#clean下
xcodebuild clean -xcodeproj ./$Project_Name/$Project_Name.xcodeproj -configuration $Configuration -alltargets
#appstore腳本
xcodebuild -project $Project_Name.xcodeproj -scheme $Project_Name -configuration $Configuration -archivePath build/$Project_Name-appstore.xcarchive clean archive build CODE_SIGN_IDENTITY="${APPSTORECODE_SIGN_IDENTITY}" PROVISIONING_PROFILE="${APPSTOREROVISIONING_PROFILE_NAME}" PRODUCT_BUNDLE_IDENTIFIER="${AppStoreBundleID}"
xcodebuild -exportArchive -archivePath build/$Project_Name-appstore.xcarchive -exportOptionsPlist $AppStoreExportOptionsPlist -exportPath ~/Desktop/$Project_Name-appstore.ipa
如果覺得本文對你有用,點(diǎn)個(gè)贊唄!
參考鏈接:
https://blog.csdn.net/dcw050505/article/details/70651236
https://blog.csdn.net/cneducation/article/details/54729106
https://www.aliyun.com/jiaocheng/373104.html