Ad

How To Retrieve Firebase Storage Images In Release Mode?

I use the following code to retrieve images from Firebase Storage using 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);
     }

This is the 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;
        }
    }

This is the part of the ImagesAdapter where I display the image in an ImageView using Picasso:

    @Override
    public void onBindViewHolder(@NonNull ImagesViewHolder holder, int position)
    {
        Picasso.get()
            .load(imagesList.get(position).toString())
            .fit()
            .into(holder.imagesImageView);
     }

Everything works fine when I run this code in the Debug mode. But, when I create a signed apk and run the app, it shows the following exception:

No setter/field for sharableImage found on class com.ksdfunapps.ksdstickersforchat.a

What is wrong with the code? This is the structure of Firebase database:

enter image description here

Ad

Answer

add proguard rules in proguard file than build your signed 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.** {
  *;
}

For more description see this link

Ad
source: stackoverflow.com
Ad