Multiple Flavor of Application in iOS Xcode

Rishabh Jain
7 min readMar 22, 2020

Wanna share the same code base of application for multiple clients? I.e White-label products. It is easily possible in Android studio as it has an inbuilt feature with few steps you can achieve the goal. For ref. of android please read this article whereas in Xcode one has to make certain configuration in order to support multiple flavor of the application.

There are two types of configuration:

  1. Multiple configuration — It includes debug, release, free, paid, etc builds of one flavor (In Xcode flavor is termed as scheme or target)
  2. Multiple schemes/targets/flavors — It includes App flavor with same code base but minor changes like app icon and app name. For example, development, staging and production build each has different API endpoints respective to the environment.

In this article we will discuss the 2nd point and steps to implement it in the project with example. We will be using objective c language in the sample and create 3 flavors of the application. For swift check this out.

At the end of the article we will achieve the following

Click here for complete sample project source code.

Please follow the steps mentioned below to achieve the goal:

  1. Create a new project with objective c
  2. Start with creating UserInterface
    A. Open Main.storyboard and create the user interface with image view and text labels in which the image view and some labels will be dynamic. The value will be determined by flavor you build which will be handled programmatically.
    B. Link the controls by creating outlets by clicking on Assistant Editor button (ref. image) in the workspace toolbar. The assistant editor opens your object’s implementation file. In the Xcode 11.1 you will find the Assistant button inside the menu button on Jump Bar.
  3. As mentioned above we will create 3 flavors i.e 3 schemes namely
    — SoftTech
    — MaxTech
    — CrypticTech
  4. Let’s start with the first flavor i.e ‘SoftTech’
    (We already have one scheme present i.e the default one)
    A. To bifurcate the code we will create directories for each flavor which will hold flavor specific files.
    — To create directory right click on the root directory in our case it’s ‘MultiFlavorSample’ and click on “New Group”. Rename Folder to ‘SoftTech’ for better understanding.

B. Create flavor specific files inside the folder. We need following files, one is header file for app constants, second Asset Catalog for images and third plist file.

I. Header File — Right Click on the folder we just created and click on ‘New File..’
It will display a popup to choose a template for the new file. Look for Header File and click Next.
Save As tab shows up in that name the file as ‘AppConstants.h’, next let the group be folder itself and in target please make sure to select the respective flavor also deselect the other flavors then Click on Create.
This will create the file under that folder.

II. Asset Catalog — Right Click on the folder we just created and click on ‘New File..’
It will display a popup to choose a template for the new file. Look for Asset Catalog and click Next.
Save As tab shows up in that name the file as ‘Images’, next let the group be folder itself and in target please make sure to select the respective flavor also deselect the other flavors then Click on Create.
This will create the asset catalog under that folder.
— After that click on + symbol → Add Icons and Launch Images → New iOS app Icon
III. Plist file (Optional) — For this flavor plist file move the existing Info.plist file to the folder in order to accumulate all resources of the flavor under the same folder.
After moving the plist you will face build error of “Build input file cannot be found”. To resolve the issue
—Open ‘project.pbxproj’ → Click on the target → General Tab → Identity (Option to choose Info.plist file will appear).

C. Now for proper readability we will rename the target to flavor specific name under TARGETS sections of ‘project.pbxproj’ (File at the top of file hierarchy) and also scheme name under schemes section.
I. Open ‘project.pbxproj’ (File at the top of file hierarchy) click on ‘MultiFlavorSample’ on the left panel and rename it to ‘SoftTech’

II. Now add the AppConstants.h file to target specific build phases.
— Click on Build Phases → Click on Add (Plus Symbol)→ From drop-down select New Headers Phase. (This will add a new section in build phases) Expand the new section i.e Headers section → Click on Add (+ Symbol) → Select target specific AppConstants.h file. This will add header file under project section.

Note: Please verify the above step by checking if it is associated with the same target or not. To do so select the above added file in file hierarchy on the left panel, after selecting you will find the “Target Membership” section in the extreme right in that you will find tick on the respective target if not then tick the respective target and untick others.

III. Click on target ‘MultiFlavorSample’ on top of the screen next to ‘Run’ logo, it will open the drop down and click on “Manage Scheme” click on ‘MultiFlavorSample’ under Scheme column and rename it to ‘SoftTech’
Note: This is an optional step. The reason to do this is to avoid confusion and make the name consistent throughout the project.

5. Now lets create another flavor with the same code base i.e for new client. Flavor name will be ‘MaxTech’.
A. Go to “TARGETS” right click on ‘SoftTech’ flavor and click on “Duplicate”. A new scheme will be created along with that a new plist file(please find it in file hierarchy) will also be created. Now repeat the steps 1. 2. And 3.
B. Rename the newly created plist file to ‘MaxTech-Info.plist’.
C. Link the renamed plist file with the new flavor by following the given steps
In project.pbxproj Select the new target then Under “Build Settings” search for plist. Then in results look for “Packaging” section and change the path to the new Info.plist file. Rename SoftTech copy-Info.plist → MaxTech-Info.plist.
Note: the path of the plist should be according to the file directory and must be reflected to “Build Settings” under each TARGET.

6. Do the same for 3rd flavor name it ‘CrypticTech’ and repeat step 1, 2 and 3.
After completing all the mentioned steps file directory tree on the left panel would look like this

Troubleshoot
Here are some issues I faced during implementation of this sample code.
1.Error- Build input file cannot be found: ‘/Users/apple/Documents/Rishabh/MultiFlavorSample/MultiFlavorSample/Info.plist’
Solution- Under “Build Settings” in project.pbxproj search for plist. Then in results look for ‘Packaging’ section and change the path to Info.plist file
— MultiFlavorSample/Info.plist — -> MultiFlavorSample/SoftTech/Info.plist

2. In case after running the each target(flavor) you find out that the values aren’t changing i.e Image and text.
Solution- Set ALWAYS SEARCH USER PATHS to YES under BUILD_SETTINGS tab of each flavor.

In conclusion, I would like to add that in order to implement MultiFlavor feature in iOS it’s not a tough task rather it’s a tricky task, some configuration in Xcode and you are done with it. Forgive me if I have missed out on anything in this article. In upcoming articles I would be writing about automating the builds using scripting, jenkins and fastlane. In case of suggestions and improvements please feel free to contact me. In the I would like to thank a few for helping me out Fenil Jain and @divyeshdhedhi . Thank you for reading!

--

--