Reputation: 7368
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)
What is the best idea to solve this Test/Production environment for Firebase Database?
Upvotes: 8
Views: 1883
Reputation: 4537
You can create separate databases under the same project and use them for your debug and release builds.
In the code, just point get instances for different databases based on which build it is.
FirebaseDatabase firebaseDatabase;
if (BuildConfig.DEBUG) {
//Url of new database
firebaseDatabase = FirebaseDatabase.getInstance("https://app-1234.firebaseio.com/");
} else {
//For release builds use the default database
firebaseDatabase = FirebaseDatabase.getInstance();
}
Upvotes: 0
Reputation: 10350
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);
Upvotes: 1
Reputation: 599716
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.
Upvotes: 3