Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 应用程序在测试设备上调试时工作正常,但在版本apk中没有,它不会从firebase获取post.class变量_Java_Android_Firebase Realtime Database - Fatal编程技术网

Java 应用程序在测试设备上调试时工作正常,但在版本apk中没有,它不会从firebase获取post.class变量

Java 应用程序在测试设备上调试时工作正常,但在版本apk中没有,它不会从firebase获取post.class变量,java,android,firebase-realtime-database,Java,Android,Firebase Realtime Database,我的应用程序在活动中有帖子,帖子有一个图像和类似按钮,还有星星计数和共享按钮。当调试到测试设备时,一切正常,但在发布的版本中不正常。 在google store上发布应用程序后,post.class下的所有变量都不会被接收/显示(所有使用post.get的变量,例如post.getimage()都不会从firebase数据库获取值。另一方面,会接收存储在post之外的值(例如,我有一个单独的starcount节点,我得到了childcount的值,它工作正常)。 我已经尝试了所有可能的解决方案,

我的应用程序在活动中有帖子,帖子有一个图像和类似按钮,还有星星计数和共享按钮。当调试到测试设备时,一切正常,但在发布的版本中不正常。 在google store上发布应用程序后,post.class下的所有变量都不会被接收/显示(所有使用post.get的变量,例如post.getimage()都不会从firebase数据库获取值。另一方面,会接收存储在post之外的值(例如,我有一个单独的starcount节点,我得到了childcount的值,它工作正常)。 我已经尝试了所有可能的解决方案,但没有任何效果: 使用SHA发布密钥(上载密钥)更新应用程序,然后生成已签名的apk(aab),所有三个SHA(调试、发布和应用程序签名密钥)都保存在我的firebase项目指纹下。 我还检查了firebase数据库规则。 我将post.class中的一些变量从public更改为private

我直接在设备上下载了APK,但它也不工作。它在测试设备上工作得非常好。如果有人能提供帮助,我将不胜感激

这是邮班

// [START post_class]

@IgnoreExtraProperties

public class Post {

private String image;
public String uid;
public String author;
public String title;
public String body;
public String videoLink;
private int starCount = 0;
private int starCount2 = 0;
private Map<String, Boolean> stars = new HashMap<>();

//shares
private String ntDeeplink;
private int ntNumShares = 0 ;
private String postID;

public Post() {
    // Default constructor required for calls to DataSnapshot.getValue(Post.class)
}

public Post(String image, String uid, String author, String title, String body, String videoLink) {
    this.image = image;
    this.uid = uid;
    this.author = author;
    this.title = title;
    this.body = body;
    this.videoLink = videoLink;


}

//note 2 constructor here were icrease instead of one , and the above one in connectedto some methods already


public Post(int starCount, Map<String, Boolean> stars, String ntDeeplink, int ntNumShares, String ntPostID) {
    this.starCount = starCount;
    this.stars = stars;
    this.ntDeeplink = ntDeeplink;
    this.ntNumShares = ntNumShares;
    this.postID = postID;
}

public Post(int starCount2) {
    this.starCount2 = starCount2;
}

// [START post_to_map]   ....this and bindToPost(if there is a view) replace the method of populateViewHolder
// but only for non Storage Items like Images
@Exclude
public Map<String, Object> toMap() {
    HashMap<String, Object> result = new HashMap<>();

    result.put("image",image);
    result.put("uid", uid);
    result.put("author", author);
    result.put("title", title);
    result.put("body", body);
    result.put("videoLink", videoLink);
    result.put("starCount", starCount);
    result.put("starCount2", starCount2);
    result.put("stars", stars);
    //numShares also created int the contants
    result.put("ntNumShares", ntNumShares);
    result.put("ntDeeplink", ntDeeplink);
    result.put("postID", postID);

    return result;
}

//shares

public String getImage() {
    return image;
}

public void setImage(String image) {
    this.image = image;
}

public String getUid() {
    return uid;
}

public void setUid(String uid) {
    this.uid = uid;
}

public String getAuthor() {
    return author;
}

public void setAuthor(String author) {
    this.author = author;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getBody() {
    return body;
}

public void setBody(String body) {
    this.body = body;
}

public String getVideoLink() {
    return videoLink;
}

public void setVideoLink(String videoLink) {
    this.videoLink = videoLink;
}

public int getStarCount() {
    return starCount;
}

public void setStarCount(int starCount) {
    this.starCount = starCount;
}

public int getStarCount2() {
    return starCount2;
}

public void setStarCount2(int starCount2) {
    this.starCount2 = starCount2;
}

public Map<String, Boolean> getStars() {
    return stars;
}

public void setStars(Map<String, Boolean> stars) {
    this.stars = stars;
}

public String getNtDeeplink() {
    return ntDeeplink;
}

public void setNtDeeplink(String ntDeeplink) {
    this.ntDeeplink = ntDeeplink;
}

public int getNtNumShares() {
    return ntNumShares;
}

public void setNtNumShares(int ntNumShares) {
    this.ntNumShares = ntNumShares;
}

public String getPostID() {
    return postID;
}

public void setPostID(String postID) {
    this.postID = postID;
}


// [END post_to_map]

经过两天的搜索,我找到了问题的答案: 造成此问题的是Proguard。创建签名的APK时,Proguard会清除所有未使用的代码或类。在我的情况下,Proguard错误地删除了post.class:

解决方案:

  • 我将post.class和其他我想确保Proguard不会删除的类放在一个包(模型)下,您可以将它们放在不同的包下,但您需要将它们全部列在Proguard规则下,如下所示:

  • 在5月份的android studio项目中,我打开了proguard-rules.pro

  • 当Proguard创建签名的APK(或aab)时,我将下面的一行放在列表中,并防止类被删除

其中com.domain.app是包的名称


希望这能节省一些时间。

这对我的案例非常有用-keep class com.hamsoftug.cashflow.models.*{*}
        ValueEventListener postListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // Get Post object and use the values to update the UI
            final Post post = dataSnapshot.getValue(Post.class);
            final DatabaseReference postRef = mPostReference;
            final DatabaseReference postRefLikes = mPostReferenceLikes;


            // [START_EXCLUDE]

            //Image
            String image = null;
            if (post != null) {
                image = post.getImage();
            }
            Picasso.with(HbDetailActivity.this).load(image).placeholder(R.drawable.likes_hl_gr).into(hbDActivityPostImage);
-keepclassmembers class com.mydomain.app.models.** {*;}