In Comviva we follow Automated Build distribution as per below —

  • AdHoc Build Creation Using FastLane
  • Distribution of builds to QA OR Stake Holders via Firebase
  • Jenkins Job SetUp to have Parameterised build against Git Branch / Environment etc

In this article — I am sharing details on first two pointers —

  • FastLane Setup
  • Firebase Build Distribution

Best Practice is to have one Runner Machine which takes care of all Certificates/ Provisioning Profiles and anyone can go there execute the job and get the IPA.

To start with — we need to make sure that we have setup our app on Firebase and downloaded GoogleService-Info.plist

FastLane SetUp

The tool fastlane(https://docs.fastlane.tools/getting-started/ios/beta-deployment/) 
is a collection of Ruby scripts, so you must have the correct version of Ruby installed. 
Normally macOS comes with Ruby 2.0 by default, but you can confirm whether this is the 
case by opening Terminal and entering

Check if ruby is installed or not. Open terminal, run:

ruby -v

If it’s not installed, the easiest way to do so is via Homebrew a package manager for macOS. Install Homebrew by entering this Terminal command:

/user/bin/ruby -e \ "$(curl -fsSL https://raw/githubusercontent.com/Homebrew/install/master/install)"

If above commands fails, then there will come a suggestion in to run that command. Rerun above command after running the suggested command

then install Ruby using:

brew update && brew install ruby

Run $ “brew lin — overwrite ruby” of Homebrew instructs you to do so.

Now you will install Xcode Command Line Tools(CLT). Let’s first check if it is already installed by entering below command in terminal, run:

xcode-select -—install

if it is already installed, you will get the error: xcode-select: error: command line tools are already installed, use “Software Update” to install updates. If not installed then installation will start.

Now, you are ready to install fastlane. Enter the below commands in your terminal, run:

sudo gem install -n /usr/local/bin fastlane —-verbose

You might have to enter password. Enter the System password if prompted.

Now you are ready to set up fastlane project

In terminal — Go To your project folder & execute below command to setup fastlane for project —

if prompted Manual setup — manually setup your project to automate your tasks

Enter the digit against it, we will set up manually. In this case above enter 1.

Back in the project folder, you’ll see a few new things: Gemfile, which includes the fastlane gem as a project dependency and a fastlane folder containing: Appfile: stores the app identifier, your Apple ID and any other identifying information that fastlane needs to set up your app. Fastfile: manages the lanes you’ll create to invoke fastlane actions. If fastlane init got stuck somewhere while executing bundle update. Follow the below steps to resolve this issue, Open the Gemfile and replace

source “https://rubygems.org” with source “http://rubygems.org” and save the file.

now again run below command in terminal:

bundle update

You will now generate a binary so you can perform an upload for ad-hoc. We’ll use the gym command to generate an .ipa file for this.

Creating the IPA file

Open terminal, go to your project folder, run:

fastlane gym init

Above command creates Gymfile in fastlane folder.

Open Gymfile in your text editor, disable smart quotes, and replace the contents of the file with below code:

#1
output_directory("./fastlane/builds")
#2
export_method("ad-hoc")
#3
include_bitcode(true)
#4
include_symbols(true)
#5
export_xcargs("-allowProvisioningUpdates")

This code does the following:

  1. Specifies where fastlane should store the .ipa app binary file
  2. This sends ad-hoc through for the export_method parameter value. This builds the app for testing. Any devices attached to your Apple Developer account on the portal can run the app.
  3. Includes bitcode from the build. Bitcode allows Apple to optimize your app.
  4. Includes symbols from the build. Including symbols allows Apple to access the app’s debug information.
  5. Allows Xcode to use automatic provisioning.

Open Fastfile in a text editor, then replace the contents of the file with and save:

default_platform(:ios)

platform :ios do
     #1
     desc "Create dev ipa"
     #2
     lane :build_beta_dev do
     #3
     enable_automatic_code_signing
     #4
     increment_build_number
     #5
     gym(scheme: "DEV")
     end
end

This code does the following:

  1. Provides description for the lane. Lane is collection of commands which run in sequence.
  2. Lane name is “build_beta_dev”.
  3. This enables the automatic provisioning in Xcode.
  4. This increments the build number by 1.
  5. This runs the gym command and sends scheme. In this case scheme is “DEV”. We can have multiple scheme and as per our needs we can specify here.

Open text editor, paste below code. Replace the <[BUNDLE_IDENTIFIER]> with the bundle identifier pf yours.

BUNDLE_IDENTIFIER = "<[BUNDLE_IDENTIFIER]>"

Name the file as .env.DEV. File name which starts with . is hidden.

Save the file and close.

Open Appfile in text editor, replace the contents with the following code:

#1
app_identifier(ENV['BUNDLE_IDENTIFIER'])
#2
apple_id("<APPLE_DEV_ACCOUNT_EMAIL_ID>")
#3
team_name ("<APPLE_DEV_ACCOUNT_TEAM_NAME>")
  1. The bundle identifier of the App.
  2. Email address of the app-store or app-store connect.
  3. Team name

Make sure you have logged into xcode accounts using this dev account too and synced certs & provisioning profiles

Open terminal, go to your project directory, run:

fastlane build_beta_dev

This will create build folder containing .ipa file and .dSYM zip file.

Now, ad-hoc ipa is generated. Let’s upload it to firebase

Upload to firebase

Setting up the Firebase App Distribution Plugin

Next, you need to set up the Firebase App Distribution plugin. This tool allows you to upload to Firebase from fastlane with an action.

From Terminal, run the following command to add the App Distribution plugin to your fastlane installation:

fastlane add_plugin firebase_app_distribution
If the command prompts you with an option, select Option 3: RubyGems.org.
 
If for some reason, plugins not installed, try again after disabling VPN.

Next step is Login to firebase. Follow the steps mentioned in the website.

Now open Fastfile in text editor, paste the code below fastlane lane:

#1
desc "Upload dev to Firebase"
#2
lane :upload_firebase_dev do
#3
firebase_app_distribution(
#4
ipa_path: "./fastlane/builds/<APP_NAME>.ipa",
#5
app: "<FIREBASE_APP_ID>",
#6
groups: "<GROUP_CREATED_ON_FIREBASE_FOR_QA>",
#7
release_notes: "<RELEASE_NOTES>"

This code does the following:

  1. Add description.
  2. Firebase upload lane name.
  3. Invokes the firebase_app_distribution action.
  4. .ipa path generated using command build_beta_dev
  5. Firebase app id.
  6. group name created in firebase.
  7. release notes to be published.

After all these setup, run the following command from Terminal:

fastlane upload_firebase_dev
Now go back to Gemfile revert the changes that you made. Replace http with https and save.

It’s always good to clean the build folder before running build command

To clean the build folder, paste the code below the line “platform :ios do”:

desc "clean"
     lane :clean do
     clear_derived_data(derived_data_path: "./fastlane/builds/")
end

Now combine all the lanes in a separate lane

Open Fastfile, write it below firebase lane:

desc "build and upload dev to firebase"
lane :do_everything_dev do
     clean
     build_beta_dev
     upload_firebase_dev
end

Run the command in terminal:

fastlane do_everything_dev

Above command builds ad-hoc, stores in build folder, and then uploads to firebase.

Stay with us for next article on the same — for Jenkins SetUp — to have Parameterised build against Git Branch / Environment etc.

Md Mozammil

Md Mozammil

Md Mozammil have been working as a Senior iOS Developer for around 3 years for a Fintech company. Most of his work lies in developing new features for various banks across different countries while...