Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make different Firebase Database for Release and Debug mode in a single project/app?

Here we are working on the project that uses the Firebase Realtime Database. Is it possible to make different Firebase Database for Release and Debug mode in single Android app?

Project:(App with release/debug mode)

  1. Debug Mode(Test Environment) - Firebase Database 1
  2. Release Mode(Production Environment) - Firebase Database 2

What is the best idea to solve this Test/Production environment for Firebase Database?

like image 212
jazzbpn Avatar asked Sep 28 '16 10:09

jazzbpn


People also ask

How do I create a multiple realtime database in Firebase?

Create multiple Realtime Database instancesIn the Firebase console, go to the Data tab in the Develop > Database section. Select Create new database from the menu in the Realtime Database section. Customize your Database reference and Security rules, then click Got it.

Can a Firebase project have multiple apps?

You're limited to one database per project. You'll need multiple projects to get multiple db instances. You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.

Can two apps use the same Firebase database?

Yes, You can use the same firebase database in more than one android application as below: In the Project Overview section of Firebase Console add an android application.


2 Answers

There is only a single database in a project at the moment. So either you'll need to model debug and release data into the same database or you'll need a separate project for each.

Many of these scenarios are covered in this blog post: Organizing your Firebase-enabled Android app builds.

like image 134
Frank van Puffelen Avatar answered Oct 19 '22 10:10

Frank van Puffelen


Rather than using google-services.json to drive initialisation of Firebase (assuming that's what you're currently doing?), I'd suggest dynamically creating FirebaseApp using something like following

    String apiKey;
    String databaseUrl;

    if (useDebugDatabase) {
        apiKey = "xxxxxx";
        databaseUrl = "<debug firebase database url>";
    } else {
        apiKey = "xxxxxx"
        databaseUrl = "<release firebase database url>";
    }


    FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
            .setApiKey(apiKey)
            .setApplicationId(context.getString(R.string.google_app_id))
            .setDatabaseUrl(databaseUrl)
            .build();
    FirebaseApp firebaseApp = FirebaseApp.initializeApp(context, firebaseOptions, "MyApp");

    FirebaseDatabase database = FirebaseDatabase.getInstance(firebaseApp);
like image 45
John O'Reilly Avatar answered Oct 19 '22 10:10

John O'Reilly