web-dev-qa-db-ja.com

通知でアナリティクスを使用しようとすると、Firebaseに静的メソッドzzUr()がありません

Firebase Cloud Messagingを使い始めています。

Notifications and Analyticsを使用するためのガイドのサンプルコードのみがあります。アナリティクスの通知をインストールしないと問題なく動作しますが、gradleにアナリティクスを追加すると、通知を送信しようとするとこのエラーが発生します。

Java.lang.NoSuchMethodError:静的メソッドなしzzUr()Landroid/content/Intent;クラスLcom/google/firebase/iid/FirebaseInstanceIdInternalReceiver内。またはcom.google.firebase.messaging.FirebaseMessagingService.zzz(不明なソース)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) 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());
}

どんな助けも感謝します!

28
S.P.

これを試して:

追加

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に設定します

53
Daniel Andujar

他の人がすべての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'
14
Hamed.Ghadirian

異なるバージョンのFirebaseまたはGoogle Play Serviceライブラリの使用はサポートされていません。すべてのライブラリは一緒に保護されるため、内部メソッド/クラスの名前は異なるライブラリ間で一致します。異なるバージョンのライブラリを使用すると、クラスとメソッドが欠落している可能性があります(この場合のように)。異なるバージョンのライブラリの混合もテストされていません。アプリを正常に実行したとしても、設計どおりに機能しない可能性が非常に高くなります。

常に同じリリースバージョンのライブラリを使用してください。

9
djabi

すべてのファイアベースの同じバージョンを保持 enter image description here 使用しているツール...

4
M-Groups

私にとって、これはうまくいきます。バージョンを変更しました。

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'
2
mesutpiskin

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'
2
Douglas

(最新のPlay-servicesおよびfirebaseライブラリで上記の回答を参照しながら解決を望んでいる人々へ)

すべてのPlayサービスとFirebaseライブラリのバージョン15以降、バージョン番号はセマンティックバージョン管理スキームに準拠しています。

Com.google.Android.gms:play-services- *およびcom.google.firebase:firebase- *に一致する各Maven依存関係は、動作するために同じバージョン番号を持つ必要がなくなりましたビルド時および実行時に正しく

詳細な説明については、こちらを参照してください。 新しいSDKバージョン管理の発表

最新のSDKバージョン管理を使用している人々に役立つことを願っています。

また、AndroidXにまだ移行しておらず、FirebaseおよびPlayサービスのベースSDKを最新のもの(17.0.0)に更新しようとしている場合は、以下を参照してください: June17,2019 release notes

ここで、問題を解決するために私が何をしたかを知らせるために、次のような依存関係を設定しました。

次のライブラリではアプリは動作しませんでした:

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-messagingバージョンを下げて、それは魅力のように働いた...

0
Hiten Bahri