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

No static method zzUr() in Firebase when I try to use Analytics with Notifications

我开始使用 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.access00(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)

我在 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 或 Google Play 服务库。所有库都被保护在一起,因此内部 methods/classes 的名称在不同库之间匹配。当您使用不同版本的库时,您可能会看到缺少 类 和方法(就像您在本例中所做的那样)。来自不同版本的混合库也没有经过测试。即使您碰巧成功 运行 该应用程序,它也很可能无法按设计运行。

请始终使用来自完全相同发行版本的库。

尝试更改 build.gradle 中的 Firebase 版本。对我有用!

版本必须相同:

compile 'com.google.firebase:firebase-analytics:9.2.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'com.google.firebase:firebase-core:9.2.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'

对我来说,这行得通。我更改了版本。

compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-database:9.4.0'

保持您正在使用的所有 firebase 工具的相同版本...

(To the people hoping for the resolution while referring to the above answers with latest Play-services and firebase libraries)

从所有 Play 服务和 Firebase 库的版本 15 开始,版本号遵循语义版本控制方案。

每个 Maven 依赖匹配 com.google.android.gms:play-services-* 和 com.google.firebase:firebase-* 不再需要具有相同的版本号才能在构建时和 运行 时都能正常工作。

有关更详细的说明,请参阅此处:announcing new SDK versioning

希望对使用最新版 SDK 的人有所帮助。

对于尚未迁移到 AndroidX 并尝试将其 Firebase 和 Play 服务基础 SDK 更新到最新版本 17.0.0 的用户,请参考以下内容:June17,2019 release notes

现在让您知道我为解决问题所做的工作是具有如下依赖项:

app didn't work with following libs:

implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.google.firebase:firebase-analytics:16.5.0'

App worked with following:

implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.8'

implementation 'com.google.android.gms:play-services-ads:17.2.1'

implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-messaging:17.3.3'
implementation 'com.google.firebase:firebase-analytics:16.4.0'

所以基本上我降低了我的 firebase-messaging 版本和分析,它就像一个魅力...