'Firebase + Proguard/R8

I am currently working on setting up Firebase (FCM) in my project and have encountered a problem when I run my R8-obfuscated app, the Firebase service (FirebaseMessagingService) no longer works. Has anyone encountered the same problem? Any solution?

UPD: Finally I fixed it for FCM by downgrading to

com.google.firebase:firebase-messaging:15.0.0

There are some deprecated classes in use now but it works.

UPD2: While running obfuscated app with the newest versions of libraries I also noticed warnings in the logs:

W/FA: Failed to retrieve Firebase Instance Id

This is most likely the root of the problem.



Solution 1:[1]

Finally got it fixed, next proguard rules did a trick for me:

# Firebase
-keep class com.google.android.gms.** { *; }
-keep class com.google.firebase.** { *; } // especially this one

Solution 2:[2]

Just see the complaints R8 throws in the build log ...and do as the say. Only because it might provide configuration for the library itself, does not imply it provides configuration for your application code. Also make sure to have the fingerprint of the release key added in the Firebase console.

Solution 3:[3]

In my case I broke it myself.

While setting up obfuscation I turned on debug mode for testing

release {
    debuggable true
}

And with combination of

FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)

it was bound to fail, don't be me :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Maksim Sukhotski
Solution 2 Martin Zeitler
Solution 3 solidogen