我开始使用Firebase云消息传递.
我只有指南的示例代码来使用通知和分析.如果我不安装Google Analytics通知工作正常,但当我添加gradle时,我尝试发送通知时遇到此错误:
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)的机器人. app.ActivityThread.main(ActivityThread.java:5951)在java.lang.reflect.Method.invoke(本机方法)在java.lang.reflect.Method.invoke(Method.java:372)在com.android.internal. os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1400)at 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()); }
任何帮助将不胜感激!
试试这个:
加
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
我有同样的问题,因为其他人说我对所有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'
不支持使用不同版本的Firebase或Google Play服务库.所有库都在一起进行编程,因此内部方法/类的名称在不同库之间匹配.当您使用来自不同版本的库时,您可能会看到缺少的类和方法(就像在这种情况下一样).混合不同版本的库也未经过测试.即使您碰巧成功运行该应用程序,其可能性也不会按设计运行.
请始终使用完全相同的发行版本中的库.