shell自動打包IPA
阿新 • • 發佈:2019-01-26
自動打包ipa,測試發現時間和用xcode打包差不多,但可以減少滑鼠點選操作。
#!/bin/bash
#----------使用說明---
#將EnterpriseExportOptionsPlist放在.xcodeproj同級目錄
#執行指令碼,直接拖放專案目錄(.xcodeproj上級資料夾)
#mac 下終端訪問檔案出現“Permission Denied”解決方案:chmod a+x ./檔名
#----------使用說明 END---
#配置資訊--Start---------
version_string="3.5.0" #版本號-空值不設定
build_number="3.5.1286" #版本號-空值不設定
##企業(enterprise)證書名&描述檔案
ENTERPRISECODE_SIGN_IDENTITY="iPhone Distribution: xxx Service Co., Ltd."
EnterpriseBundleID="com.xxx.inhouse"
ENTERPRISEROVISIONING_PROFILE_NAME="73c2dfe3-ebc4-4801-bbd6-e4ba25f14fe9"
echo "請拖入專案檔案目錄(.xcodeproj檔案的上層目錄)"
# 讀取使用者輸入並存到變數裡
read user_input
Project_Path=$user_input
#EnterpriseExportOptionsPlist檔案路徑
EnterpriseExportOptionsPlist=$Project_Path/EnterpriseExportOptionsPlist.plist
echo "$EnterpriseExportOptionsPlist"
echo "$Project_Path"
cd $Project_Path
#查詢專案名稱
Project_Name=`find . -name *.xcodeproj | awk -F "[/.]" '{print $(NF-1)}'`
###############獲取版本號,bundleID
info_plist=$Project_Path/$Project_Name/Info.plist
echo "~~~0~$Project_Name~~~~~"
ipa_outPath=~/Desktop/$Project_Name #儲存ipa檔案到桌面
echo "~~~~~開始編譯~~~~~"
#修改plist 版本號,修改build號函式--放在呼叫前
PlistBuddy_setting(){
echo "~~~~~修改plist版本號~~~~~"
bundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $info_plist`
bundleIdentifier=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $info_plist`
bundleBuildVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $info_plist`
echo "~~~工程名~~~~~$Project_Name~~Bundle ID~~~$bundleIdentifier~~版本號~~~~~$bundleBuildVersion"
if [ ! -n $version_string ]; then
echo "IS NULL"
else
# 修改版本號
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version_string" "${info_plist}"
fi
if [ ! -n $version_string ]; then
echo "IS NULL"
else
# 修改build號
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $build_number" ${info_plist}
fi
}
xcodebuild_Archive(){
xcodebuild -project $Project_Name.xcodeproj -scheme $Project_Name -configuration Release -archivePath $Project_Name-enterprise.xcarchive clean archive build CODE_SIGN_IDENTITY="${ENTERPRISECODE_SIGN_IDENTITY}" PROVISIONING_PROFILE="${ENTERPRISEROVISIONING_PROFILE_NAME}" PRODUCT_BUNDLE_IDENTIFIER="${EnterpriseBundleID}"
}
xcodebuild_ExportArchive(){
xcodebuild -exportArchive -archivePath $Project_Name-enterprise.xcarchive -exportOptionsPlist $EnterpriseExportOptionsPlist -exportPath $ipa_outPath
}
#清理工程
xcodebuild -project ${Project_Path}/${Project_Name}.xcodeproj clean
#利用PlistBuddy修改plist資訊
PlistBuddy_setting;
#企業打包指令碼
xcodebuild_Archive; #第一步--archive-.xcarchive
xcodebuild_ExportArchive; #第二步--exportArchive-ipa
if [ -d "$ipa_outPath" ]; then
echo "匯出成功✅!! $ipa_outPath"
open $ipa_outPath
fi