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

Android 当我尝试将分析与通知一起使用时,Firebase中没有静态方法zzUr(),android,firebase,firebase-cloud-messaging,firebase-analytics,Android,Firebase,Firebase Cloud Messaging,Firebase Analytics,我开始使用Firebase云消息 我只有指南中使用通知和分析的示例代码。如果我没有安装分析通知,则可以正常工作,但当我添加gradle分析时,我在尝试发送通知时出现以下错误: java.lang.NoSuchMethodError:没有静态方法zzUr()Landroid/content/Intent;在Lcom/google/firebase/iid/FirebaseInstanceInInternalReceiver类中;或其超类(声明'com.google.firebase.iid.fir

我开始使用Firebase云消息

我只有指南中使用通知和分析的示例代码。如果我没有安装分析通知,则可以正常工作,但当我添加gradle分析时,我在尝试发送通知时出现以下错误:

java.lang.NoSuchMethodError:没有静态方法zzUr()Landroid/content/Intent;在Lcom/google/firebase/iid/FirebaseInstanceInInternalReceiver类中;或其超类(声明'com.google.firebase.iid.firebaseInstanceInInternalReceiver'出现在/data/app/com.myapp.newapp-2/base.apk中),位于com.google.firebase.messagingservice.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(本机方法) 位于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)

我在格拉德尔有:

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-messaging:9.0.2'
对此(所有设备上的版本相同)


如果这不起作用,则不支持使用不同版本的firebase或Google Play服务库将所有firebase版本设置为9.0.2或9.0.0。所有库都在一起前进,因此内部方法/类的名称在不同库之间匹配。当您使用不同版本的库时,可能会看到缺少的类和方法(在本例中就是这样)。混合来自不同版本的库也没有经过测试。即使你碰巧成功运行了该应用程序,它也很可能无法按设计工作


请始终使用完全相同版本的库。

尝试在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'
我发现对于
播放服务
,我必须使用相同的版本:

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工具的相同版本

(对于希望解决问题的人,请参考上述最新答案。) 播放服务和firebase库)

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

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

有关更多详细说明,请参阅此处:

希望它能帮助人们使用最新的SDK版本

另外,对于尚未迁移到AndroidX并试图将Firebase和Play services base SDK更新为最新版本(17.0.0)的用户,请参考以下内容:

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

应用程序无法与以下库一起工作:

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'
应用程序与以下内容一起工作:

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消息版本和分析,它就像一个魅力…

嗨,丹尼尔,是的,出于某种原因,我不得不使用相同的版本。它起作用了!
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'
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'