4

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.

AL.
  • 33,241
  • 9
  • 119
  • 257
Arun Chand
  • 364
  • 4
  • 18
  • Duplicates https://stackoverflow.com/questions/38962025/can-i-initialize-firebase-without-using-google-services-json/44396850#44396850 – Gennadiy Ryabkin Jun 06 '17 at 18:03

2 Answers2

3

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.

Karthi R
  • 1,288
  • 8
  • 24
2

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.

Gennadiy Ryabkin
  • 6,364
  • 3
  • 28
  • 37
  • Please confirm that google-services.json does nothing other than this. Why they have invented the bicycle, but do not recommend just copy paste several strings to your resources? – Oleksandr Albul Feb 01 '18 at 14:07