iOS一键打包机器人实现

640?wx_fmt=jpeg

黑客技术

点击右侧关注,了解黑客的世界!

640?wx_fmt=jpeg

640?wx_fmt=jpeg

Java开发进阶

点击右侧关注,掌握进阶之路!

640?wx_fmt=jpeg

640?wx_fmt=jpeg

Python开发

点击右侧关注,探讨技术话题!

640?wx_fmt=jpeg


作者丨芦苇科技App技术团队
https://juejin.im/post/5d5a6dcaf265da03ea5a7d69


目的


封装一个打包小机器人小应用,双击就能让项目自动打包上传到fir.im上



640?wx_fmt=other


思路


用.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文件夹放到工程目录里



640?wx_fmt=other



.plist表配置如下


640?wx_fmt=other

需要填写的有 teamID ,method, provisioningProfiles个人比较推荐从之前手动打包所产生的ExportOptions.plist文件里获取


640?wx_fmt=other


debug_config.plist与ExportOptions.plist的对应关系,其中method内测就用development,上架用App Store


640?wx_fmt=other

四 .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


如果什么意外在工程目录的上一级会出现一个文件夹,里面有如下东西


640?wx_fmt=other

五 包装成Mac应用


其实到上面一步基本就完成,但作为程序员应该更懒,这里我们可以利用Mac自带的自动化操作将终端命令封装保存


640?wx_fmt=other


640?wx_fmt=other


然后你就有属于自己的自动打包机器人啦,双击运行直接自动打包上传到fir.im

640?wx_fmt=other


六 可能出现的问题


  • 如果执行机器人时直接报错或者打包后生产空文件夹空,则可能是环境配置问题,需要从新开始配置

  • 如果打包出来只有.xcarchive文件,则是证书配置问题,需要重新检查证书

  • 如果有生成.api但却没成功上次到fir.im则可能是输入的fir token有误,或者fil-cil没安装成功


 推荐↓↓↓ 

640?wx_fmt=jpeg

?16个技术公众号】都在这里!

涵盖:程序员大咖、源码共读、程序员共读、数据结构与算法、黑客技术和网络安全、大数据科技、编程前端、Java、Python、Web编程开发、Android、iOS开发、Linux、数据库研发、幽默程序员等。

640?wx_fmt=png

万水千山总是情,点个 “在看” 行不行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值