Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM : java.lang.noclassdeffounderror: com.google.android.gcm.GCMRegistrar

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 !

like image 298
user1492955 Avatar asked Jun 30 '12 12:06

user1492955


4 Answers

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.

like image 135
Lalit Poptani Avatar answered Nov 11 '22 05:11

Lalit Poptani


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

like image 40
user1503987 Avatar answered Nov 11 '22 04:11

user1503987


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.

like image 10
Jacksonkr Avatar answered Nov 11 '22 04:11

Jacksonkr


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.

like image 6
Shamitha Avatar answered Nov 11 '22 05:11

Shamitha