简体   繁体   中英

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.

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

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.

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:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM