- 环境:Xcode 12
- 利用 自带命令 xcodebuild 实现自动打包
- 通过 xcrun altool 自动上传
说明:
- 根据需要自行修改脚本中的路径,确保路径正确。通常打包失败的原因是没有读取到 ExportOptions.plist ,或者 ExportOptions.plist 配置有误。
- AppleID账号的密码,可以去appleid.apple.com申请专用密码,跳过2步验证。
AutoBuild.sh
#!/bin/sh
#
# 使用方式:
# 1 cd到脚本目录
# 2 执行AutoBuild.sh脚本
#工程绝对路径
# project_path=$(`dirname $0`; pwd)
# 打包名
archiveName="puzzleCube"
# 工程名
# project_name=$PWD/../puzzleCube
# workspace名
project_workspace=$PWD/../puzzleCube.xcworkspace
# Scheme名
project_scheme="puzzleCube"
# 编译模式 Release Debug
build_type="Release"
# archive_path
archive_path=$PWD/../BuildScript/build/temp/${archiveName}.xcarchive
# ipa文件存放路径
export_ipa_path=$PWD/../BuildScript/build/${build_type}/${archiveName}
# exportOptions plist
export_options_plist=$PWD/../BuildScript/ExportOptions.plist
# apple开发者账号
appleid=""
# 密码,最好是专用密码
applepassword=""
echo "http:///-----------"
echo "http:/// 正在清理工程"
echo "http:///-----------"
xcodebuild clean -workspace $project_workspace -scheme $project_scheme -configuration $build_type -quiet || exit
echo "http:///-----------"
echo "http:/// 正在编译工程: ${build_type}"
echo "http:///-----------"
xcodebuild archive -workspace ${project_workspace} -scheme ${project_scheme} -configuration $build_type -archivePath $archive_path || exit
echo "http:///-----------"
echo "http:/// 开始导出ipa: ${export_ipa_path}"
echo "http:///-----------"
xcodebuild -exportArchive -archivePath $archive_path -exportPath ${export_ipa_path} -exportOptionsPlist ${export_options_plist} -allowProvisioningUpdates YES -quiet || exit
echo "http:///-----------"
echo "http:/// 开始验证ipa: $export_ipa_path/$project_scheme.ipa"
echo "http:///-----------"
# xcrun altool --validate-app -f $export_ipa_path/$project_scheme.ipa -u $appleid -p $applepassword --output-format xml
echo "http:/// 命令已注释"
echo "http:///-----------"
echo "http:/// 开始上传ipa:${export_ipa_path}/${project_scheme}.ipa"
echo "http:///-----------"
# xcrun altool --upload-app -f $export_ipa_path/$project_scheme.ipa -u $appleid -p $applepassword --output-format xml
echo "http:/// 命令已注释"
ExportOptions.plist
- method :此参数的值有四种类型 app-store, ad-hoc, enterprise or development
- signingCertificate: 根据method类型选择填Apple Distribution 或者 Apple Development
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>destination</key>
<string>export</string>
<key>method</key>
<string>app-store</string>
<key>provisioningProfiles</key>
<dict>
<key>app的bundleID</key>
<string>描述文件名字,或者UUID</string>
</dict>
<key>signingCertificate</key>
<string>Apple Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>你的teamID</string>
<key>uploadBitcode</key>
<false/>
<key>uploadSymbols</key>
<false/>
</dict>
</plist>