20

I am trying to register a device onto GCM using the following code:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    GCMRegistrar.checkDevice(this);
    // the following function can be removed when deploying the app
    GCMRegistrar.checkManifest(this);

    final String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) {
      GCMRegistrar.register(this, SENDER_ID);
    } else {
      Log.v(TAG, "Already registered");
    } 

I have imported import com.google.android.gcm.GCMRegistrar;
and also added GCM.jar to my buildpath in Eclipse which i got thru the sdk download

Please help !

Android Developer
  • 987
  • 1
  • 8
  • 22
user1492955
  • 1,728
  • 2
  • 12
  • 13
  • 3
    You should put the jar in your libs folder (not lib), and verify it is in the "Android dependencies" list. Sometimes I found out re-arranging the order of the dependencies changes behavior, so you can try it also – Shushu Jun 30 '12 at 19:11
  • thanks i copied the jar file to the libs folder and it seems to work ! – user1492955 Jul 02 '12 at 06:20
  • @Shushu: the jar is in my libs folder, but not in dependencies. So, how to add it in dependencies? – Narendra Singh Feb 11 '15 at 08:38

10 Answers10

31

In the updated ADT(Above ADT 17) you have to put jar files inside libs folder and not lib. So make sure that you put gcm.jar file inside libs and not lib folder.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
28

Just go to project properties -> java build path -> "order and export " now giv a tick on the jar file "GCM.jar" that you have added

user1503987
  • 281
  • 2
  • 2
10

My gcm.jar was already in libs, so it wasn't a folder naming issue for me..

I had to go to Right Click > Build Path > Configure Build path... for the project in question and I removed the following:

  • Any lingering files outside of a folder/bundle
  • Android Private Libraries
  • Any bundles with the word 'reference' in them (you may not have one)

You might get a lot of "errors" in your project so restart Eclipse and let it clean. Once it cleans you'll have no errors. Run your project and viola.

Thanks to DLew for this answer.

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
  • 1
    Thanks so much! this answer may have had zero votes and been pretty far down the page but it's the one that worked when all the others failed for me! – Bltucker Jun 18 '13 at 03:23
  • Your answer is great and its worked for me. Thanks to Jackson and BLT also – Sakthimuthiah Jul 12 '13 at 11:04
6

Make a folder libs in your project folder and put the gcm.jar in it. Then add it to your class path using add external jars in configure build path option.

Shamitha
  • 1,407
  • 1
  • 10
  • 9
3

You have to put gcm.jar file inside libs, then go to project Properties > Java Build Path > Libraries and add it to your path using Add External JARs..., after in Order and Export you check gcm.jar and press OK. That should work

1

Make sure that the gcm jar file is in the right libs folder and added into the java build path at your project properties.

Klaasvaak
  • 5,634
  • 15
  • 45
  • 68
1

I had same problem, after update SDK in my project. it helped for me: I just "add support library" in "Android tools". Hope this helps anyone else.

busylee
  • 2,540
  • 1
  • 16
  • 35
1

Me also got same problem, after adding android-support-v4.jar and gcm.jar into my libs folder no issues found its work like a charm

Thanks

Madhu
  • 1,780
  • 23
  • 47
0

The SENDER_ID field should be the project ID from when you created your google api project. Read the beginning of this: http://developer.android.com/guide/google/gcm/gs.html#libs

TAG should also be a string -> ""tag Name"

matt.hallman
  • 141
  • 1
  • 6
0

Hello You are using old GCM implementations use new implementations available on https://developers.google.com/cloud-messaging/android/start

Jotiram Chavan
  • 375
  • 1
  • 8