https://developers.google.com/cloud-messaging/android/client I've read this article. And it says that I need to download and add the configuration file to my project. But they do not explain, why should I do this? Won't it work without adding the configuration file?
2 Answers
If you do not generate and add the proper configuration file to your project, then yes, you will not be able to get push notification working.
In previous version of the SDK, you had to configure the senderID manually in your code.
Now, with GCM 3, Google has unified the way to configure Google Service. Their portal now let you configure all the service you want to enable for your app. Once done, it generates a configuration file that contains the parameter you need from the mobile to use the service.
Without that info, and most notably the project number, Google will be unable to generate InstanceID that allows receiving push with your senderID and Server API key. This is a way to match the client credential on Android, with the server credentials on the backend that allows you to send push notifications to your Android app and your app only.
How does it works ?
The configuration file is used by the google-services Gradle Android plugin to generate the needed configuration resources. It means you are using it if you have this in your build.gradle
file:
apply plugin: 'com.google.gms.google-services'
Then, it will generate the resource R.string.gcm_defaultSenderId
that you see in Google GCM example code:
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
However, if you decide to hardcode the SenderID in your code and pass it to the instanceID.getToken
method, then indeed, it will work.
Having the JSON configuration file is a convenience provided by Google. It is cleaner as it centralize all your Google Service parameter.
The link of your app to project / senderID is mandatory, but if you really do not like the idea of having this JSON Google server configuration file you can work around it by putting the needed values elsewhere manually.

- 9,035
- 1
- 24
- 44
-
how does this work with the new more atomic google services. `https://developers.google.com/android/guides/setup` wher you can include just GCM `com.google.android.gms:play-services-gcm:8.1.0` if I do that, then the `gcm_defaultSenderId` is not found in android studio – Zapnologica Nov 02 '15 at 06:26
-
As of `com.google.android.gms:play-services:8.3.0`, I think the configuration file is now required. I tried to build my project without that and got this error: **Execution failed for task ':app:processDebugGoogleServices'. > File google-services.json is missing from module root folder. The Google Services Plugin cannot function without it.** – Mateus Gondim Mar 03 '16 at 23:39
I am also working on multiple GCM-projects but still using Eclipse, Eclipse-ADT-plugin and the old project structure and I did not include this config-file into my projects. I also was confused at the beginning and hence tried it in a Android-Studio project using Gradle but the config file was not necessary either.
So Rémond´s answer might make sense but for me everything is working fine (including generating InstanceID-Token and also Topic-Messaging is working).
So in fact, it should work without adding the file and you do not need this file anyway.

- 1,341
- 1
- 16
- 22
-
Are you using the old method to integrate ? i guess this is because you are still passing the parameter from code. – Mickaël Rémond Aug 06 '15 at 05:20
-
No I only use the new API, never passing the sender id from code, that's why I have been confused about the docs either and there is no old method for InstanceID API, this is completely new – sschmid Aug 06 '15 at 05:37
-
Well, there must be a way to do the mapping as otherwise GCM does not know that the push API key match this app. – Mickaël Rémond Aug 06 '15 at 07:04
-
You are right, I just had a look at my code, The sender id is needed when calling ´getToken´ from ´InstanceId´ (I am sorry) Nevertheless the config file seems to be useless – sschmid Aug 06 '15 at 07:19
-
I updated my answer to give more details on how it works and why it works without the file in your case. – Mickaël Rémond Aug 06 '15 at 08:44