0

I have to implement firebase in 2 configurations Debug and Release. This is the reason I have removed json files and wrote code line this:

for configuration 1-

var env1 = new FirebaseOptions.Builder()
                            .SetApplicationId(myId)
                            .SetApiKey(myKey)
                            .SetStorageBucket(appspot.com)
                            .SetProjectId(myPID)
                            .SetDatabaseUrl(MYURL)
                            .Build();

var app1 = FirebaseApp.InitializeApp(Application.Context, env1, "Debug");
analytics= FirebaseAnalytics.GetInstance(app1.ApplicationContext);

For configuration 2-

var env2 = new FirebaseOptions.Builder()
                            .SetApplicationId(myId)
                            .SetApiKey(myKey)
                            .SetStorageBucket(appspot.com)
                            .SetProjectId(myPID)
                            .SetDatabaseUrl(MYURL)
                            .Build();

var app2 = FirebaseApp.InitializeApp(Application.Context, env2, "Release");
analytics= FirebaseAnalytics.GetInstance(app1.ApplicationContext);

Here either it is giving error like missing_google_id or firebase is not initialized.

I have tried adding string value in xml file for android,still same error. To acieve my goal I have also tried adding multiple json files in different directories as per the link below

Xamarin firebase different google-services,json for different build configurations

but it seems it still looks for json file in root folder..

So how to implement firebase without or with json file for multiple environments

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
uncle_scrooge
  • 409
  • 1
  • 5
  • 28

1 Answers1

0

There definitely is no way to report analytics data from multiple FirebaseApp instances in a single app. See Firebase Analytics (Two projects) for single app.

If I remember correctly, Google Analytics for Firebase always reports analytics for the default FirebaseApp instance. The best reference I found for that is Use multiple firebase accounts in single android app for google analytics, but if someone has a more authoritative source I'd love to hear.

If that is the case, since each build is either Debug *or Release, you could initialize only the relevant FirebaseApp instances for the specific build target.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807