7

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.

fragon
  • 3,391
  • 10
  • 39
  • 76
  • Have you read this [post](http://stackoverflow.com/questions/30772201/google-services-json-for-different-productflavors)? – Alex Mamo May 19 '17 at 07:40
  • Why project number and project id have different values for the same project? – AlexTa May 19 '17 at 07:41
  • @AlexMamo yes. But as I have written I want to use multiple google-services.json files in ONE flavor. – fragon May 19 '17 at 07:43
  • @AlexTa Because different parties are managing Analytics and Firebase Ads for the app. – fragon May 19 '17 at 07:43

1 Answers1

2

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)

Datt Patel
  • 1,203
  • 1
  • 11
  • 10
  • What about for the Flutter packages? That's what I'm looking for, actually. Do you have any idea? – Gustavo Lopes Mar 23 '21 at 14:37
  • 1
    @GustavoLopes Yes, Check out this doc: https://pub.dev/documentation/firebase_core/latest/firebase_core/Firebase/initializeApp.html (Use `FirebaseOptions` and name) https://pub.dev/documentation/firebase_core_platform_interface/latest/firebase_core_platform_interface/FirebaseOptions-class.html – Datt Patel Mar 23 '21 at 14:43
  • 1
    That is perfect!! In the end, the problem was with the flutter library. But your solution made me realize that and I could fork and update the library to my needs. Thank you. You were really helpful! – Gustavo Lopes Mar 28 '21 at 12:24