#打包目錄
upload_path="在此填寫項目打包絕對路徑"
#項目路徑
target_path="在此填寫項目所在目錄絕對路徑"
echo "打包路徑:$upload_path"
echo "項目路徑:$target_path"
#配置信息 release版本
configuration="Debug"
#項目名稱
target_name="項目名稱"
project_name="${target_name}.xcodeproj"
workspace_name="${target_name}.xcworkspace"
scheme="$target_name"
echo "configuration配置:$configuration"
echo "project_name名稱:$project_name"
echo "target_name項目名稱:$target_name"
echo "workspace_name工作空間名稱:$workspace_name"
echo "scheme名稱:$scheme"
## archive包時使用證書瓤摧、描述文件UUID战转;ipa包時使用描述文件(描述文件名稱)
codeSignIdentity="iPhone Developer"
provision_UUID="描述文件UUID"
provisoning_profile="描述文件名稱"
echo "codeSignIdentity開發(fā)證書:$codeSignIdentity"
echo "provision_UUID描述文件UUID:$provision_UUID"
echo "provisoning_profile描述文件:$provisoning_profile"
# 指定目錄時
cd "$upload_path"
ipa_path="$upload_path/${target_name}"
archive_path="$upload_path/${target_name}.xcarchive"
exportOptionsPlist_path="$upload_path/ExportOptions.plist"
log_path="$upload_path/log.txt"
pwd
echo "ipa_path導(dǎo)出路徑:$ipa_path"
echo "archive_path生成路徑:$archive_path"
echo "plist生成路徑:$exportOptionsPlist_path"
echo "log_path打印路徑:$log_path"
# 3 刪除舊文件
rm -rf "$log_path"
rm -rf "$archive_path"
rm -rf "$ipa_path"
cd "$target_path"
pwd
# 4 清理構(gòu)建目錄
# xcodebuild clean -configuration "$configuration" -alltargets
xcodebuild clean -configuration "$configuration" -alltargets >> $log_path
# 5 歸檔(其他參數(shù)不指定的話运怖,默認用的是.xcworkspace或.xcodeproj文件里的配置)
xcodebuild archive -workspace "$workspace_name" -scheme "$scheme" -configuration "$configuration" -archivePath "$archive_path" CODE_SIGN_IDENTITY="$codeSignIdentity" PROVISIONING_PROFILE="$provision_UUID" >> $log_path
# 6 導(dǎo)出IPA
xcodebuild -exportArchive -exportOptionsPlist "$exportOptionsPlist_path" -archivePath "$archive_path" -exportPath "$ipa_path" PROVISIONING_PROFILE_SPECIFIER="$provisoning_profile" >> $log_path
echo "file=@$upload_path/$target_name.ipa"
# 7钱烟、8是上傳到蒲公英和fir平臺的代碼,如果只是需要打包的話夭咬,不需要下面兩個步驟,如果需要上傳到相應(yīng)平臺可以解開相關(guān)注釋
# 7 上傳IPA到蒲公英
# curl -F "file=@$upload_path/$target_name/$target_name.ipa" \
# -F "_api_key=在此替換蒲公英上面的apiKey" \
# https://www.pgyer.com/apiv2/app/upload
#8 上傳到fir平臺
# 將XXX替換成自己的Fir平臺的token
# fir login -T XXX
# fir publish "$upload_path/$target_name/$target_name.ipa"
注意事項
執(zhí)行腳本之前,先用Xcode打包一遍钞瀑,將ExportOptions.plist文件復(fù)制到打包目錄下面,否則執(zhí)行腳本會提示找不到ExportOptions.plist文件內(nèi)容