Flutterfire with flavors — The missing documentation
FlutterPulseThis article was translated specially for the channel FlutterPulseYou'll find lots of interesting things related to Flutter on this channel. Don't hesitate to subscribe!🚀
Recently, we gazed upon a mysterious issue we had after setting up Firebase Crashlytics in our Flutter project with multiple flavors.
FirebaseJsonException: Please run "flutterfire configure" […]
During the documented process for adding Firebase to our app here, we are introduced to flutterfire_cli , a handy tool for configuring auto-magically our Firebase app with our Flutter app. It handles the generation and copy of the GoogleService-Info.plist and google-services.json in your project. It even adds the build phase scripts in Xcode and the gradle dependencies, how cool !
With the current 1.2.0 version of flutterfire_cli, you don 't have to manually set up anything, or so we thought, until we ran into an issue with our CI/CD:
FirebaseJsonException: Please run "flutterfire configure" to update the
`firebase.json` at the root of your Flutter project with correct values.
type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast
The thing is, we use flavors in our app, we have dev, staging and prod.
After following the official documentation for flavors in a flutter app here for ios, and here for android, we looked for firebase documentation with flavors and found… nothing. Well, almost nothing, there is a doc about Configuring multiple projects, but it's not for flutter, and it tells you to specify the service file configuration while calling for the firebase initilisation in code.
We don't want to do that.
It's not explained anywhere on the official documentations.
After scouring the internet for answers, we stumbled upon a more detailed flutterfire config command:
flutterfire config --project=<firebase-project-name> \
--out=lib/application/config/firebase_options_<env>.dart \
--ios-bundle-id=com.example.app.<env> \
--ios-out=ios/flavors/<env>/GoogleService-Info.plist \
--android-package-name=com.example.app.<env> \
--android-out=android/app/src/<env>/google-services.json
Thanks to the excellent blog post of Andrea Bizzotto, but what really bothers me is that:
It's not explained anywhere on the official documentations.
At this point, we could run our application but couldn't build it for release. We run into the main issue:
FirebaseJsonException: Please run "flutterfire configure" […]
We had the issue specifically on iOS, so we thought it was a bad scheme configuration, but our schemes are configured as expected… We checked the firebase.json and our file was looking good for us on the ios part:
{
"ios": {
"buildConfigurations": {
"Debug-dev": {
"projectId": "project-dev",
"appId": "1:123412341234:ios:iuhe1iu2heu32hru1h12ru",
"uploadDebugSymbols": true,
"fileOutput": "ios/config/dev/GoogleService-Info.plist"
},
"Debug-staging": {
"projectId": "project-staging",
"appId": "1:123412341234:ios:uh12983h18b89bf1ub7yb3",
"uploadDebugSymbols": true,
"fileOutput": "ios/config/staging/GoogleService-Info.plist"
},
"Debug-prod": {
"projectId": "project-prod",
"appId": "1:123412341234:ios:nd73hbdyuvas7dv378dfd2",
"uploadDebugSymbols": true,
"fileOutput": "ios/config/prod/GoogleService-Info.plist"
}
}
}We inspected the logs directly in Xcode (the farthest icon on the left, in case you didn't know, flutter build commands logs there too) and it strikes us at the FlutterFire bundle-service-file step:
You have not configured a "GoogleService-Info.plist" file with the build configuration: "Release-dev"
If you want to archive or build your ios app, without creating symlinks in Xcode, without adding custom phase build scripts, you HAVE to rerun the flutterfire config command, and when prompted with the choice of BuildConfiguration , chose Release-<env> .
And now everything works fine. Our firebase.json file is updated with 3 more buildConfigurations for Release-dev , Release-staging and Release-prod .
No thanks to an incomplete official documentation (/rant), and thanks to nice blog posts about the topic, we finally found the issue !
I hope this blog post can come in aid to some people with the same problem. You shouldn't have to manually set anything if a tool is supposed to handle it for you !
Have a nice day,
Louis.