自动化方案大概有三种:
Jinkens
fastlane
shell脚本 Jinkens有图形界面,比较可视化,但是需要注册,下载软件,配置了半天,还是没成功,我就先不处理了;
shell脚本,需要脚本功底;
fastlane
开源,安装方便,可持续交付,很多朋友也推荐,所以果断用吧;
1、打开终端,安装Xcode command line tools:
xcode-select --install
如果没有安装,则会提示安装:
如果已经安装,则提示
2、安装Fastlane
sudo gem install fastlane
检查是否安装成功:
终端输入:
fastlane --version
可以看到版本号信息,就表示安装成功;
3、fastlane 初始化
终端cd 打开工程所在目录,执行fastlane init
,会出现下图提示:
这里我选择4
,手动配置,然后回车,一路回车;等看到如下提示,就表示fastlane初始化完成;
接着就可以看到,项目工程里,多出了几个文件:
我们需要在Appfile、Fastfile两个文件中,配置相关信息;
配置 Appfile 文件
Appfile:添加App相关信息;
# app_identifier("[[APP_IDENTIFIER]]") # The bundle identifier of your app
# apple_id("[[APPLE_ID]]") # Your Apple email address
# For more information about the Appfile, see:
# https://docs.fastlane.tools/advanced/#appfile
app_identifier "com.****.****" # bundleId
apple_id "*******@xxxx.com" # 苹果账号
team_id "*******" # 团队ID
# 有多个账号的时候 可以for_lane这样添加多个;
# for_lane :inhouse do
# app_identifier "com.****.****" # bundleId
# apple_id "*******@xxxx.com" # 苹果账号
# team_id "*******" # 团队ID
# end
配置 Fastfile 文件
Fastfile:配置打包相关信息;
默认的Fastfile文件是这样的:
Fastfile文件解读
lane
解读:
我的Fastfile
文件配置,仅供参考:
# 指定平台,可以设置为 ios、android、mac
default_platform(:ios)
platform :ios do
# 打包描述
desc "Description of what the lane does"
#lane :xxxxx do,xxxx一般写项目名称,注意分号后面不能有空格
lane :xxxx do
gym(
# 每次打包之前clean一下
clean: true,
scheme: "xxxx",#打包的scheme名称
configuration: 'xxxx',#configuration配置,默认有Release、Debug两种模式,如果有自定义的话,就写你自定义的configuration就行
#export_method:可选的值有:app-store、ad-hoc、development、enterprise
export_method:"ad-hoc", #打包的类型
include_bitcode: true,# 是否包含bitcode
include_symbols: true,# 是否包含symbols
output_directory: 'xxxxxx',#ipa包导出址
output_name:"xxxx.ipa", #ipa包名
#export_xcargs 如果项目是自动管理证书的方式,直接按照我的来写就行,
#如果是手工管理,则需要手动配置证书文件,自行百度吧😂
export_xcargs: '-allowProvisioningUpdates',
export_options: { iCloudContainerEnvironment: "Production"},#导出Production类型的ipa包
)
notification(app_icon: './fastlane/icon.png', title: 'manager', subtitle: '打包成功,已导出安装包', message: '开始准备发布……')#使用终端提示打包成功
#ipa包自动发布到fir
firim(firim_api_token: "xxxxxx") # token 在fir 上查看
end
end
提示⚠️:不知道自己的Scheme是什么的,可以去Product->Scheme->Edit Scheme下查看Scheme名称
安装fir.im 插件
安装fir,需要有Gemfile文件,所以必须进入项目所在路径,终端cd
进入项目所在路径,执行以下命令:
fastlane add_plugin firim
根据终端的提示,输入
y
即可;
安装完成后,在Gemfile文件中,就会出现如下信息:
4、打包
配置Appfile、Fastfile、安装fie.im插件完成后,接下来就开始打包;
使用终端进入项目所在路径,执行如下命令:
fastlane xxxx
# 提示:
# xxxx 是Fastfile文件里,lane后面的项目名称
静候打包完成,大功告成
5、fastlane其他配置
fastlane还有很多配置功能,比如上传App Store,自动增加版本号等等,后续再一点一点补充文章;
请谅解😂😂😂
6、补充说明:export_options: { iCloudContainerEnvironment: "Production"}
因为我的项目里,使用到iCloud,所以在打包的时候,必须增加export_options选项;
如果你的项目里,没有使用到,可以去掉;