之前在Xcode8之前,写过一个自动打包脚本,一次可以打包多个不同渠道的包,后来Xcode升级后,不能用了,因为8之后,使用xcodebuild命令,需要exportOptionsPlist参数,才能导出ipa,所以要改造一下:
一、准备配置信息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
# 渠道 测试、发布
CONFIGURATIONS="Debug Release"
# 发布包配置
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参数设置(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
#导出.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 '*** 当前版本:'$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文件已导出 ***"
open $exportFilePath
else
echo "*** 创建.ipa文件失败 ***"
fi
echo '*** 打包完成 ***'
mv $exportFilePath/$scheme_name.ipa $exportFilePath/${scheme_name}_V${bundleShortVersion}.ipa || failed "mv ipa"
done
四、把脚本文件放在项目的根目录下(有workspace的目前)
打开终端,cd 到项目所在路径,执行sh auto.sh回车,等待一会,在build目录就会出现对应的渠道的ipa