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

标签 android firebase firebase-cloud-messaging firebase-analytics

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

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

java.lang.NoSuchMethodError: No static method zzUr()Landroid/content/Intent; in class Lcom/google/firebase/iid/FirebaseInstanceIdInternalReceiver; or its super classes (declaration of 'com.google.firebase.iid.FirebaseInstanceIdInternalReceiver' appears in /data/app/com.myapp.newapp-2/base.apk) at com.google.firebase.messaging.FirebaseMessagingService.zzz(Unknown Source) at com.google.firebase.iid.zzb.onStartCommand(Unknown Source) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3316) at android.app.ActivityThread.access$2200(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1547) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

我已经毕业了:

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

关于android - 当我尝试将 Analytics 与通知一起使用时,Firebase 中没有静态方法 zzUr(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38202644/

相关文章:

java - 是否有用于 GCM 云连接服务器的 Java API

firebase - 如何在flutter中使用firebase电话身份验证中的forceResendingToken来重新发送otp

javascript - Firebase Auth 登录区别

ios - 推送通知在 TestFlight 上不起作用

firebase - 获取请求具有无效的身份验证凭据错误 FCM

Android:将浮点值从 Java 传递到 JNI 始终为 NaN

android - java.lang.UnsatisfiedLinkError 错误

android - Camera.getParameters().getSupportedPreviewSizes() 在模拟器中返回 NULL

ios - Firebase 注册函数中无法将类型 'User?' 的值转换为预期参数类型 'User!' 错误

java - 将 FCM 发送到您的 Android 应用的特定版本