点击右侧关注,了解黑客的世界!
点击右侧关注,掌握进阶之路!
点击右侧关注,探讨技术话题!
作者丨芦苇科技App技术团队
https://juejin.im/post/5d5a6dcaf265da03ea5a7d69
目的
封装一个打包小机器人小应用,双击就能让项目自动打包上传到fir.im上
思路
用.sh脚本执行xcodebuild命令进行打包,后fir-cli命令上传到fir.im,测试可以正常打包后用Mac自带的自动化工具执行该脚本
过程
一 环境配置 1.确定ruby存在
ruby -v
2.安装fir-cli
sudo gem install fir-cli
3.检查xcodebuild是否安装
xcode-select --install
二 相关文件及证书配置 这里需要配置文件里需要一个.sh的脚本,以及一张对应的证书配置表.plist,这里把这些都放在scripts文件夹里
(地址:https://github.com/propertyChen/scripts)
然后把scripts文件夹放到工程目录里
.plist表配置如下
需要填写的有 teamID ,method, provisioningProfiles个人比较推荐从之前手动打包所产生的ExportOptions.plist文件里获取
debug_config.plist与ExportOptions.plist的对应关系,其中method内测就用development,上架用App Store
四 .sh说明
#!/bin/sh
# Your configuration information
target_name="xxxxxx.xcodeproj" # 有效值 ****.xcodeproj / ****.xcworkspace (cocoapods项目)
project_name="xxxxxx" # 工程名
work_type="workspace" # 有效值 project / workspace (cocoapods项目)
api_token="你fir的tonken" # fir token
sctipt_path=$(cd `dirname $0`; pwd)
echo sctipt_path=${sctipt_path}
work_path=${sctipt_path}/..
rm -rf ${work_path}/build
#cd ../
#pod install --no-repo-update
#cd ${sctipt_path}
out_sub_path=`date "+%Y-%m-%d-%H-%M-%S"`
out_base_path="../打包文件"
out_path=${work_path}/${out_base_path}/${out_sub_path}
mkdir -p ${out_path}
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
source $HOME/.rvm/scripts/rvm
rvm use system
fi
xcodebuild -$work_type ${work_path}/$target_name -scheme $project_name -configuration Debug -sdk iphoneos clean
xcodebuild archive -$work_type ${work_path}/$target_name -scheme $project_name -configuration Debug -archivePath ${out_path}/$project_name.xcarchive
xcodebuild -exportArchive -archivePath ${out_path}/$project_name.xcarchive -exportPath ${out_path} -exportOptionsPlist ${sctipt_path}/debug_config.plist
echo ${out_path}/$project_name.ipa
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
source ~/.rvm/scripts/rvm
rvm use default
fi
fir p ${out_path}/$project_name.ipa -T $api_token -c 发布debug版本
exit 0
这是我这边使用的脚本,虽然虽然完全没学过脚本语言,但认真看还是很容易懂得,到mkdir -p ${out_path}之前无非就是配置各种路径,重点是在下面
xcodebuild -$work_type ${work_path}/$target_name -scheme $project_name -configuration Debug -sdk iphoneos clean
xcodebuild archive -$work_type ${work_path}/$target_name -scheme $project_name -configuration Debug -archivePath ${out_path}/$project_name.xcarchive
xcodebuild -exportArchive -archivePath ${out_path}/$project_name.xcarchive -exportPath ${out_path} -exportOptionsPlist ${sctipt_path}/dev_config.plist
xcodebuild命令 clean,archive,exportArchive是不是很熟悉的感觉,就是我们常规的清除、打包、导出等操作用命令的方式执行而已
fir p ${out_path}/$project_name.ipa -T $api_token -c
这点就是之前需要fir-cli的原因,这段就是用fir-cli命令上传已经打包好的ipa,其中对应的fir token需要登录fir.im获取
到这里基本工作都弄完了,终端cd到你工程目录下scripts文件夹,直接执行.sh文件就可以自动打包了
bash -l dev_config.sh
如果什么意外在工程目录的上一级会出现一个文件夹,里面有如下东西
五 包装成Mac应用
其实到上面一步基本就完成,但作为程序员应该更懒,这里我们可以利用Mac自带的自动化操作将终端命令封装保存
然后你就有属于自己的自动打包机器人啦,双击运行直接自动打包上传到fir.im
六 可能出现的问题
如果执行机器人时直接报错或者打包后生产空文件夹空,则可能是环境配置问题,需要从新开始配置
如果打包出来只有.xcarchive文件,则是证书配置问题,需要重新检查证书
如果有生成.api但却没成功上次到fir.im则可能是输入的fir token有误,或者fil-cil没安装成功
推荐↓↓↓
长
按
关
注
?【16个技术公众号】都在这里!
涵盖:程序员大咖、源码共读、程序员共读、数据结构与算法、黑客技术和网络安全、大数据科技、编程前端、Java、Python、Web编程开发、Android、iOS开发、Linux、数据库研发、幽默程序员等。
万水千山总是情,点个 “在看” 行不行