What ProGuard configuration do I need for Firebase on Android?

caw picture caw · Oct 9, 2014 · Viewed 40.9k times · Source

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?

Answer

caw picture caw · Oct 9, 2014

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.