Simplify you life with fastlane

If you ask any iOS developer, he will most likely tell you that the process of publishing an app is far from simple. Fastlane can dramatically simplify your life by automating all of this. Once configured, one command line will compile your app and send it to iTunes Connect.

What is fastlane?

Fastlane is a free set of tools created by Felix Krause that automate building and releasing your iOS apps.

For me, fastlane is mostly useful for 3 things:

  1. Automatically synchronize certificates across your team: you’re starting a job in a new company and you need an Apple Certificate to compile the app on your phone, but first, someone has to give you the p12 file to install it (if he’s not on holidays)… Forget about that, thanks to the match tool, all Certificates and Provisioning Profiles will be stored in a private Git repository, and if you don’t have the correct Certificate, it will generate it for you automatically.
  2. Automatically choose which Provisioning Profile to use: depending on the type of app you want to compile (Development, Ad Hoc, In House or App Store), the match tool will automatically fetch the correct Provisioning Profile, or create or update it if needed. Dead simple! I’ve simply forgotten what it’s like to deal with that manually.
  3. Automatically run the tests, compile your app and send it to TestFlight: thanks to the scan, gym and pilot tools, fastlane will run the tests, compile your app and upload it to TestFlight or any other service provider supported (e.g. Crashlytics) with one single command line.

Fastlane has a lot of other tools but only with those ones, you should already be convinced to use it. See the Actions section below for more information on how to use them.

Requirements

Apple has recently changed its servers to require TLS 1.2, which may not be available to your system installed Ruby (2.0.0). So before installing fastlane, start by installing OpenSSL and upgrading your Ruby version to 2.3.1 with Homebrew, which will allow communication with iTunes Connect and the Apple Developer Portal servers.

Open your Terminal and type the following commands:

brew update

brew install openssl

brew install ruby

Configuration

You can finally install fastlane:

sudo gem install fastlane

To initialize fastlane in a project, go into your project directory and type the following command:

fastlane init

Follow the setup assistant, which will set up fastlane for you.

This will prompt you for your Apple ID in order to verify that your application already exists on both iTunes Connect and the Apple Developer Portal. If that’s not the case, fastlane will ask you if it should be created automatically.

This setup will:

  • Create a fastlane folder,
  • Create fastlane/Appfile, which stores your Apple ID and Bundle Identifier,
  • Create fastlane/Fastfile, which stores your lanes.

For more details, please follow the fastlane guide.

Appfile

The Appfile is used to define a Bundle Identifier. By default, there is only one bundle identifier, but you can create one for each lane. You could also specify the app identifier directly in the Fastline file, but it’s more convenient to externalize it in the Appfile.

<pre class="wp-block-code">```
apple_id "<APPLE_ID>" # Your Apple email address
team_id "<TEAM_ID>" # Developer Portal Team ID

for_platform :ios do
    for_lane :test do
        app_identifier "com.nicolasbichon.exampleapp.test"
    end

    for_lane :beta do
        app_identifier "com.nicolasbichon.exampleapp.beta"
    end

    for_lane :appstore do
        app_identifier "com.nicolasbichon.exampleapp"
    end
end

By using a different app identifier per lane, you will be able to have different apps on your phone, you could even have [different icons for your app](https://medium.com/@nicolasbichon/how-to-have-different-icons-for-your-app-7fecbaa68ad7).

### Fastfile

The **Fastfile** is the main file used by fastlane, this is where you will configure your **lanes** with **actions**.