我使用以下代码通过Firebase Storage
从Firebase Database
检索图像:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference("images");
}
@Override
public void onStart()
{
super.onStart();
ValueEventListener listener = new ValueEventListener()
{
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
{
for (DataSnapshot singleImage: dataSnapshot.getChildren())
{
SharableImageClass sharableImage = singleImage.getValue(SharableImageClass.class);
imagesList.add(sharableImage.getSharableImage());
}
ImagesAdapter addapter = new ImagesAdapter(getActivity(), imagesList);
imagesRecyclerView.setAdapter(addapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
{
Toast.makeText(getActivity(), "Error.. Cannot connect to Internet", Toast.LENGTH_SHORT).show();
}
};
databaseReference.addValueEventListener(listener);
}
这是SharableImageClass.class:
public class SharableImageClass
{
public String sharableImage;
public SharableImageClass() {
}
public SharableImageClass(String sharableImage) {
this.sharableImage = sharableImage;
}
public String getSharableImage() {
return sharableImage;
}
public void setSharableImage(String sharableImage) {
this.sharableImage = sharableImage;
}
}
这是我使用Picasso在ImageView中显示图像的ImagesAdapter的一部分:
@Override
public void onBindViewHolder(@NonNull ImagesViewHolder holder, int position)
{
Picasso.get()
.load(imagesList.get(position).toString())
.fit()
.into(holder.imagesImageView);
}
当我在 Debug 模式下运行此代码时,一切正常。但是,当我创建一个签名的apk并运行该应用程序时,它显示以下异常:
在com.ksdfunapps.ksdstickersforchat.a类上找不到sharableImage的设置程序/字段。
代码有什么问题?这是Firebase数据库的结构:
答案 0 :(得分:0)
在proguard文件中添加proguard规则,而不是构建已签名的APK
# Add this global rule
-keepattributes Signature
# This rule will properly ProGuard all the model classes in
# the package com.yourcompany.models. Modify to fit the structure
# of your app.
-keepclassmembers class com.yourcompany.models.** {
*;
}
有关更多说明,请参见此link