How do you use Flutter Flavors in Xcode

7,787

Solution 1

I faced the same issue. If you are using git, try to remove the source code folder and clone again. Git caches something that prevent from building for iOS

If you haven't set up flavor for iOS yet, following this part 3 tutorial

https://medium.com/@LohaniDamodar/flutter-separating-build-environment-with-multiple-firebase-environment-92e40e26d275

Solution 2

Removing .idea directory and restart Android Stdio fixed the same issue on my environment.

Share:
7,787
The Tahaan
Author by

The Tahaan

My feet on a mountain, I am alive.

Updated on December 14, 2022

Comments

  • The Tahaan
    The Tahaan over 1 year

    I have an existing project (20k lines of code) that I now want to build for iOS (The project has been developed and tested using Android, though I did check that every package it depends on indicates iOS support.)

    I'm completely new to Mac (It took me a while to figure out how even to launch apps via the GUI) but I managed to work through the Flutter setup guides for MacOS.

    Flutter doctor shows all OK and so far the Sample Flutter app can run on the Xcode iPhone simulator.

    The app needs to have a flavor specified when built or launched, - on the android side I have dev, qa, and prod, each with full and free, ie 6 flavors in total and separate entry points.

    Right now when I try to Run the app on the simulator from Android Studio, I get the error

    The Xcode project does not define custom schemes.
    You cannot use the --flavor option.
    Could not build the application for the simulator.
    Error launching the application on iPhone 11 Pro Max.

    On the android side I use multiple src directory structures with AndroidManifest files and separate mipmap resource directories, plus a script to switch the asset-bundle based on the flavor. The Flavors each specifies a specific main-*.dart entry point / target and there are a series of googleservices.json files also corresponding to the flavors.

    I now need a way to translate all of that to xcode - I gather that it is called "Schemas". I gather I need a tool to set up the schemas (and where that fails, a script to set up per-flavor parts during the build process). Or are they called Runner Profiles?

    My question is where is this tool. Is there a command-line version? Can I somehow launch the Xcode GUI and set up Schemas for a project that lives in Android Studio? A lot of the terminology used in the many blogs that cover this will probably become clear once I can actually see what it looks like.

    Once I have the tooling in place I realise from reading other people's questions that the next hurdle will be to see where specific setup/tweaking is required to get the iOS build to pass, I gather this is particularly an issue with some packages, but for now I'm still working out the tooling.

    Possibly related to "my next hurdle", or possibly related to incomplete tooling setup, when I try to run the app on the Simulator without any flavor specified, it tells me that the Xcode build completes and the app is installed on the simulator, but it fails with a Stack trace. My guess is that it is telling me that it doesn't have a googleservices.json file (which should be sorted out once the correct (googleservices-plist.info?) file is set, based on the flavor is activated - but where and how is this done?)

    It could also be due to permissions, or even package errors.

    Edit: The call stack refers to FIRapp configure and FLFirebaseMessagingPlugin registerWithRegistrar. This hints at the missing googleservices config that is obviously not yet available - since it is flavor specific and I need to set that up.

    Some pointed/specific questions:
    1. Does flutter run and flutterbuild pass the "flavor" parameter as the name of a scheme to xcode? I would assume the answer is yes, else there needs to be a mapping somewhere.
    2. How do I set up schemes for every flavor in xcode (with cognisance for the fact that the project is in Android Studio).
    3. What is the iOS equivalent for the AndroidManifest.xml, specifically for specifying the applicationID and Launcher Icon and Application "Label"
    4. How does one specify per-Schema (per flavor) googleservices.json files for iOS?
    5. How / where does one set per-schema launcher icons?

    I guess I could do all of the above by having a script that replaces the "default schema" files using a set of files beloning to a specified "flavor" - this is the strategy I use because Flutter Flavors doesn't extend to the assets or for that matter anything set in the pubspec.yaml file - but I prefer to use supported tools as far as possible over hackish solutions.