authors are vetted experts in their fields and write on topics in which they have demonstrated experience. All of our content is peer reviewed and validated by Toptal experts in the same field.
旧金山雷诺兹
验证专家 在工程

Francisco is a technical lead with extensive experience in iOS, Node.js, and web project development.

专业知识

以前在

Cookunity
分享

Making software for iOS is more than just about writing Objective-C or Swift code: It involves knowing how UIKit works, how certificates are made, how to publish your app to the store, how to deal with app reviews, 和更多的. If you find this eternal task list tiring, some automation in your workflow is exactly what you need.

满足 Fastlane, the tool designed to save you minutes or even hours in each deploy.

Delivery automation with Fastlane iOS

Fastlane helps you automate the process of s结束ing beta builds to Crashlytics, TestFlight, App Store, 还有更多.

在本文中, you will learn how you can use Fastlane to automate your iOS app deployment workflow. Although we will focus on the iOS aspect of this tool, Fastlane works equally well for Android development automation.

Getting Started with Fastlane

There are several installation methods that you can choose between, dep结束ing on what you find the easiest. 如果你有 家酿 installed and configured, installing Fastlane takes just one command:

brew cask install fastlane

Otherwise, Fastlane being a Ruby-based tool, 宝石 总是一个选项:

sudo 宝石 install fastlane -NV

Or, you can 总是 download Fastlane from the 官方网站.

Once you have installed Fastlane, run fastlane init in your project directory and follow the instructions.

Deployment 自动化

With Fastlane installed, you can now write Ruby scripts to indicate step by step what you need to do to get your deployment where you want it. This is done using 行动, tools, and lanes.

Fastlane 工具, 行动, and Plugins

Fastlane works by having tools at its core that help you build your app. On top of the build tools, there are over 170 built-in integrations with services like Crashlytics, HockeyApp, TestFlight, 和更多的 plugins that third parties make and publish so you can connect to other services 和更多的.

其核心是, you get the main tools that let you do a variety of tasks: From taking automated screenshots to framing them and uploading them to the store, it lets you run all your tests automatically before building the app.

行动 are the core tools that Fastlane has, and plugins are a way to add third-party 行动 to your Fastlane setup.

车道

Fastlane uses lanes that essentially group a list of 行动 or plugins sequentially so that you can achieve the same result every time.

在车道上行驶时, each action will export an environment variable, and the following 行动 will automatically get these variables to keep the process going. 例如, using the 健身房 action will result in the path of the .异丙醇 file being generated, and using crashlytics 将访问这个 .异丙醇 location to upload this file to its beta service distribution system.

Using Fastlane with iOS

You are starting with a new Toptal client who wants a very simple app. The design is already done, and the app can be coded in a few weeks. The next step is to start coding it, and during your the iteration process, you are going to s结束 a beta app every a couple of weeks to the client so that they can see your progress and give you feedback on how things are working.

Every time you s结束 a beta 版本 to the client, you are going to go through a basic checklist: signing the app, uploading it to a beta service, adding a new 版本 to it, 等. Add to this the things you have to do once (every year): signing certificates, signing push notification certificates (if needed), 和更多的.

With Fastlane, all of these can now happen automatically!

S结束ing to Crashlytics Beta

例如, you need to create signing certificates and provisioning profiles to share your app via Crashlytics Beta.

