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

半世苍凉 提交于 2019-11-27 02:37:57

问题


I'm starting to use the Firebase Cloud Messaging.

I have only the example code of the guide to use the Notifications and Analytics. If I don't install Analytics notifications works fine, but when I add in gradle the Analytics I have get this error when I try to send a notification:

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)

I have in gradle:

compile 'com.google.firebase:firebase-messaging:9.0.2'
compile 'com.google.firebase:firebase-core:9.2.0'

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

Any help will be appreciated!


回答1:


try this:

add

compile 'com.google.firebase:firebase-analytics:9.2.0'

and change this:

compile 'com.google.firebase:firebase-messaging:9.0.2'

to THIS (same version on all)

compile 'com.google.firebase:firebase-messaging:9.2.0'

if this doesn't work, put all firebase versions to 9.0.2, or 9.0.0




回答2:


I had the same issue, as others said I used the same version for all firebase libraries, but it didn't worked:

compile 'com.google.firebase:firebase-core:9.6.0'
compile 'com.google.firebase:firebase-messaging:9.6.0'

I found that I must use the same version for 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'



回答3:


Using Firebase or Google Play Service libraries from different version is not supported. All libraries are proguarded together so the name of internal methods/classes match between different libraries. When you use libraries from different versions you will likely see missing classes and methods (as you do in this case). Mixing libraries from different versions is also not tested. Even if you happen to successfully run the app its very likely things will not work as designed.

Please always use libraries from exactly the same release version.




回答4:


keep same version of all firebase tools which you are using...




回答5:


Try to change the Firebase Versions in build.gradle. It works to me!

The Versions must be the same:

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'



回答6:


For me, this works. I changed the versions.

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'



回答7:


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

Beginning with version 15 of all Play services and Firebase libraries, version numbers adhere to the semantic versioning scheme.

Each Maven dependency matching com.google.android.gms:play-services-* and com.google.firebase:firebase-* is no longer required to have the same version number in order to work correctly at build time and at run time.

For More detailed explanation refer here : announcing new SDK versioning

Hope it will help to people using latest SDK versioning.

Also for people who have not migrated to AndroidX yet and who tries to update their Firebase and Play services base SDK's to latest which is 17.0.0 kindly refer below : June17,2019 release notes

Now to let you know what I did to fix my problem was to have the dependencies as follows:

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'

So basically I lowered down my firebase-messaging version along with analytics and it worked like a charm...



来源:https://stackoverflow.com/questions/38202644/no-static-method-zzur-in-firebase-when-i-try-to-use-analytics-with-notificatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!