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 !

3
  • 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
    Commented Jun 30, 2012 at 19:11
  • thanks i copied the jar file to the libs folder and it seems to work ! Commented Jul 2, 2012 at 6:20
  • @Shushu: the jar is in my libs folder, but not in dependencies. So, how to add it in dependencies? Commented Feb 11, 2015 at 8:38

10 Answers 10

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.

1
  • 6
    my gcm.jar is inside libs and i hae configures path still no success
    – Passion
    Commented Oct 29, 2013 at 10:43
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

0
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.

2
  • 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
    Commented Jun 18, 2013 at 3:23
  • Your answer is great and its worked for me. Thanks to Jackson and BLT also Commented Jul 12, 2013 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.

0
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.

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.

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

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"

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.