iOS 自动化构建 xcodebuild实现方法
程序员文章站
2023-08-24 08:59:09
xcidebuild
apple 官网 xcodebuild 文档
使用 shell 实现 clean、build、archive、export 等功能
自动化构建主要还是使用 clean、arc...
xcidebuild
apple 官网 xcodebuild 文档
先用 xcode 手动打个包,比如 ad_hot 的包并导出,可以得到 ipa 包,以及「exportoptions.plist」以供后续使用(打 appstore 包,也会有一个)使用 shell 实现 clean、build、archive、export 等功能
自动化构建主要还是使用 clean、archive、export
project 自动签名
#!/bin/bash # jenkins 下,默认是项目文件夹,也是默认参数(此处用以本机测试) workspace=~/desktop/test # 项目路径 project_name="test" target_name="test" project_path=${workspace}/$project_name.xcodeproj # 输出配置 # export_options_plist 的 plist 就是打包来的 exportoptions.plist,修改了名字 export_options_plist=${workspace}/export/export_ad_hot.plist res_dir=~/desktop/${target_name}pack res_archive_path=${res_dir}/ach.xcarchive res_ipa_dir=${res_dir}/ipa res_ipa_path=${res_ipa_dir}/${target_name}.ipa # clean xcodebuild other_cflags="-fembed-bitcode" clean -project $project_path -scheme $target_name # archive xcodebuild other_cflags="-fembed-bitcode" archive -archivepath $res_archive_path -project $project_path -scheme $target_name # export xcodebuild other_cflags="-fembed-bitcode" -exportarchive -archivepath $res_archive_path -exportpath $res_ipa_dir -exportoptionsplist $export_options_plist echo "打包成功:${res_ipa_path}"
workspace 手动签名
#!/bin/bash # jenkins 下,默认是项目文件夹,也是默认参数(此处用以本机测试) workspace=~/desktop/qiakr export lc_all=zh_cn.gb23https://blog.csdn.net/u013059266/article/details/12;export lang=zh_cn.gb23https://blog.csdn.net/u013059266/article/details/12 # 项目路径 workspace_name="xxx" target_name="xxx" workspace_path=${workspace}/realcloud/xxxx/${workspace_name}.xcworkspace # 项目配置 build_config="release" product_bundle_identifier="com.xxx.xxxx.app" code_sign_identity="iphone distribution: hangzhou xxxx technology co, ltd. (xxxx)" provisioning_profile="xxxx-e40b-487b-8a2c-xxxxx" enable_bitcode="yes" # 输出配置 export_options_plist=~/desktop/ad_hot_qa.plist res_dir=~/desktop/${target_name}-pack res_archive_path=${res_dir}/ach.xcarchive res_ipa_dir=${res_dir}/ipa res_ipa_path=${res_ipa_dir}/${target_name}.ipa # clean xcodebuild other_cflags="-fembed-bitcode" clean -workspace $workspace_path -scheme $target_name # archive xcodebuild other_cflags="-fembed-bitcode" archive -archivepath $res_archive_path -workspace $workspace_path -scheme $target_name -configuration $build_config code_sign_identity="${code_sign_identity}" provisioning_profile=${provisioning_profile} product_bundle_identifier=${product_bundle_identifier} enable_bitcode=${enable_bitcode} # export xcodebuild other_cflags="-fembed-bitcode" -exportarchive -archivepath $res_archive_path -exportpath $res_ipa_dir -exportoptionsplist $export_options_plist echo "打包成功:${res_ipa_path}"
相关说明
project 和 workspace 都是可以手动和自动的,手动的话需要配置证书和配置文件
pod 之后的就对应使用 workspace,不使用 project
附录https://blog.csdn.net/u013059266/article/details/1:上传蒲公英
蒲公英文档
很简单,注意 path 即可
path=$res_ipa_path api_key=742cd3ecaehttps://blog.csdn.net/u013059266/article/details/1032adc45a6ce59d759c7f msg="qa 测试包-正式环境" a=$(curl -f "file=@$path" -f "_api_key=$api_key" -f "buildupdatedescription=${msg}" https://www.pgyer.com/apiv2/app/upload)
附录2:jenkins 补充
# 构建后操作:补充个二维码下载安装链接 # set build description # "appqrcodeurl":"(.*)" #
附录3:sh 运行权限
添加本地 sh 文件运行权限 chmod u+x ~/desktop/test.sh