android 使用 GCM 的应用在 运行 后崩溃

android app using GCM crash after running

我正在尝试使用 GCM 技术创建一个应用程序来推送通知,但该应用程序在 运行 后崩溃了。

这是我的日志文件..我找不到错误:

05-11 20:04:55.758: I/dalvikvm(20069): DexOpt: access denied from Lcom/google/android/gms/common/GooglePlayServicesUtil; to field Landroid/app/Notification;.extras
05-11 20:04:55.758: W/dalvikvm(20069): VFY: unable to resolve instance field 12
05-11 20:04:55.758: D/dalvikvm(20069): VFY: replacing opcode 0x54 at 0x00b3
05-11 20:04:55.758: E/dalvikvm(20069): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
05-11 20:04:55.758: W/dalvikvm(20069): VFY: unable to resolve check-cast 29 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
05-11 20:04:55.758: D/dalvikvm(20069): VFY: replacing opcode 0x1f at 0x000e
05-11 20:04:55.758: I/dalvikvm(20069): Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh
05-11 20:04:55.758: W/dalvikvm(20069): VFY: unable to resolve virtual method 534: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
05-11 20:04:55.758: D/dalvikvm(20069): VFY: replacing opcode 0x6e at 0x000b
05-11 20:04:55.793: D/AndroidRuntime(20069): Shutting down VM
05-11 20:04:55.793: W/dalvikvm(20069): threadid=1: thread exiting with uncaught exception (group=0x4108f2a0)
05-11 20:04:55.803: E/AndroidRuntime(20069): FATAL EXCEPTION: main
05-11 20:04:55.803: E/AndroidRuntime(20069): java.lang.RuntimeException: Unable to resume activity {com.prgguru.example/com.prgguru.example.MainActivity}: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2639)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2667)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2140)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.app.ActivityThread.access0(ActivityThread.java:140)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.os.Looper.loop(Looper.java:137)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.app.ActivityThread.main(ActivityThread.java:4921)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at java.lang.reflect.Method.invokeNative(Native Method)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at java.lang.reflect.Method.invoke(Method.java:511)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at dalvik.system.NativeStart.main(Native Method)
05-11 20:04:55.803: E/AndroidRuntime(20069): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
05-11 20:04:55.803: E/AndroidRuntime(20069):    at com.google.android.gms.common.GooglePlayServicesUtil.zzO(Unknown Source)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at com.prgguru.example.MainActivity.checkPlayServices(MainActivity.java:206)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at com.prgguru.example.MainActivity.onResume(MainActivity.java:235)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1199)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.app.Activity.performResume(Activity.java:5280)
05-11 20:04:55.803: E/AndroidRuntime(20069):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2629)
05-11 20:04:55.803: E/AndroidRuntime(20069):    ... 12 more
05-11 20:04:55.838: D/dalvikvm(20069): GC_CONCURRENT freed 218K, 14% free 9628K/11143K, paused 33ms+3ms, total 77ms
05-11 20:04:55.838: D/dalvikvm(20069): WAIT_FOR_CONCURRENT_GC blocked 33ms
05-11 20:05:11.633: I/Process(20069): Sending signal. PID: 20069 SIG: 9

怎么了?!

您应该在标签内添加此行。

 <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

确保 google-play-service_lib 库已添加或未添加到您的项目。