I would like to use Firebase analytics for one of my library modules. I would like to program in such a way that configuration file (google-services.json
) should be accessible from either client app folder or configure the same from the client side.
Is there a way I could implement the above mentioned scenario?
Thanks in advance.
The general answer is yes, the google-services. json is safe to check in to your repo and is something that should be shared among engineers on your team. The JSON file does not contain any super-sensitive information (like a server API key).
There is no way to use two google-services. json files in a single Android app. The file name is the same between them and they need to be in the same location. So one will overwrite the other in that case.
You can initialize your library project configurations manually as below,
For more info, kindly refer working-with-multiple-firebase-projects-in-an-android-app
Also go-through how-does-firebase-initialize-on-android to understand; how the Firebase module is getting initialized by itself.
For Android apps using Firebase, there is a central FirebaseApp object that manages the configuration for all the Firebase APIs. This is initialized automatically by a content provider when your app is launched, and you typically never need to interact with it. However, when you want to access multiple projects from a single app, you'll need a distinct FirebaseApp to reference each one individually. It's up to you to initialize the instances other than the default that Firebase creates for you.
FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId("1:530266078999:android:481c4ecf3253701e") // Required for Analytics.
.setApiKey("AIzaSyBRxOyIj5dJkKgAVPXRLYFkdZwh2Xxq51k") // Required for Auth.
.setDatabaseUrl("https://project-1765055333176374514.firebaseio.com/") // Required for RTDB.
.build();
FirebaseApp.initializeApp(this /* Context */, options, "secondary");
Hope I've answered your question.
I've found interesting workaround. Try the following:
put your google-services.json
to any sample app google provides for Firebase integration. Compile it.
Take a look on path app/build/generated/res/google-services/debug/values/
there should be generated values.xml
file with bunch of strings mentioned in errors you described. Copy these strings to value.xml file of your project. That's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With