Fastlane has an action called 匹配 that, once you set it up, does the following:

  1. Create distribution signing certificates.
  2. Create an ad-hoc provisioning profile (attached to the certificate from #1).
  3. Save the certificate and the profile from #1 and #2 to a Git repository, encrypted using OpenSSL.

设置很简单.

首先,运行 快车道匹配初始 to get started and, once you set your Git repo, just call 快车道比赛特设 to get an ad-hoc provisioning profile or run fastlane 匹配 appstore to get an App Store certificate.

使用的优点 匹配 are that you can sync the certificates very easily between computers—and between teammates—without having to revoke the certificates anymore, and the speed that you gain. 只是跑 fastlane 匹配 appstore gives you a certificate in a couple of seconds.

好吧, now we have the certificates and provisioning we need, let’s make a release to Crashlytics.

A typical workflow for submitting your app to Fabric’s Crashlytics includes the following steps:

  1. Create the distribution signing certificates.
  2. Create an ad-hoc provisioning profile (attached to the certificate from #1).
  3. Set your app to use the provisioning profile from #2.
  4. 存档你的应用.
  5. Open Fabric and follow the steps to s结束 the app to beta testers.

Fastlane replaces the chore with this:

平台:ios do
  Lane:beta do
    匹配(类型:“特别的”)
    健身房
    crashlytics
  结束
结束

现在,运行 fastlaneβ from your terminal will launch this script.

这将首先调用 匹配, an action that handles creating and updating signing certificates and provisioning profiles, 然后调用 健身房, an action that builds and packages the app for you, using the same certificates and profiles created before, 最后, crashlytics, which is going to take this signed .异丙醇 and upload it to the Crashlytics service.

All of those steps get called, 总是, 以同样的顺序, making the resulting file more predictable and reducing errors.

MacBook-Pro:TestProject user$ fastlaneβ

+------+-------------------------------------+-------------+
|                     fastlane summary                     |
+------+-------------------------------------+-------------+
| Step | Action                              | Time (in s) |
+------+-------------------------------------+-------------+
| 1    | Verifying required fastlane 版本 | 0           |
| 2    | 匹配                               | 57          |
| 3    | 健身房                                 | 592         |
| 4    | crashlytics                         | 195         |
+------+-------------------------------------+-------------+

[20:25:13]: fastlane.tools just saved you 14 minutes! 🎉

So that was a basic setup for how to run Fastlane to s结束 your app to Crashlytics. What else can we automate?

Incrementing Build Versions

我们可以, 例如, set that each time we are going to s结束 a beta, we want to increase the build 版本 number.

This can be achieved using an action called increment_build_number that can be called from a terminal by fastlane run increment_build_number or used inline in our beta lane:

平台:ios do
  Lane:beta do
    increment_build_number
    匹配(类型:“特别的”)
    健身房
    crashlytics
  结束
结束

祝贺你! You now have an automated deploy script that also increments your build 版本 number. The only caveat is that, once you call this lane, you are going to have files changed in your project (or, 至少, the ones that incorporate the build number).

In case you were planning to commit that change to the repository anyway, there is an action for that: commit_版本_bump. This action commits the files with the new 版本 number.

平台:ios do
  Lane:beta do
    increment_build_number
    匹配(类型:“特别的”)
    健身房
    crashlytics
    commit_版本_bump (
     xcodeproj:“。.xcodeproj”,
   )
  结束
结束

This will commit files with a commit message like this “Version Bump to 27”.

Crashlytics to TestFlight

好吧, 如果你走了这么远, you can have an automated deploy to Crashlytics in a very short time that will save you countless hours in the long run. The best part about it is, if you wanted to s结束 your app to TestFlight instead, all you would need to do is change crashlytics to 飞行员.

Or, you can create a separate lane for that:

平台:ios do
  lane :beta-testflight do
    increment_build_number
    匹配(类型:“特别的”)
    健身房
    飞行员
    commit_版本_bump (
     xcodeproj:“。.xcodeproj”,
   )
  结束
结束

iOS 自动化 Made Simple

Fastlane is simple and easy to use. But, it brings amazing value to your regular iOS开发 workflow by saving you from doing menial things and hours of your time that you would have 结束ed up wasting.

I hope you will find this introduction to Fastlane useful. You can check out the official documentation to learn more about Fastlane, especially the list of 行动 if you are looking for some inspiration on what you could automate for your current and next iOS projects.

Understanding the basics

  • 什么是快车道?

    Fastlane is a tool that automates the release and delivery workflows for your iOS and Android apps.

  • How do I install Fastlane?

    Run “brew cask install fastlane” in a terminal or download the installer from http://download.fastlane.Tools/

Hire a Toptal expert on this topic.
现在雇佣
旧金山雷诺兹

旧金山雷诺兹

验证专家 在工程

Buenos Aires, Argentina

Member since December 8, 2016

作者简介

Francisco is a technical lead with extensive experience in iOS, Node.js, and web project development.

authors are vetted experts in their fields and write on topics in which they have demonstrated experience. All of our content is peer reviewed and validated by Toptal experts in the same field.

专业知识

以前在

Cookunity

World-class articles, delivered weekly.

By entering your email, you are agreeing to our 隐私政策.

World-class articles, delivered weekly.

By entering your email, you are agreeing to our 隐私政策.

Toptal开发者

加入总冠军® 社区.