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

非 Y 不嫁゛ 提交于 2019-12-08 01:34:46

问题


Please help, it's all the days that I work on this problem and used all possible solutions found on the web.

Requirements: Use juno eclipse, ADT 20 I have works with business GCM, I did a project a bit more complicated using the demo of Android developers (http://developer.android.com/guide/google/gcm/demo.html) And I realized that my application was in Crask each call class GCMRegistrar.

So I created a minimal exercise that will work if I unlock everything.

import com.google.android.gcm.GCMRegistrar;

    public class Manda extends Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_manda);

        crash --->  GCMRegistrar.checkDevice(this);

            // while developing the app, then uncomment it when it's ready.

            GCMRegistrar.checkManifest(this);

        }

I attach the screenshot of the min exercise I added the gcm.jar library and I did all I found.

I am a new user than I can not post img but I put a public link of bropbox https://www.dropbox.com/s/dyi0y4sppz4rcq3/img%20GCM%20problem.zip


回答1:


As stated in Google's docs, you MUST add your AndroidManifast.xml file the following:

<service android:name="YOUR.PACKAGE.NAME.GCMIntentService" />

<receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="YOUR_CATEGORY_NAME" />
            </intent-filter>
        </receiver>

Make sure you put your IntentService class in the right package.

In addition, how did you add the gcm.jar to you project? You need to create a "libs" folder in your project and put the jar there




回答2:


Solution 1:

  1. Check that you have put gcm.jar file inside libs and not lib folder.

Solution 2:

Mostly this is the problem.Follow below steps to resolve the problem:

  1. Right click on Project->Build Path-> Configure Build Path and then Order and Exports
  2. Now check the Android Private Libraries .The checkbox should check of required library.
  3. Refresh ,Clean and Run..here you go!



回答3:


The problem was my emulator without Google Apis (Google Inc). If you are using android emulator you have to create emulator with Google Apis (Google Inc).



来源:https://stackoverflow.com/questions/12734303/gcm-java-lang-noclassdeffounderror-com-google-android-gcm-gcmregistrar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!