selector

Fastlane的使用及进阶

2020-10-12  本文已影响0人  风ai翔
image
一、Fastlane是什么

1、简介
Fastlane是用Ruby语言编写的一套自动化工具集和框架,每一个工具实际都对应一个Ruby脚本,用来执行某一个特定的任务,而Fastlane核心框架则允许使用者通过类似配置文件的形式,将不同的工具有机而灵活的结合在一起,从而形成一个个完整的自动化流程。

2、原理

3、功能

二、Fastlane的安装

安装参考:https://www.jianshu.com/p/c38157e5d6c1

ruby版本必须高于2.0,macbook自带的ruby可能低于2.0
不要卸载、更改mac系统内置的ruby!mac系统需要它,更改以后,会导致mac系统故障!
使用rvm管理和安装指定版本的ruby

三、Fastlane使用及问题

1、fastlane init 的选择问题

fastlane init

新版本安装的时候出现了下面的分支选择,按要求选择就行

1.   Automate screenshots(自动截屏)
2.   Automate beta distribution to TestFlight (自动testfilght型配置)
3.   Automate App Store distribution (自动发布型配置)
4.   Manual setup - manually setup your project to automate your (需要手动配置内容)

这里我们选择4,然后一直按回车。会生成Gemfile文件,fastlane文件夹,Appfile,Fastfile文件。


执行init后生成

2、配置文件解释

Appfile: 存储有关开发者账号相关信息
Fastfile: 核心文件,主要用于命令行调用和处理具体的流程,lane相对于一个方法或者函数
Deliverfile: deliver工具的配置文件
metadata: 元数据文件夹
screenshots: 截图文件夹
Matchfile: Match操作对应的配置文件

不要手动创建这些文件

3、关于Gemfile

1)那么可以理解为:fastlane、cocoapods就是ruby的软件包,就是gem。所以gemfile管理的就是fastlane的版本。
2)类似于pod更新,bundle update fastlane用于更新fastlane版本。
3)在实际项目中为了使用固定的fastlane版本,都建议使用bundle exec fastlane [lane_name]来执行fastlane命令,如jenkins中打包。
4)综上所述,Gemfile其实就是一个管理fastlane版本的工具。

4、Fastfile代码生命周期

执行顺序 方法名 说明
1 before_all 脚本自动执行的第一个 lane,只执行一次
2 before_each 每次执行 lane 之前都会执行一次
3 lane 自定义的任务
4 after_each 每次执行 lane 之后都会执行一次
5 after_all 脚本自动执行的最后一个 lane,只执行一次
6 error 在执行上述情况任意环境报错都会中止并执行一次

5、Actions

常用Actions

四、实例

1、马甲包多target方案打包实例
问题:多target如下图所示,每个target对应一个马甲包,每个马甲包有各自的Apple账号、TeamID、BundleID等资源,fastlane默认支持一个target,如何通过fastlane打出不同的包呢?

image.png image.png

2、马甲包重签名方案打包实例
问题还是:每个马甲包有各自的Apple账号、TeamID、BundleID等资源
步骤:

五、spaceship

spaceship => 为pilotboardingdeliver等工具提供跟iTC和ADC的交互API。spaceship本来是个独立的项目,后来被Fastlane收编进来。

实例1:spaceship最常用的功能是用于处理二步认证问题
实例2:利用Multiple Spaceships同步设备UDID
# Launch 2 spaceships
spaceship1 = Spaceship::Launcher.new("felix@krausefx.com", "password")
spaceship2 = Spaceship::Launcher.new("stefan@spaceship.airforce", "password")

# Fetch all registered devices from spaceship1
devices = spaceship1.device.all

# Iterate over the list of available devices
# and register each device from the first account also on the second one
devices.each do |device|
  spaceship2.device.create!(name: device.name, udid: device.udid)
end
实例3:新增设备UDID并更新描述文件
Spaceship.device.create!(name: dev_name, udid: dev_udid)

#match管理
fastlane match --type="adhoc" --force_for_new_devices=true

#手动管理
profile = Spaceship::Portal.provisioning_profile.development.all.find { |p| p.name == "***" }
profile.devices = Spaceship::Portal.device.all
profile.update!
上一篇 下一篇

猜你喜欢

热点阅读