When using the Firebase SDK for Android apps, I keep getting warnings and errors like these (in Eclipse):
Warning ... can't find referenced class ... Warning: there were ... unresolved references to classes or interfaces ... You may need to specify additional library jars (using '-libraryjars') ...
Unfortunately, Firebase doesn't have any official documentation about its use with ProGuard.
What directives do I need for my apps to successfully compile releases with Firebase when obfuscated with ProGuard?
Open the Firebase Assistant: Tools > Firebase. In the Assistant pane, choose a Firebase product to add to your app. Expand its section, then click the tutorial link (for example, Analytics > Log an Analytics event). Click Connect to Firebase to connect your Android project with Firebase.
You can download the Firebase config file or Firebase config object for each of your project's apps from the Firebase console's Project settings page. You need this config file or object to configure your app to use Firebase.
ProGuard is a tool to help minify, obfuscate, and optimize your code. It is not only especially useful for reducing the overall size of your Android application as well as removing unused classes and methods that contribute towards the intrinsic 64k method limit of Android applications.
Based on my personal tests, it turned out something along these lines is necessary for Firebase-enhanced Android apps to compile with ProGuard.
In any case, you have to add -keepnames class com.my.package.beans.** { *; }
if you are using custom objects in your Firebase, i.e. beans or POJOs.
Firebase SDK 1.0.18:
-keepnames class com.firebase.** { *; } -keepnames class com.shaded.fasterxml.jackson.** { *; } -keepnames class org.shaded.apache.** { *; } -keepnames class javax.servlet.** { *; } -dontwarn org.w3c.dom.** -dontwarn org.joda.time.** -dontwarn org.shaded.apache.commons.logging.impl.**
Firebase SDK 1.1.1:
-keep class com.firebase.** { *; } -keep class org.shaded.apache.** { *; } -keepnames class com.shaded.fasterxml.jackson.** { *; } -keepnames class javax.servlet.** { *; } -keepnames class org.ietf.jgss.** { *; } -dontwarn org.w3c.dom.** -dontwarn org.joda.time.** -dontwarn org.shaded.apache.** -dontwarn org.ietf.jgss.**
Firebase SDK 2.0.0:
-keep class com.firebase.** { *; } -keep class org.apache.** { *; } -keepnames class com.fasterxml.jackson.** { *; } -keepnames class javax.servlet.** { *; } -keepnames class org.ietf.jgss.** { *; } -dontwarn org.w3c.dom.** -dontwarn org.joda.time.** -dontwarn org.shaded.apache.** -dontwarn org.ietf.jgss.** # Only necessary if you downloaded the SDK jar directly instead of from maven. -keep class com.shaded.fasterxml.jackson.** { *; }
Last resort:
-keep class !com.my.package.** { *; }
Notes:
Any official guideline would be welcome. The -dontwarn
directives are obviously dangerous, code may break at points that I have not tested. Furthermore, the above rules are quite permissive and other rules may better optimize your APKs.
I found this in Firebase documentations:
When using Firebase Realtime Database in your app along with ProGuard you need to consider how your model objects will be serialized and deserialized after obfuscation. If you use DataSnapshot.getValue(Class) or DatabaseReference.setValue(Object) to read and write data you will need to add rules to the proguard-rules.pro file:
# Add this global rule -keepattributes Signature # This rule will properly ProGuard all the model classes in # the package com.yourcompany.models. Modify to fit the structure # of your app. -keepclassmembers class com.yourcompany.models.** { *; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With