Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 529
fragon Avatar asked May 19 '17 07:05

fragon


People also ask

How can I add two Google services JSON in the same project?

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.

Where do I put GoogleService-info plist?

Add your GoogleService-Info. plist file is something you can download from your Firebase's project settings. Drag your GoogleService-Info. plist to the Runner folder.


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)

like image 126
Datt Patel Avatar answered Oct 22 '22 19:10

Datt Patel