-
下载脚本和对应的plist
-
链接: https://pan.baidu.com/s/18PP5MSb6uHChEQ2i9bh30Q
经过修改,自己写出的脚本打包分四种模式 1:app-store 2:fir 3:蒲公英 4:development
-
一、配置自动打包发布的流程
1、创建Shell脚本
2、将Shell脚本文件拖入工程的根目录
3、根据自己需求选择好描述文件(测试包或是正式包)
4、根据自己的项目修改一下shell.sh
5、cd到工程根目录,通过./shell.sh 执行脚本即可
将通过这几步来讲解整个过程
准备工作
准备工作做完后,正式开启自动化之路
准备工作
-
1、终端执行 gem install fir-cli
因为要上传到Fir平台,需要先安装fir-cli
-
2、安装RVM
如果没有安装过rvm,需要安装rvm,在终端输入rvm -v命令查看,如果打印出rvm:command not found说明没有安装过rvm,如果能打印出rvm版本等信息说明安装过。如果没有安装过rvm可以通过下面的命安装,如果已经安装过可以忽略。
在终端输入 curl -L get.rvm.io | bash -s stable ,然后稍等一会rvm就安装好了
在终端输入 source ~/.bashrc
在终端输入 source ~/.bash_profile
再输入rvm -v查看安装成功
3.准备工作做完后,正式开启自动化之路
在Xcode配置证书。我这边直接让Xcode自动管理,当然,你也可以手动配置
二、修改一下shell.sh 文件
根据自己项目实际,修改为自己的项目名称
完整脚本,上传到App Store,其它可自行加上(可用)
#!/bin/bash
# 自己的AppleID账号密码
AppleID="AppleID"
AppleID_Password="AppleID密码"
project_path=$(pwd)
#取当前时间字符串添加到文件结尾
now=$(date +%Y-%m-%d-%H\:%M\:%S)
#取当前日期
today=$(date +%Y-%m-%d)
# 指定项目的scheme名称
scheme="项目的scheme名称"
# 指定项目名
project_name="项目名"
# 指定要打包的配置名
configuration="Release"
# plist文件所在目录
exportOptionsPlistPath=${project_path}/ExportOptionsForAppStore.plist
# 指定项目地址
workspace_path="${project_path}/${project_name}.xcworkspace"
# 指定输出路径
output_path="$HOME/Library/Developer/Xcode/Archives"
# 指定输出归档文件夹地址
archiveFinder_path="${output_path}/${today}"
# 指定输出归档文件地址
archive_path="${archiveFinder_path}/${project_name}${now}.xcarchive"
# 指定ipa输出地址
ipa_path="~/Desktop/Firestonelamp-IPA/${project_name}${now}"
# altool工具路径
altoolPath="/Applications/Xcode10.1.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
#输出设定的变量值
echo "===workspace path : ${workspace_path}==="
echo "===archive path : ${archive_path}==="
echo "===ipa path : ${ipa_path}==="
echo "===profile : ${provisioning_profile}==="
#先clean一下
echo "===开始 clean 工程==="
xcodebuild clean \
-workspace ${workspace_path} \
-scheme ${scheme} \
-configuration ${configuration} \
-quiet || exit
echo "===clean 完成==="
#根据指定的项目, scheme, configuration, 输出路径, 打出archive包
echo "===开始打包==="
if [ ! -d "${archiveFinder_path}" ]; then
mkdir ${archiveFinder_path}
fi
xcodebuild archive \
-workspace ${workspace_path} \
-scheme ${scheme} \
-configuration ${configuration} \
-archivePath ${archive_path} \
-quiet
echo "===打包完成==="
#导出ipa包
echo "===正在导出ipa==="
xcodebuild \
-allowProvisioningUpdates \
-exportArchive \
-archivePath ${archive_path} \
-configuration ${configuration} \
-exportPath ${ipa_path} \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet
echo "===.ipa 文件已导出==="
# open ${ipa_path}
# 验证并上传到App Store
echo "===验证并上传到App Store==="
"$altoolPath" --validate-app -f ${ipa_path}/${project_name}.ipa \
-u ${AppleID} -p ${AppleID_Password} \
-t ios --output-format xml
"$altoolPath" --upload-app -f ${ipa_path}/${project_name}.ipa \
-u ${AppleID} -p ${AppleID_Password} \
-t ios --output-format xml
echo "===上传完成==="
exit
-
脚本解释:
清理构建目录
echo "===开始 clean 工程==="
xcodebuild clean \
-workspace ${workspace_path} \
-scheme ${scheme} \
-configuration ${configuration} \
-quiet || exit
echo "===clean 完成==="
编译之前先clean下,就如同在Xcode进行Product -> Clean。
编译打包成Archive
xcodebuild archive \
-workspace ${workspace_path} \
-scheme ${scheme} \
-configuration ${configuration} \
-archivePath ${archive_path} \
-quiet
编译工程,编译并生成.xcarchive文件,放在build_path下,名字是project_name.xcarchive,就如在Xcode进行Product -> Archive这一步最为耗时.
将Archive导出ipa
xcodebuild \
-allowProvisioningUpdates \
-exportArchive \
-archivePath ${archive_path} \
-configuration ${configuration} \
-exportPath ${ipa_path} \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet
将生成的.xcarchive文件导出.ipa包到指定的exportIpaPath路径下。
-
说明:
用\来进行换行分隔,一条shell命令过长时可以进行分割显示. $变量名是引用变量,拿来使用 || exit 指明如果这一条命令执行失败,则退出当前shell.
-
通过Fir-cli命令上传到Fir平台
# 将XXX替换成自己的Fir平台的token
fir login -T XXX
fir publish $exportIpaPath/$scheme_name.ipa
-
通过altool工具提交ipa包到app store
这个工具实际上是Application Loader,打开Xcode-左上角Xcode-Open Developer Tool-Application Loader 可看到,它的路径:
# altool工具路径
altoolPath="/Applications/Xcode10.1.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
验证并上传到App Store # 将-u 后面的AppleID替换成自己的AppleID的账号,-p后面的AppleID_Password替换成自己的密码
echo "===验证并上传到App Store==="
"$altoolPath" --validate-app -f ${ipa_path}/${project_name}.ipa \
-u ${AppleID} -p ${AppleID_Password} \
-t ios --output-format xml
"$altoolPath" --upload-app -f ${ipa_path}/${project_name}.ipa \
-u ${AppleID} -p ${AppleID_Password} \
-t ios --output-format xml
echo "===上传完成==="
上传到App Store的命令解释
exportAppstore.plist: 新建一个plist文件, 里面是一个Dictionary, key-value如下, 都是可选值, 不需要全部填上,可参考最底下链接下载参考
compileBitcode: Bool
For non-App Store exports, should Xcode re-compile the app from bitcode? Defaults to YES.
embedOnDemandResourcesAssetPacksInBundle : Bool
For non-App Store exports, if the app uses On Demand Resources and this is YES, asset packs are embedded in the app bundle so that the app can be tested without a server to host asset packs. Defaults to YES unless onDemandResourcesAssetPacksBaseURL is specified.
iCloudContainerEnvironment
For non-App Store exports, if the app is using CloudKit, this configures the "com.apple.developer.icloud-container-environment" entitlement. Available options: Development and Production. Defaults to Development.
manifest : Dictionary
For non-App Store exports, users can download your app over the web by opening your distribution manifest file in a web browser. To generate a distribution manifest, the value of this key should be a dictionary with three sub-keys: appURL, displayImageURL, fullSizeImageURL. The additional sub-key assetPackManifestURL is required when using on demand resources.
method : String
Describes how Xcode should export the archive. Available options: app-store, ad-hoc, package, enterprise, development, and developer-id. The list of options varies based on the type of archive. Defaults to development.
onDemandResourcesAssetPacksBaseURL : String
For non-App Store exports, if the app uses On Demand Resources and embedOnDemandResourcesAssetPacksInBundle isn't YES, this should be a base URL specifying where asset packs are going to be hosted. This configures the app to download asset packs from the specified URL.
teamID : String
The Developer Portal team to use for this export. Defaults to the team used to build the archive.
thinning : String
For non-App Store exports, should Xcode thin the package for one or more device variants? Available options:
(Xcode produces a non-thinned universal app), (Xcode produces a universal app and all available thinned variants), or a model identifier for a specific device (e.g. "iPhone7,1"). Defaults to .
uploadBitcode : Bool
For App Store exports, should the package include bitcode? Defaults to YES.
uploadSymbols : Bool
For App Store exports, should the package include symbols? Defaults to YES.
-
下载脚本和对应的plist
-
链接: https://pan.baidu.com/s/18PP5MSb6uHChEQ2i9bh30Q
经过修改,自己写出的脚本打包分四种模式 1:app-store 2:fir 3:蒲公英 4:development
-
-
问题1:账号开启认证问题
Please sign in with an app-specific password. You can create one at appleid.apple.com
-
解决办法
- 问题2:build号相同,在Xcode的改下项目的build版本号
参考文章:
iOS一键搞定自动打包并发布到AppStore和Fir
iOS的打包、发布库 CLI for Building & Distributing iOS Apps (.ipa Files)
-
轻轻点击,关注我
-
轻轻点击,在慕课网关注我
-
关注我
-
浏览我的GitHub
-
扫一扫,关注我的公众号