#打包目录
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开发证书:$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导出路径:$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 清理构建目录
# xcodebuild clean -configuration "$configuration" -alltargets
xcodebuild clean -configuration "$configuration" -alltargets >> $log_path
# 5 归档(其他参数不指定的话,默认用的是.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 导出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平台的代码,如果只是需要打包的话,不需要下面两个步骤,如果需要上传到相应平台可以解开相关注释
# 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"
注意事项
执行脚本之前,先用Xcode打包一遍,将ExportOptions.plist文件复制到打包目录下面,否则执行脚本会提示找不到ExportOptions.plist文件内容