How to combine two or more google-services.json files together for different google services in the same project using Android Studio

I am creating a project in which I want to integrate GCM and Google sign in , but the problem is that it has a google-services.json configuration file that we need to add to our project.

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

Here is my 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" } 
+5
source share
2 answers

Finally, I did it as follows:

Step 1: Open your google service page in my case the google sign and GCM . A button will appear with the inscription Get configuration file , click on it and enter your data and get the configuration files.

Step 2: Verify that both configuration files have the same configuration in the project_info and client_info . The difference would be in the services object, where you need to check the status, if you added two or more services, the status value will be 2 , which means that they are enabled by services. You can see in the bottom configuration file that I created for the two services that are signed by Google and GCM .

You just need to check your status in the service , where it says 2 for all the services that you integrated into your project, this is the configuration file that you must 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 use the Google login service to generate an oauth_client field value that you would not get if you only generated for GCM .

+6
source

You do not need two different google-services.json files. Both will have identical configurations. These configuration files are unique for each project, regardless of how many services you have activated.

Before creating a configuration file, make sure that you have activated both services. The generated configuration file will be valid for both.

Follow the “Continue to Login” link that appears under the “Download and Install Configuration” link for documentation on what to do next.

+5
source

Source: https://habr.com/ru/post/1011704/


All Articles