How to setup a different Firebase project for Debug and Release environments

@brunolemos
2 min readFeb 10, 2018

--

In this quick tutorial I assume you have already followed the official Firebase installation guides for iOS and Android, it’s already working for 1 single Firebase project and you just want to switch to a second one depending on the environment (Debug / Release).

Firebase doesn’t support a “Sandbox” mode, so we need two different projects.

Firebase Setup

  • Create a second Firebase project
  • Download its google-services.json and GoogleService-Info.plist

Android Setup

  • Create two folders inside the src directory: debug and release;
  • Copy the respective google-services.json file on each one.

That’s it, Android will pick the correct one automatically on build. 💯

iOS Setup

  • Create two folders on project root directory: Debug and Release;
  • Copy the respective GoogleService-Info.plist file on each one;
  • On Xcode, drag both folders to Build Phases > Copy Bundle Resources
  • On AppDelegate.m, inside the didFinishLaunchingWithOptions method, replace the standard Firebase initialization code ([FIRApp configure];) with the following:

Objective-C

NSString *filePath;
#ifdef DEBUG
NSLog(@"[FIREBASE] Development mode.");
filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist" inDirectory:@"Debug"];
#else
NSLog(@"[FIREBASE] Production mode.");
filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist" inDirectory:@"Release"];
#endif

FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
[FIRApp configureWithOptions:options];

Swift 4

var filePath:String!
#if DEBUG
print("[FIREBASE] Development mode.")
filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist", inDirectory: "Debug")
#else
print("[FIREBASE] Production mode.")
filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist", inDirectory: "Release")
#endif

let options = FirebaseOptions.init(contentsOfFile: filePath)!
FirebaseApp.configure(options: options)

That’s it!
You are ready to go 🙌

Thanks for reading!
Follow me on Twitter: @brunolemos

--

--