com.google.android.gsf package couldn't be fou

2020-01-25 06:01发布

I am trying to use new Google Cloud Messaging system but I have some problems.

I read Getting Started document and reviewed demo app; after that I applied requirements to my application then I created a new virtual device with API 16.

But when I try to register my device to GCM, it fails because of this line:

GCMRegistrar.checkDevice(getApplicationContext()); 

In logcat I see these errors:

07-05 07:06:31.925: E/AndroidRuntime(691): FATAL EXCEPTION: main
07-05 07:06:31.925: E/AndroidRuntime(691): java.lang.UnsupportedOperationException: Device does not have package com.google.android.gsf
07-05 07:06:31.925: E/AndroidRuntime(691):  at com.google.android.gcm.GCMRegistrar.checkDevice(GCMRegistrar.java:83)
07-05 07:06:31.925: E/AndroidRuntime(691):  at aero.tav.mobile.genel$4.onClick(genel.java:201)
07-05 07:06:31.925: E/AndroidRuntime(691):  at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
07-05 07:06:31.925: E/AndroidRuntime(691):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 07:06:31.925: E/AndroidRuntime(691):  at android.os.Looper.loop(Looper.java:137)
07-05 07:06:31.925: E/AndroidRuntime(691):  at android.app.ActivityThread.main(ActivityThread.java:4745)
07-05 07:06:31.925: E/AndroidRuntime(691):  at java.lang.reflect.Method.invokeNative(Native Method)
07-05 07:06:31.925: E/AndroidRuntime(691):  at java.lang.reflect.Method.invoke(Method.java:511)
07-05 07:06:31.925: E/AndroidRuntime(691):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-05 07:06:31.925: E/AndroidRuntime(691):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-05 07:06:31.925: E/AndroidRuntime(691):  at dalvik.system.NativeStart.main(Native Method)

I had added gcm.jar to my class path; I don't know what is wrong.

2条回答
叼着烟拽天下
2楼-- · 2020-01-25 06:17

It's probably running on a device that doesn't support GCM, so your call to GCMRegistrar.checkDevice( this ); is throwing an exception. Check your logcat to be sure.

If you're testing it on an emulator, make sure you have the emulator set up to use Google APIs. When you create the emulator, the create new AVD window has a "Target" box. Select something in that box that says "Google APIs".

enter image description here

查看更多
三岁会撩人
3楼-- · 2020-01-25 06:23

it seems to me like you're using the wrong emulator.

The default emulator uses a regular Android emulator that doesn't have any Google packages and can't run all sorts of things like maps, c2dm and all sorts of stuff like that.

what you want to do, is create a new emulator that can support the Google APIs.

then, when you run the project, choose the emulator that runs the target name Google APIs (Google Inc).

good luck.

查看更多
登录 后发表回答