Using Fastlane, Match and Gym for delivering iOS Apps (Part 1)

Since I’ve started to developing iOS apps, hardest part for me is waiting the archiving and uploading my app to iTunes Connect. It’s really annoying that when you spent 10 minutes for fixing a bug but waiting an hour to uploading and processing lead you questioning your whole engineering career. Okay maybe I’m exaggerate but you get my point :)

When I heard fastlane for the first time, it was 2015 summer and I’ve just started work on iOS apps from tutorials and youtube videos. I tried to used it in my own project but I got scared from Ruby’s syntax and I couldn’t imagine how fastlane could have helped me. Because of my prejudice I’ve been always stay away from it. But when I started working on MenaPay and when it comes our API versioning to developing/testing different feature in our app, fastlane is incredibly handy.

In this post I’ll try to share my two weeks experience with fastlane and its features gym and match.

What is fastlane?

Fastlane is one of the most popular tool to automatize your beta development, App Store screenshots and releases. Developed by Felix Krause in 2014, bought by Twitter’s Fabric at the end of 2015, then Fabric was bought by Google in 2017.

You can download fastlane with gem and brew from your terminal.

sudo gem install fastlane -NV brew cask install fastlane

After progress is finished you can go to your Xcode project to initialize your first Fastfile. Fastlane has two options for creating your fastfile, in Ruby or in Swift(in beta progress). I decided to go with Ruby since it’s been there almost 5 years and it would be easy to find a documentation or stackoverflow question to help your problem.

fastlane init
Fastlane will show you couple of options to choose. I chose 4 for manual setup so I can set up different lanes for sending apps to beta development or release.

After you use this command, Fastfile will be added to your project’s directory.

If you open the Fastfile on Atom/Visual Code you’ll see the Fastfile template:

If we teardown our template code little bit, desc is the part that we explain our lane’s purpose to other developer in our team maybe even ourself, lane will be the fastlane option when we use “bundle exec fastlane lane_name”

I’ve changed my lane’s name to beta and wrote some code to send my app to beta distribution.

//1
cocoapods
//2
increment_build_number
//3
match(app_identifier: "com.mertserin.fastlanetest", type: "appstore", readonly: true)
//4
gym(scheme: "FastlaneTest", workspace: "FastlaneTest.xcworkspace", export_method: "app-store", configuration: "Release", clean: true, output_directory: "build")
//5
testflight(ipa: "build/FastlaneTest.ipa", skip_waiting_for_build_processing: true)
//6
clean_build_artifacts

Let’s read our code one by one:

1-) Fastlane will make sure our pods is update to date

2-)Since we need to change our build number or version number when we want to send new version to iTunes Connect, fastlane will do it for us.

3-)We will get to match later in our post but for brief information, match will help us to keep sync our certificates and provisioning profile on Apple’s Developer Portal

4-)We will also explain gym but for another brief information, gym will help us to send ipa with different scheme and configuration.

5-)After we create out ipa, we need to distribute our app through TestFlight.

6-)It’ll clear all the trash that’s been created by match and gym.

There are two parts in this code that we haven’t talked about it yet. Match and Gym

What is Match?

I’ve met with match when I worked for a team for the first time. Since I’ve been working alone for long time, I’ve never thought about certificates and provisioning profile. Xcode will create it for me and it’s good to go. But when I be the part of the team that has other 2 iOS developer, I’ve realized that it was really hard keep your Developer portal clean and sync. Lucky for us fastlane came up with a solution they called match.

Match will help you to store your distribution/developer certificates in private git repository and it would be much easier when another developer joined your team.

You can initialize match with:

fastlane match init

It’ll ask for the private git repository’s URL.

If you want to create your distribution certificates:

#Creating for distribution certificates
fastlane match appstore
#Creating for development certificates
fastlane match development

When you run this command you’ll see something like this:

It’ll ask your Apple ID to retrieve your certificates, if you added by someone to different development team it’ll ask you to choose your team and you need to provide bundle identifiers. When when this progress completed you’ll have your distribution or development certificates. If you go to your private git repository, you’ll see that our certificates has been added by match. Since match is here to sync our certificates, other team member only need to run match init command to download these certificates.

Your certificates and profile which has been provided by match

What is Gym?

It’s much easier when you’re working alone on your app or when you’re on your still development process but after you publish your app and you need to make sure that nothing’s broken when you add new features or fixing bugs for older version. I was looking for a solution to split my app to Test and Production versions and sending different apps to iTunes Connect. Thanks to fastlane someone had the same problem before so they came up with gym.

gym(scheme: "FastlaneTest", workspace: “FastlaneTest.xcworkspace”, export_method: “app-store”, configuration: “Release”, clean: true, output_directory: "build")

For different lanes you can customize your code with different scheme or different configuration. For example in your scheme you can provide a different app name or different API url and you don’t need to worry about switching parameter to sending this app to App Store release, gym will do it for us automatically.

Testing Fastlane Integration

If we do implementation correctly, now we can test our beta lane with

bundle exec fastlane beta

command from our terminal. First match will download our certificates and provisioning file, then gym will create our ipa with given parameters. If everything is perfect you’ll see this message from terminal.

It might take a while to create and upload our app to iTunes Connect

Conclusion

After working on Fastlane for couple of weeks and delivering my apps in , I was little bit mad why I didn’t use it before and in my future projects fastlane will be the first thing that I’ll add to my project.

In my next post I’ll write about how can we customize our project’s configuration to post different two version to iTunes Connect.

Thank you for your time and see you in the next post.

iOS Engineer at P.F.C.