0

I am using Firebase storage to save images/videos/ and audios. I have both API keys: debug and release. When I run the application on the phone everything works fine. However, when I generate the release apk, sometimes it works fine and other times it simply does not.

Any ideas of what might cause that?

FirebaseStorage storage = FirebaseStorage.getInstance();
        StorageReference storageRef = storage.getReferenceFromUrl("gs://manager-plus.appspot.com");
        StorageReference riversRef = storageRef.child("media/" + mediaDataList.get(i).name+SystemClock.elapsedRealtime());
        Uri uri;
        if (mediaDataList.get(i).type == 1)
            uri = Uri.fromFile(LoadBitmaps.saveBitmap(LoadBitmaps.decodeSampledBitmap(new File(mediaDataList.get(i).url), 100, 100)));
        else uri = Uri.fromFile(new File(mediaDataList.get(i).url));
        uploadTask = riversRef.putFile(uri);
        uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    Long size = Long.parseLong(mediaDataList.get(i).size) + Prefs.getInstance(getApplicationContext()).getSize();
                    if (Double.parseDouble(formatSize(size)) <= 2.0) {
                        Prefs.getInstance(getApplicationContext()).setSize(Long.parseLong(mediaDataList.get(i).size) + Prefs.getInstance(getApplicationContext()).getSize());
                        DataOnline dataOnline = new DataOnline();
                        dataOnline.link = String.valueOf(taskSnapshot.getDownloadUrl());
                        dataOnline.type = mediaDataList.get(i).type;
                        dataOnline.name= mediaDataList.get(i).name;
                        dataOnline.save();
                    } else {
                        Toast.makeText(getApplicationContext(), "Please subscribe to the paid version", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
                    }
                })
                .addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                        //calculating progress percentage
                        double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
                        build.setProgress(100, (int) progress, false);
                        notificationManager.notify(101, build.build());
                    }
                });

Thanks,

Miriana Itani
  • 865
  • 9
  • 25
  • You should provide more information to your statement "sometimes it works fine and other times it simply does not", what exceptions are you getting? – riggaroo Dec 31 '16 at 09:18
  • I am not getting any exceptions. I am running the application from android studio everything works perfectly. I can upload and preview everything on the cloud. However, when I generate the signed apk, if I upload something on the cloud, it uploads and I could see it in the storage section, But when I try to preview it through the app it does not show. – Miriana Itani Dec 31 '16 at 09:21
  • Show your code, How you are managing nodes for retrieving data – Rahul Dec 31 '16 at 09:23
  • @Rasi I am saving the download link locally once the media is successfully uploaded – Miriana Itani Dec 31 '16 at 09:25
  • Is there any information in the logs? – riggaroo Dec 31 '16 at 09:48
  • @riggaroo no. I think now it is not a firebase issue rather than a local database issue. Maybe sometimes the link is not being saved locally; therefore it is not showing in the UI. – Miriana Itani Dec 31 '16 at 09:58
  • Include your code in the question – riggaroo Dec 31 '16 at 09:58
  • @riggaroo code included – Miriana Itani Dec 31 '16 at 10:04
  • Perhaps check your Proguard config? I cant help much without logs of the error.. – riggaroo Dec 31 '16 at 12:45
  • @riggaroo what is progaurd config – Miriana Itani Dec 31 '16 at 12:57
  • Read here for more about Proguard - https://developer.android.com/studio/build/shrink-code.html and for firebase proguard rules see http://stackoverflow.com/questions/26273929/what-proguard-configuration-do-i-need-for-firebase-on-android – riggaroo Dec 31 '16 at 13:00
  • You said the *preview* function of your app is the thing that sometimes works and sometimes doesn't. Have you tried debugging that? What you're showing here is your upload code, which you say is not having a problem. – Doug Stevenson Jan 01 '17 at 02:35
  • @DougStevenson thank you so much. I figured it out, what was actually happening is that active android was actually not saving the data sometimes. That is why it was not appearing on the UI which is actually, so I changed the library from active android to sugar ORM> Thank you for your help – Miriana Itani Jan 01 '17 at 17:19
  • 1
    If you could answer your own question and accept it, that might be helpful for others. Thank you. – Doug Stevenson Jan 01 '17 at 20:44

1 Answers1

1

After so much debugging, it turned out that the problem was not due firebase; it was actually due to active-android. A library I was using to cache links locally.

Therefore, for anyone facing this problem: please first check : developer.android.com/studio/build/shrink-code.html

In my case I used sugar ORM instead of activeandroid, and my problem was solved.

Good luck

Miriana Itani
  • 865
  • 9
  • 25