java应用程序在测试设备上调试时工作正常,但在发布版apk中没有,它没有获得post。来自firebase的类变量
我的应用程序在活动中有帖子,帖子有一个图像和类似按钮,还有星星计数和共享按钮。当调试到测试设备时,一切正常,但在发布的版本中不正常。 在GoogleStore上发布应用程序后,所有变量都会显示在post下。类未被接收/显示(使用post.get的所有内容,例如post.getimage()未从firebase数据库获取值。另一方面,接收存储在post之外的值(例如,我有一个单独的starcount节点,我得到了childcount的值,它工作正常)。 我已经尝试了所有可能的解决方案,但没有任何效果: 使用SHA发布密钥(上载密钥)更新应用程序,然后生成已签名的apk(aab),所有三个SHA(调试、发布和应用程序签名密钥)都保存在我的firebase项目指纹下。 我还检查了firebase数据库规则。 我在帖子中更改了一些变量。从公共课到私人课
我直接在设备上下载了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]
} //[课程结束]
这就是我在活动中获得形象的方式
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);
# 1 楼答案
经过两天的搜索,我找到了问题的答案: 造成这个问题的是Proguard。创建签名的APK时,Proguard会清除所有未使用的代码或类。。就我的情况而言,这是一篇博文。Proguard错误地删除了类:
解决方案:
我把它放在柱子上。类和其他类,我希望确保Proguard不会在一个包(模型)下删除它们,您可以将它们放在不同的包下,但您需要在Proguard规则下列出所有这些类,如下所示:
在5月份的android studio项目中,我打开了proguard rules。pro
当Proguard创建签名的APK(或aab)时,我将下面的一行放在列表中,并防止类被删除
在哪里。领域app是包的名称
希望这能节省某人的时间