【问题标题】:Firebase realtime database does not retrieving data in release apk [Android]Firebase 实时数据库不会在发布 apk [Android] 中检索数据
【发布时间】:2018-05-20 01:24:35
【问题描述】:

在设备或模拟器上运行应用程序时检索到的数据完美,但生成发布apk时没有显示图像

我认为问题是由于proguard所以我尝试了这个答案 https://stackoverflow.com/a/26274623/4819445

但它不起作用。

这是我的proguard_rules.pro

-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-dontwarn org.ietf.jgss.**
-dontwarn com.firebase.**
-dontnote com.firebase.client.core.GaePlatform

-keepattributes Signature
-keepattributes *Annotation*
-keepattributes InnerClasses,EnclosingMethod

-keep class com.images.backgrounds.** { *; }

-keep class com.firebase.** { *; }

-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }


-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.apache.**
-dontwarn org.w3c.dom.**
-dontwarn javax.annotation.**
#
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}

另外,我在模型类中添加了@Keep 我在 bulid gradle 文件中设置了 minifyEnabled = true:

release {
            useProguard true
            shrinkResources true
            minifyEnabled true
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

但是 POJO 的图像仍然没有显示在 APK 中

请帮帮我

【问题讨论】:

标签: android firebase android-proguard


【解决方案1】:

Proguard 很可能会在发布模式下隐藏/剥离这些类,从而使 Firebase 无法序列化/反序列化它们。 您可以包含注释“@Keep”,这样 proguard 就不会从此类中删除任何方法。

例如:

...
@IgnoreExtraProperties
@Keep
public class Posto {
    public String uid;
    public String nome;
...

在 build.gradle 中包含这个依赖:

compile 'com.android.support:support-annotations:25.2.0' 

查看更多信息:https://developer.android.com/studio/build/shrink-code.html

这个答案是基于我自己的问题,在Encapsulated getters refurn null from firebase database only in release. Works fine in debug mode上报告并解决

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,我已经为我的项目构建了一个签名的 Apk 和 App 包,这就是我在 Kotlin 中解决它的方法,您只需将以下注释添加到包含 firebase 凭据的模型或类中说 uid、姓名、电子邮件、照片和其他:

            @IgnoreExtraProperties
            @Keep
            
            there is my full class with my model directory:
            
            @IgnoreExtraProperties
            @Keep
            @Parcelize
            class Post(val uid: String, val title:String, val description:String, val imageUri: String, val likes:Int, val timeStamp:Long) :
                Parcelable {
                constructor() : this("" , "", "", "", 1, -1)
            }
    

    注意:虽然 Google Play 商店需要应用程序包,但我建议您使用相同的登录海证书来构建 apk。然后在你的手机本地运行apk,如果一切正常,那么你可以继续上传你生成的app bundle。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-06
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 2020-12-09
      • 2021-08-20
      • 1970-01-01
      相关资源
      最近更新 更多