setup_firebase_multiple_envs.mo
Owner: Louis Lagrange
Correcter: Thomas Pucci
Prerequisites (~30min)
Foreword
You can install and setup Firebase with two different ways:
Javascript asynchronous setup
Native synchronous setup
Pros
- 👍 No Native code is required - ⏩ Setup is quick
- 🚀 In your application, you do not need to wait for firebase to instantiate each time you need it - ✅ You can use Firebase Phone Authentication
Cons
⚠️ You cannot use this setup if you aim to use Firebase Phone Authentication as it requires the default Firebase app to be setup (meaning the native synchronous setup to be done: see the paragraph ℹ️ Important note here)
📲 You need install native libraries
This MO aims to setup Firebase with the Native synchronous setup. For the Javascript asynchronous setup read the docs here; and each time you need to call Firebase in your JS code, wait for the Firebase app initialization with onReady() method.
Steps (~30min)
It's pretty straightforward to install Firebase when you have only one environment. But what if you have multiple environments, such as dev, staging and production? Here's a step-by-step guide.
Android (~10min)
On Android, Firebase groups the different configurations in one file.
Go to the Firebase console
Select your project
Click "Add an application", choose Android
Fill in the form (giving a name like
Staging), click save, and close the windowRepeat steps 3 to 4 for all your environments
Download the
google-services.jsonfileSelect one of the Android applications
Click on "google-services.json"
Put
google-services.jsonin yourappfolder (android/appin React-Native)You might want to add
google-services.jsonin your.gitignore

iOS (~20min)
On iOS, there is one Firebase configuration file per environment.
Go to the Firebase console
Select your project
Click "Add an application", choose iOS
Fill in the form (giving a name like
Staging), click saveDownload the configuration file
GoogleService-Info.plistand rename it likeGoogleService-Info.{APP_IDENTIFIER}.plistExample: for
tech.bam.myApp.staging,GoogleService-Info.tech.bam.myApp.staging.plist
Repeat steps 3 to 5 for all your environments
Duplicate your configuration file for dev environment two times and rename them like so:
GoogleService-Info.plistGoogleService-Info..plist
Put all your configuration files in the root of your iOS app folder (
iosin React-Native)Make sure that your app identifier is injected in your
.pbxproj. For example, if you're using Fastlane, add aupdate_app_identifierstep like:update_app_identifier( xcodeproj: xcodeproj_full_path, plist_path: plist_full_path, app_identifier: ENV['APP_IDENTIFIER'] )If you bootstrapped your project with BAM generator, use the following in the iOS build lane:
update_app_identifier( xcodeproj: xcodeproj, plist_path: ENV['IOS_PLIST_PATH'], app_identifier: ENV['IOS_APP_ID'] )In XCode, in
Build phases, add aSelect GoogleService-Info.plistbuild step before theCopy Bundle Resourcesstep that contains:cp "GoogleService-Info.plist" "GoogleService-Info.plist.bak" cp "GoogleService-Info."$IOS_APP_ID".plist" "GoogleService-Info.plist"In XCode, in
Build phases, add aClean GoogleService-Info.plistbuild step after theCopy Bundle Resourcesstep that contains:cp "GoogleService-Info.plist.bak" "GoogleService-Info.plist" rm "GoogleService-Info.plist.bak"Make sure that the
GoogleService-Info.plistis listed in the resources of theCopy Bundle ResourcesstepYou might want to add
GoogleService-Info.*.plistin your.gitignore

Troubleshooting
You can take a look at the commit that adds crash reporting and analytics in DailyScrum: 8005ce3
Last updated