🚀 Integrating Fastlane with multiple target for a single iOS project 🚀

Jun 26, 2018 · 6 min read

Well, let’s start this article why we need Fastlane, as a mobile app developer we can just generate and archive the build through XCode publish directly to TestFlight or Fabric Beta . So what we are doing here is a manual job, it means in a team there should be a member who will be responsible for configuring the Xcode archiving process , have to take care of build provisions & certificates and also has to constantly supervise the uploading process in testflight or fastlane then notify testers/QA team about the new build so that QA can test the app.

Now , what if I say we can do the whole process in a blaze , no dedicated team member is needed and anyone from the team can deploy the app in Appstore or TestFlight or Fabric Beta thus means no dependency .

Fastlane is one of the great tools to automate iOS deployments, releases and all sorts of common iOS development tasks like code signing, configuring provisioning profiles, certificates and also increment versions from Apple developer portal. Fastlane provided programmatic implementation to automate all these tasks so that we can set up continuous integration and continuous delivery on any CI server like Jenkins. However, one needs have to learn and write some Ruby code in order to configure Fastlane but that is a very basic ruby code which is not so hard to write if one follow the Fastlane Docs and this article .

Setup Fastlane

So let’s set up our fastlane in an iOS App which has 3 multiple scheme for one app, so we expect that the app will deliver 3 different app/package from a single project.

I will like you follow the basic setup process from this link:-

So now we have a fastfile in project directory now we do start learning the real magic “Alohomora ” — you will understand the spell if you follow Harry Potter, though it is out of context. Huh!

Now let me show you my project structure which consist of 3 different targets, so that we can make build accordingly through fastlane.

We have 3 targets App1, App2 and App3 in the current project named as Demo_Project_Medium

So Fastfile is a ruby file that defines all your ‘lanes’. A lane is a set of instructions you want Fastlane to run. So I will like you all to use Atom IDE as text editor for fastlane related things which is fast and have smarter context-aware auto-completion, code navigation features such as an outline view, go to definition and find all references , we can also hover-to-reveal information, diagnostics (errors and warnings) and document formatting.

Here is the initial fastfile.

So now before creating lane in fastfile , we will create 3 environment variables file for 3 targets defined in the project which will help us to deploy specific target app / ipa through fastfile . You can create this empty files using Atom Editor and make sure the file name should be like this syntax — “ .env.<TargetName>”

In the environment variable we will define the following :-

  1. SCHEME — — The exact scheme or target name used for the app
  2. BUNDLE IDENTIFIER — — The identifier for specific target or scheme
  3. PROVISION PROFLE NAME — — The name of provision profile saved in your mac locally , so that at the time of archiving the app , fastlane will try to find the provisioning profile by that name. The name will be as it is showing in the section of provisions of apple developer account. Note:- To find the provision profile stored in your system , the path should be: ~/Library/MobileDevice/Provisioning Profiles . The ~/Library folder is hidden in finder by default, so you either have to unhide it or use the Finder menu Go->Go to folder… and enter the path, or use Terminal and execute the command.
  4. APP NAME — — The name of the target/scheme used in the project.

So, now we will add the following content in the .env.App1 file

SCHEME = "App1"
BUNDLE_IDENTIFIER = "com.SandeepM.app1"
APP_NAME = "App1"
The .env file will look like this as you can see I have added different provision as per archive type debug and release.

Kindly note that you have to add the content for other env files i.e app2 and app3 also specifically mention scheme,bundle identifier,provison in the respective .env files.

Working on Fast lane and automate task

Now we add lane named as “createIPA” in Fastfile to perform automation operation to generate ipa for specific target.

# More documentation about how to customize your build
# can be found here:
# https://docs.fastlane.tools
fastlane_version "1.109.0"
# This value helps us track success metrics for Fastfiles
# we automatically generate. Feel free to remove this line
# once you get things running smoothly!
default_platform :ios
puts "Create Ipa as per scheme name 1. App1 2. App2 3. App3 "

# Fastfile actions accept additional configuration, but
# don't worry, fastlane will prompt you for required
# info which you can add here later
ENV['FASTLANE_XCODEBUILD_SETTINGS_RETRIES'] = "120" #this is to handle timeout due to CPU operationlane :createIPA do
# build your iOS app
clean_build_artifacts # Delete the local dSYM files
clear_derived_data . #Delete existing derived data

scheme: ENV['SCHEME'], #{}"iOSConsumerApp-TH",
export_method:"ad-hoc", #"app-store", #"ad-hoc",
export_xcargs: "-allowProvisioningUpdates",
include_bitcode: false,
export_options: {
uploadBitcode: false,
uploadSymbols: false,
compileBitcode: false,
provisioningProfiles: {
"signingStyle": "manual"

Once you add the following code in the fastfile, save it and run the following command as per the environment or target you want to generate ipa :-

fastlane createIPA --env App1 

The following command will execute the lane action specified in our fastfile and also try to find the lane with name “createIPA” and execute the operation. You may be wondering what “— env APP1” is ?? Well, it means for which target we are want to build the app as we have multiple targets so we can specify which app we want to build i.e App1 or App2 or App3.

Note :- The target name is case sensitive so please use the exact name you used to create the .env files for each targets.

Let’s see how our command works :-

Archiving process for target App1
Archiving process for target App2
Archiving process for target App3

So after this operation is completed we will see the respective the ipa file in the project directory.

Project directory contains their respective ipa files for each target
Photo by Matt Botsford on Unsplash


So here is end of the article , now you have get it how fastlane automate the process of archiving and creating IPA with multiple target .

In the next article — https://medium.com/@vizllx/build-test-deliver-a-complete-guideline-for-ios-ci-cd-5fa02bffa7ce

I will show you the next level of automating the task through fastlane:-

  1. Incrementing version number automatically
  2. Uploading build to Beta
  3. Uploading dysm symbol files to Crashlytics for getting in-depth crash report
  4. Integrating Slack and HipChat with Fastlane, automate messages after successful build.

Till then Happy coding .

Learn and share your knowledge who knows someone somewhere might be benefit by your small effort.

“An overhead shot of a cup of coffee next to an open laptop, two pencils and a stack of sticky notes” by Lauren Mancke on Unsplash


Written by

Mobile Engineering , Photographer, Hardcore agile development enthusiast. Github- https://bit.ly/2K9bq4B StackOverflow- https://bit.ly/2tEjW

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade