5

I'm trying to run GCM sample application present here in my Eclipse.

I'm not using Android studio and I don't have gradle plug-in in my eclipse.

After importing the GCM client android app in eclipse, I'm getting error:

gcm_defaultSenderId cannot be resolved or is not a field

I do not want to shift to Android studio.

  1. How can I remove this error & make my app run?

  2. If I've to install gradle, which plugin should I use in my Eclipse-MARS?

PS - I've never used gradle before.

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
adam black
  • 607
  • 5
  • 14
  • Welcome to Stack Overflow. I have fixed a few English issues and marked up the error using >. Please explain further when you get the error, for example when you are compiling or starting up Eclipse ???? – Rohit Gupta Oct 14 '15 at 19:28
  • You can drop the R.string id and get the value by name: http://stackoverflow.com/a/38995785/606351 – Vaiden Aug 18 '16 at 10:43

1 Answers1

16

Follow the steps to get it resolved:

1.) Log in to Google Developer site URL : https://developers.google.com/cloud-messaging/android/start

2.) Click "GET A CONFIGURATION FILE" button under Step #2

3.) Provide a App name and the appropriate package name.

4.) Click "Continue to choose and configure services" button.

5.) Select "Cloud Messaging" and click "ENABLE GOOGLE CLOUD MESSAGING" button.

6.) Download the google-services.json file.

7.) Open the file and get the "project_number" value under "project_info".

8.) Open Eclipse and add the following entry under ../res/values/strings.xml file. Replace the PROJECT_ID with the value extracted from Step 7.

<string name="gcm_defaultSenderId">PROJECT_ID</string>

9.) Clean and Build, it should work.

  • Well I'm still wonderinf how Google-playservices gcm example works as I didn't find ``PROJECT_ID`` anywhere. Help tip in Android Studio says that gcm_defaultSenderId is directly derived from google-services.json but I wonder how! – fralbo Jan 21 '16 at 14:24
  • Man, you are a LIFE SAVIOR, I didn't find the problem on my code and I was just for 1 day and a half looking for it. How is it that the documentation has the word PROJECT_ID everywhere when, in fact, the PROJECT_NUMBER is the key we should use... Thank you very much for the STEP 7!! – luiscosta Feb 18 '16 at 15:39