Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate two or more google-services.json file together for different google service in same project using Android Studio

I am making a project where I want to integrate GCM and Google sign in but the problem is both have google-services.json configuration file which we need to add in our project.

So, how can I integrate both google-services.json configuration file in my project.

Here is my one of the configuration file

{
  "project_info": {
    "project_id": "default-xxx",
    "project_number": "xxx",
    "name": "xxx"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:xxx",
        "client_id": "x.package",
        "client_type": 1,
        "android_client_info": {
          "package_name": "x.package_name"
        }
      },
      "oauth_client": [],
      "api_key": [],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "cloud_messaging_service": {
          "status": 1,
          "apns_config": []
        },
        "appinvite_service": {
          "status": 1,
          "other_platform_oauth_client": []
        },
        "google_signin_service": {
          "status": 1
        },
        "ads_service": {
          "status": 1
        }
      }
    }
  ],
  "client_info": [],
  "ARTIFACT_VERSION": "1"
}
like image 634
Pankaj Avatar asked Jan 26 '16 11:01

Pankaj


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.

How do I use a different Google services JSON file with multiple product flavors Android?

How to use this file for different product flavors. There are only 3 steps first step is so simple just remove the google-service. json file from the root of the app/ module and save it your local system directory for the save side, & then make your product flavors like Production & Staging environment.

How do you maintain two Google services json production and debugging?

Place your google-services. json file in your $projectName/app/src/$buildType directory. For example, place one json file in src/release and another in src/debug . You will likely need to create the release & debug folders.


1 Answers

Finally I have done it as follows:

Step1: Open your desired google service page in my case its google sign in and GCM. There will be a button saying Get configuration file, click on that and input your details and get the configuration files.

Step2: Check both of the configuration file it would have same configuration in project_info object and client_info object. The difference would be in services object where you have to check for status if you have added two or more service the status value would be 2 which means they are enabled services. You can see in below configuration file which I have generated for two of the services which is Google sign in and GCM.

You just have to check your status values in services object where it is saying 2 for all the services you have integrated in your project is the configuration file you have to add.

{
  "project_info": {
    "project_id": "xxxxxxxxxx",
    "project_number": "xxxxxxxx",
    "name": "xxxxxxxxxxx"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "xxxxxxxxxxx",
        "client_id": "xxxxxxxxxxx",
        "client_type": 1,
        "android_client_info": {
          "package_name": "xxxxxxxxxx"
        }
      },
      "oauth_client": [
        {
          "client_id": "xxxxxxxxxx",
          "client_type": 1,
          "android_info": {
            "package_name": "xxxxxxxx",
            "certificate_hash": "xxxxxxxxxxx"
          }
        }
      ],
      "api_key": [],
      "services": {
        "analytics_service": {
          "status": 1
        },
        "cloud_messaging_service": {
          "status": 2, <======= this is my gcm service status
          "apns_config": []
        },
        "appinvite_service": {
          "status": 1,
          "other_platform_oauth_client": []
        },
        "google_signin_service": {
          "status": 2   <===== this my google sign in service status
        },
        "ads_service": {
          "status": 1
        }
      }
    }
  ],
  "client_info": [],
  "ARTIFACT_VERSION": "1"
}

Note: I am using Google sign in service so its generating oauth_client field value also which you wouldn't get if you generate only for GCM.

like image 185
Pankaj Avatar answered Oct 13 '22 01:10

Pankaj