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.
The first step is to download google-services. json file(s) from each Firebase project to a temporary location at your machine. Next, create two folders android/app/src/dev and android/app/src/prod for each flavor. The Firebase configuration files go under their flavor folders under android/app/src/ folder..
Open the default Xcode workspace in your project by running open ios/Runner.xcworkspace in a terminal window from your Flutter project directory. Select the device you intend to deploy to in the device drop-down menu next to the run button. Select the Runner project in the left navigation panel.
flutter build --flavor development. On Android, this determines which product flavor is used during the Gradle build process. On iOS, things can be configured so that a different Xcode scheme is used for each flavor. And as of December 2021, the whole process can be (mostly) automated.
Note! Unlike Android studio, flutter isn't supported to XCode yet, you have to open iOS folder of Flutter project only and solely.
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
Removing .idea directory and restart Android Stdio fixed the same issue on my environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With