Android 上的 Firebase 需要什么 ProGuard 配置? [英] What ProGuard configuration do I need for Firebase on Android?

查看:44
本文介绍了Android 上的 Firebase 需要什么 ProGuard 配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当为 Android 应用使用 Firebase SDK 时,我不断收到如下警告和错误(在 Eclipse 中):

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') ...

遗憾的是,Firebase 没有关于其与 ProGuard 一起使用的任何官方文档.

Unfortunately, Firebase doesn't have any official documentation about its use with ProGuard.

在使用 ProGuard 进行混淆时,我的应用需要哪些指令才能使用 Firebase 成功编译版本?

What directives do I need for my apps to successfully compile releases with Firebase when obfuscated with ProGuard?

推荐答案

根据我的个人测试,结果证明 Firebase 增强的 Android 应用程序需要使用 ProGuard 进行编译.

Based on my personal tests, it turned out something along these lines is necessary for Firebase-enhanced Android apps to compile with ProGuard.

无论如何,您必须添加 -keepnames class com.my.package.beans.** { *;} 如果您在 Firebase 中使用自定义对象,即 bean 或 POJO.

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.** { *; }

最后的手段:

-keep class !com.my.package.** { *; }

注意事项:

欢迎任何官方指南.-dontwarn 指令显然是危险的,代码可能会在我没有测试过的地方中断.此外,上述规则非常宽松,其他规则可能会更好地优化您的 APK.

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.

这篇关于Android 上的 Firebase 需要什么 ProGuard 配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