Flavours for Your Flutter App 2/2

Photo by Andrew Neel on Unsplash

Flavours for Your Flutter App 2/2

In my previous article Flavours for Your Flutter App 1/2 I talked about Flavours for your Android app that has been developed using the amazing Flutter framework. I outlined how you can add and run your various flavours right from your IDE or from the terminal.

Welcome to the second and final article of Flavours for your Flutter App. In this article I focus on the iOS version of your app. Let's jump right in!


Environment set up

Prerequisites:

  • Xcode installed

  • An existing Flutter project

To set up flavours in iOS, you’ll need to define build configurations in Xcode.

Creating flavours in iOS

  1. Open your project in Xcode.

  2. Select Product > Scheme > New Scheme from the menu to add a new Scheme.

    • A scheme describes how Xcode runs different actions. For this guide, the example flavour and scheme are named dev. The build configurations in the dev scheme have the -dev suffix.

    • This dev scheme is for building versions of the app that have features in testing until they are stable to be released to production.

  3. Duplicate the build configurations to differentiate between the default configurations that are already available and the new configurations for the free scheme.

    • Under the Info tab at the end of the Configurations dropdown list, click the plus button and duplicate each configuration name (Debug, Release, and Profile). Duplicate the existing configurations, once for each environment.

Note: Your configurations should be based on your Debug.xconfig or Release.xcconfig file, not the Pods-Runner.xcconfigs. You can check this by expanding the configuration names.

  1. To match the developer flavor, add -dev at the end of each new configuration name.

  2. Change the dev scheme to match the build configurations already created.

    • In the Runner project, click Manage Schemes… and a pop up window opens.

    • Double click the dev scheme. In the next step (as shown in the screenshot), you’ll modify each scheme to match its dev build configuration:

Using Flavours in iOS

Now that you’ve set up your free flavour, you can, for example, add different product bundle identifiers per flavour. A bundle identifier uniquely identifies your application. In this example, we set the Debug-free value to equal com.songlib.dev.

  1. Change the app bundle identifier to differentiate between schemes. In Product Bundle Identifier, append .dev to each -dev scheme value.

  2. In the Build Settings, set the Product Name value to match each flavour. For example, add Debug Dev.

  3. Add the display name to Info.plist. Update the Bundle Display Name value to $(PRODUCT_NAME).

Now you have set up your flavour by making a dev scheme in Xcode and setting the build configurations for that scheme.

For more information, skip to the Launching your app flavours section at the end of this document.

Plugin configurations

If your app uses a Flutter plugin, you need to update the ios/Podfile.

  1. In ios/Podfile change the default for Debug, Profile, and Release to match the Xcode build configurations for the dev scheme.
project 'Runner', {
  'Debug-dev' => :debug,
  'Profile-dev' => :release,
  'Release-dev' => :release,
}

You can set up your launch configurations like in android via the launch.json file in the .vscode. I elaborated on this in my earlier article. I will be coming back to update this as well as the earlier article as I find it wise based on my discoveries and working.