当我尝试将 Analytics 与通知一起使用时,Firebase 中没有静态方法 zzUr()

新手上路,请多包涵

我开始使用 Firebase 云消息传递。

我只有使用通知和分析指南的示例代码。如果我不安装 Analytics 通知工作正常,但是当我在 gradle 中添加 Analytics 时,我在尝试发送通知时遇到此错误:

java.lang.NoSuchMethodError: 没有静态方法 zzUr()Landroid/content/Intent;在类 Lcom/google/firebase/iid/FirebaseInstanceIdInternalReceiver 中;或其超类(’com.google.firebase.iid.FirebaseInstanceIdInternalReceiver’ 的声明出现在 /data/app/com.myapp.newapp-2/base.apk 中)在 com.google.firebase.messaging.FirebaseMessagingService.zzz(未知来源)在 com.google.firebase.iid.zzb.onStartCommand(未知来源) 在 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3316) 在 android.app.ActivityThread.access\(2200(ActivityThread.java:177)在 android.app.ActivityThread\)H.handleMessage(ActivityThread.java:1547) 在 android.os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper.java:145) 在 android。 app.ActivityThread.main(ActivityThread.java:5951) 在 java.lang.reflect.Method.invoke(Native Method) 在 java.lang.reflect.Method.invoke(Method.java:372) 在 com.android.internal。 os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

我在gradle中:

 compile 'com.google.firebase:firebase-messaging:9.0.2'
compile 'com.google.firebase:firebase-core:9.2.0'

我的 MyFirebaseMessagingService:

 @Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // If the application is in the foreground handle both data and notification messages here.
    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
    Log.d(TAG, "From: " + remoteMessage.getFrom());
    Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());

    sendNotification(remoteMessage.getNotification().getBody());
}

private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

任何帮助将不胜感激!

原文由 S.P. 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 334
2 个回答

试试这个:

添加

compile 'com.google.firebase:firebase-analytics:9.2.0'

并改变这个:

 compile 'com.google.firebase:firebase-messaging:9.0.2'

到这个(所有版本相同)

 compile 'com.google.firebase:firebase-messaging:9.2.0'

如果这不起作用,请将所有 firebase 版本设置为 9.0.2 或 9.0.0

原文由 Daniel Andujar 发布,翻译遵循 CC BY-SA 3.0 许可协议

我有同样的问题,正如其他人所说,我对所有 firebase 库使用了相同的版本, 但它没有用

 compile 'com.google.firebase:firebase-core:9.6.0'
compile 'com.google.firebase:firebase-messaging:9.6.0'

我发现我必须对 play-services 使用相同的版本:

 compile 'com.google.android.gms:play-services-analytics:9.6.0'
compile 'com.google.android.gms:play-services-base:9.6.0'
compile 'com.google.android.gms:play-services-gcm:9.6.0'

原文由 Hamed Ghadirian 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题