fastlane官方号称用最简单的方式实现iOS、Android应用的自动构建和发布。

安装

确保安装了最新的xcode命令行工具

xcode-select --install

安装fastlane

官方提供了三种安装方式。

Homebrew Installer Script Rubygems
macOS macOS macOS or Linux with Ruby 2.0.0 or above
brew cask install fastlane Download the zip file. Then double click on the install script (or run it in a terminal window). sudo gem install fastlane -NV

这里选用Rubygems的安装方式,如果安装失败尝试升级下ruby.

#安装fastlane
sudo gem install fastlane -NV
#查看版本
fastlane -v 

初始化

fastlane init

进入项目.xcproject所在目录,执行fastlane init

#初始化fastlane
fastlane init

随后按提示输入Apple id、密码等信息(密码会被存储到keychain)。

  • 登录成功后,会自动获取到App id等信息,如果没有在iTunes Connect或 Apple Developer Portal创建过,会弹出提示,根据实际需要进行操作。(fastlane会调用produce进行初始化)
[09:30:48]: This app identifier doesn't exist on iTunes Connect yet, it will be created for you
[09:30:48]: This app identifier doesn't exist on the Apple Developer Portal yet, it will be created for you
[09:30:48]: Please confirm the above values (y/n)
  • 如果提示登录失败,按提示进行输入即可(如企业账号)。

这样对于一个项目来说就fastlane的初始化就已经完成了。

20170626637372.png

分析

在执行deliver init的过程中,会同步iTC中的所有语言的元数据和截图,并按照目录结构组织好 。

这里肯定会被创建的是Appfile和Fastfile。如果Deliverfile,screenshots和metadata目录没被创建,可以运行deliver init来创建(非企业应用)。

| 文件 | |
| — | — |
| Appfile | 从 Apple Developer Portal 获取和项目相关的信息 详情|
| Fastfile | 核心文件,存放lane任务|
| Deliverfile |deliver的配置文件,从 iTunes Connect 获取和项目相关的信息详细 |
| metadata | 同步iTC中的元数据 |
| screenshots | 同步iTC中的截图 |

关于fastfile:

里面存放了很多lane,每个lane相当于按顺序执行的工作流。每个lane可以存放多个action,action可以看做具体的执行动作。

fastlane_version "2.41.0"

default_platform :ios

platform :ios do

# 执行所有命令前都会先执行这里
  before_all do    
    #cocoapods  #实际上运行了`pod install`
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."    
  end
  
 #运行测试文件
  desc "Runs all the tests"
  lane :test do
    scan
  end

  desc "Submit a new Beta Build to Apple TestFlight"
  desc "This will also make sure the profile is up to date"
  lane :beta do
    # match(type: "appstore") # more information: https://codesigning.guide
    gym(scheme: "fastlaneProj") # Build your app - more options available
    # pilot
    # sh "your_script.sh"
    # You can also use other beta testing services here (run `fastlane actions`)
  end

  # You can define as many lanes as you want
  # 当上述流程全部执行成功后执行。
  after_all do |lane|
  end
    
  #上述执行失败后执行
  error do |lane, exception|
  end
end

在命令行中使用fastlane actions可以列出所有的action,使用fastlane action [action的名字]可以查看该action的相关信息,最重要的是在帮助文档中的这里可以查看具体action的使用方法和示列。Action文档地址

|action举例| 描述|
| — | — |
| cocoapods | Runs pod install for the project | | scan | Easily run tests of your iOS app using | |gym|Easily build and sign your app using gym(打包) | |pilot|Upload a new binary to iTunes Connect for TestFlight beta testing(把应用发布到TestFlight)| |testflight|Alias for the pilot action|

重新安装

brew cask reinstall fastlane

卸载

 gem uninstall fastlane

or

brew cask uninstall fastlane

遇到的问题

—update 2018-06-28 21:05:59–

gym功能报错,考虑删除后重装

#删除指定版本
➜  gem uninstall fastlane --version=2.78
ERROR:  While executing gem ... (Gem::InstallError)
    fastlane is not installed in GEM_HOME, try:
	gem uninstall -i /Users/tyrad/.rvm/gems/ruby-2.2.5@global fastlane
➜  gem uninstall -i /Users/tyrad/.rvm/gems/ruby-2.2.5@global fastlane

Select gem to uninstall:
 1. fastlane-2.74.1
 2. fastlane-2.78.0
 3. All versions
> 3