Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Compatibility with FCM (Firebase Messaging) 22.0.0 #1340

Merged
merged 4 commits into from
May 23, 2021

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented May 21, 2021

Description

One Line Summary

To fix FCM push token registration when using Firebase Cloud Messaging version 22.0.0 switched to using the newer FirebaseMessaging.getToken API instead of FirebaseInstanceId.getToken which has been completely removed in that version.

Details

  • See commit-by-commit for additional details.

Fixes

The reported symptom of this is any fresh installs getting registered to OneSignal as not subscribed and without a push token. And seeing something like this in the logcat:

E/OneSignal: Unknown error getting FCM Token
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;
        at com.onesignal.PushRegistratorFCM.getToken(PushRegistratorFCM.java:62)
        at com.onesignal.PushRegistratorAbstractGoogle.attemptRegistration(PushRegistratorAbstractGoogle.java:97)
        at com.onesignal.PushRegistratorAbstractGoogle.access$100(PushRegistratorAbstractGoogle.java:37)
        at com.onesignal.PushRegistratorAbstractGoogle$1.run(PushRegistratorAbstractGoogle.java:84)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceId" on path: DexPathList[[zip file "/data/app/com.onesignal.sdktest-MGzr3O5PDJapVYPx3JqH6Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.onesignal.sdktest-MGzr3O5PDJapVYPx3JqH6Q==/lib/arm64, /system/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

Tests

Manual

  • Tested app with firebase-messaging:19.0.0 with minifyEnabled true
  • Tested app with firebase-messaging:22.0.0 with minifyEnabled true
  • Ensured a fresh install shows as subscribed on the OneSignal dashboard.
  • Ensured a push notification successfully displays

This change is Reviewable

* Move the implementation of getToken into it's own method.
   - Allows us to add another implementation in a follow up commit
* New getTokenWithClassFirebaseMessaging method that uses the newer
FirebaseMessaging.getToken() API added in firebase-messaging:21.0.0.
* Since all apps may not have updated to firebase-messaging:21.0.0 or
newer we are catching NoClassDefFoundError & NoSuchMethodError
and falling back to FirebaseInstanceId.getToken
* Bumped the version range of firebase-messaging in
onesignal/build.gradle to [19.0.0, 22.99.99].
* Since FirebaseInstanceId was droped in the version switched it's
implementation to use reflection.
* Added reflection rule to the consumer-progruad-rules.pro so the gralde
`minifyEnabled` does not break the reflection code if someone has
locked their firebase-messaging version to a pre 22.0.0 version.
Copy link
Contributor

@Jeasmine Jeasmine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Base automatically changed from upgrade/roboelectric4.4 to master May 23, 2021 00:15
@jkasten2 jkasten2 merged commit 7fab2f4 into master May 23, 2021
@jkasten2 jkasten2 deleted the fix/firebase-messaging-22.0.0_compat branch May 23, 2021 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants