Use multiple google-services.json and GoogleService-Info.plist files in one flavor/target

Viewed 1590

Is it possible to use two google-services.json files in an Android project? I know that there is a possibility to use multiple google-services.json files for multiple flavors, but is it possible to somehow merge two files with different project_info and use them simultaneously for a project?

Below is the example of two files which I want to use in one project and one flavor (one for Analytics and another one for Ads).

First google-services.json

{
  "project_info": {
    "project_number": "XXXXXXXXXXXX",
    "project_id": "project-one"
  },
  "client": [
    (...)
  ],
  "configuration_version": "1"
}

Second google-services.json

{
  "project_info": {
    "project_number": "YYYYYYYYYYYY",
    "firebase_url": "https://project-two.firebaseio.com",
    "project_id": "project-two",
    "storage_bucket": "project-two.appspot.com"
  },
  "client": [
    (...)
  ],
  "configuration_version": "1"
}

Also I have the same question regarding GoogleService-Info.plist files for an iOS project.

1 Answers

Yes, It is possible to use more than one FirebaseApp. But you have to use the FirebaseApp configuration by code for the second configuration. google-services.json & GoogleService-Info.plist use to crate default FirebaseApp. For the second configuration use class func configure(name: String, options: FIROptions)(Swift) & public static FirebaseApp initializeApp (Context context, FirebaseOptions options, String name)(Android).

iOS demo code:-

   let options =  FirebaseOptions(googleAppID: "1:XXXXXXXXXXXXXX:ios:XXXXXXXXXXXXXXXXXX", gcmSenderID: "XXXXXXXXXXXXX")
   options.apiKey = "XXXXXXXXXXXXXXXXXXXXXXXXX"
   options.projectID = "App-XXXXX"
   FirebaseApp.configure(name: "AppAnalytics", options: options)

Add FirebaseOptions data/values from google-services.json & GoogleService-Info.plist files.

Please refer to the below link for more details:

iOS: https://firebase.google.com/docs/reference/swift/firebasecore/api/reference/Classes/FirebaseApp https://firebase.google.com/docs/reference/swift/firebasecore/api/reference/Classes/FirebaseOptions

Android: https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseApp#initializeApp(android.content.Context,%20com.google.firebase.FirebaseOptions,%20java.lang.String)

Related