Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase SDK multiple projects in one apk

I am trying to initialize the FirebaseApp, only by using the FirebaseOptions builder, like this(I use only applicationId and ApiKey, since I only want the analytics for start):

FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId(applicationID) // Required for Analytics.
.setApiKey(apiKey) // Required for Auth.
.build();
FirebaseApp.initializeApp(context, options);

I do not have a google-services.json file in my project, I have removed the FirebaseInitProvider, like this, in my AndroidManifest.xml:

<provider android:name="com.google.firebase.provider.FirebaseInitProvider"
   android:authorities="${applicationId}.firebaseinitprovider"
   android:exported="false"
   tools:node="remove"/>

I would like to have the application id sent from my server, since I want more than one projects, and I don't really care if I lose some event during the initialization of the app. When starting the application, while trying to View events in the Android Studio debug log, like this:

adb shell setprop log.tag.FA VERBOSE

adb shell setprop log.tag.FA-SVC VERBOSE

adb logcat -v time -s FA FA-SVC

I get: Missing google_app_id. Firebase Analytics disabled.

I do not want to use google_app_id in a strings.xml static file since I want more than one projects. However I tried having all the app ids in an XML file and trying to change them using reflection before the FirebaseApp.initializeApp, but that doesn't seem to work.

like image 500
paularius Avatar asked Nov 08 '22 01:11

paularius


1 Answers

the default FirebaseApp initialization looks alike this (this is being used when passing no name):

FirebaseApp fb = FirebaseApp.initializeApp(context, options, "[DEFAULT]");

The FirebaseOptions values used by the default app instance are read from string resources.

but ...one can instead assign custom names, in order not to read from string resources:

FirebaseApp fb01 = FirebaseApp.initializeApp(context, options, "primary");
FirebaseDatabase db01 = FirebaseDatabase.getInstance(fb01);

FirebaseApp fb02 = FirebaseApp.initializeApp(context, options, "secondary");
FirebaseDatabase db02 = FirebaseDatabase.getInstance(fb02);

found this Firebase Blog, which is the credible source requested.

also the documentation for FirebaseApp generally explains it.

like image 147
Martin Zeitler Avatar answered Nov 15 '22 07:11

Martin Zeitler