之前在Xcode8之前晤郑,寫過一個自動打包腳本永脓,一次可以打包多個不同渠道的包袍辞,后來Xcode升級后,不能用了常摧,因為8之后搅吁,使用xcodebuild命令,需要exportOptionsPlist參數(shù)排宰,才能導(dǎo)出ipa似芝,所以要改造一下:
一、準(zhǔn)備配置信息build.config
# used to name the ipa
app_name=myproject
#工程絕對路徑
project_path=$(pwd)
#工程名
project_name=$app_name
#scheme名
scheme_name=$project_name
project_infoplist_path=${project_path}/${project_name}/Info.plist
#build文件夾路徑
build_path=${project_path}/build
# 渠道 測試板甘、發(fā)布
CONFIGURATIONS="Debug Release"
# 發(fā)布包配置
ProvisionFile?Debug="6de66157-ef56-4ab8-8eb5-32c902d42xxx"
CodesignDebug="iPhone Distribution: xxxx"
BundleIdDebug="com.xxx.myproject"
ProvisionFileNameDebug="xxxAd"
ProvisionFileRelease="338587dc-1194-4f0f-94b2-ef94c6945xxx"
CodesignRelease="iPhone Distribution: xxxx"
BundleIdRelease="com.xxx.myproject"
ProvisionFileNameRelease="xxxRelease"
# 電腦的登錄密碼
LOGIN_PASSWORD="xxx"
二党瓮、exportOptionsDebug.plist參數(shù)設(shè)置(Release的把method修改為app-store即可)
這里的'method': 可選項為 {app-store, ad-hoc, enterprise, development}
三、自動打包腳本autoPack.sh
# read config
. ./build.config
# unlock login keygen
security unlock-keychain -p ${LOGIN_PASSWORD} ${LOGIN_KEYCHAIN} || failed "unlock-keygen"
for config in $CONFIGURATIONS; do
#導(dǎo)出.ipa文件所在路徑
exportFilePath=${build_path}/${config}-iphoneos
#plist文件所在路徑
exportOptionsPlistPath=${project_path}/exportOptions$config.plist
echo '*** 正在 清理工程 ***'
xcodebuild \
clean -configuration ${config} -quiet? || exit
echo '*** 清理完成 ***'
echo '*** 正在 編譯工程 For '${config}
provfile=$(eval echo \$`echo ProvisionFile$config`)
codesign=$(eval echo \$`echo Codesign$config`)
bundleid=$(eval echo \$`echo BundleId$config`)
provisionfile=$(eval echo \$`echo ProvisionFileName$config`)
#取版本號
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${project_infoplist_path})
echo '*** 當(dāng)前版本:'$bundleShortVersion
xcodebuild \
archive -workspace ${project_path}/${project_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${config} \
-destination generic/platform=iOS \
CODE_SIGN_IDENTITY="${codesign}" \
PRODUCT_BUNDLE_IDENTIFIER=$bundleid \
PROVISIONING_PROFILE=$provfile \
-archivePath ${build_path}/${project_name}.xcarchive -quiet? || exit
echo '*** 編譯完成 ***'
echo '*** 正在 打包 ***'
xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
-configuration ${config} \
-exportPath ${exportFilePath} \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet || exit
if [ -e $exportFilePath/$scheme_name.ipa ]; then
echo "*** .ipa文件已導(dǎo)出 ***"
open $exportFilePath
else
echo "*** 創(chuàng)建.ipa文件失敗 ***"
fi
echo '*** 打包完成 ***'
mv $exportFilePath/$scheme_name.ipa $exportFilePath/${scheme_name}_V${bundleShortVersion}.ipa || failed "mv ipa"
done
四盐类、把腳本文件放在項目的根目錄下(有workspace的目前)
打開終端寞奸,cd 到項目所在路徑,執(zhí)行sh auto.sh回車在跳,等待一會枪萄,在build目錄就會出現(xiàn)對應(yīng)的渠道的ipa