29

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

通知と分析を使用するためのガイドのサンプル コードしかありません。Analytics 通知をインストールしないと問題なく動作しますが、Analytics をグラドルに追加すると、通知を送信しようとすると次のエラーが発生します。

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( android.app.ActivityThread.access$2200(ActivityThread.java:

私は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());
}

どんな助けでも大歓迎です!

4

7 に答える 7

53

これを試して:

追加

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

于 2016-07-05T11:51:19.707 に答える
14

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'
于 2016-09-24T11:35:37.767 に答える
9

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

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

于 2016-07-06T16:54:44.767 に答える
2

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'
于 2016-07-28T18:28:36.793 に答える
0

(最新のPlayサービスとfirebaseライブラリで上記の回答を参照しながら解決を望んでいる人へ)

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

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

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

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

また、まだ AndroidX に移行しておらず、Firebase および Play サービスの基本 SDK を最新の 17.0.0 に更新しようとしている方は、以下を参照してください。2019 年 6 月 17 日のリリース ノート

問題を解決するために私がしたことをお知らせするために、依存関係を次のようにしました。

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

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のバージョンを下げたところ、魅力的に機能しました...

于 2019-07-02T05:09:17.577 に答える