'Android - Firebase - TaskSnapshot - Method should only be accessed within private scope?

Everything was working great... until I came back to work from a 3 month break and updated my Firebase from 9.8 to 10.0.1

Now all of my calls to TaskSnapshot are giving me an error.

Here is the example code that worked fine before:

OnSuccessListener<UploadTask.TaskSnapshot> successListener = new OnSuccessListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
        attachments.add(fileName + "*-*" + taskSnapshot.getDownloadUrl().toString());

        numberOfCallbacks++;
        if (numberOfFiles == numberOfCallbacks) {
            currentUpload = false;
            onClickSendAlert(sendingView);
        }
    }
};

The error that I now get is regarding taskSnapshot.getDownloadUrl().

Android Studio underlines that line in red and says:

This method should only be accessed from tests or within private scope

Can someone explain why this is happening? I have been researching all day for two days straight now and can't for the life of me figure this out (embarrassing).

For what it's worth, this code is used to upload a file to Firebase Storage, then when it is complete (OnSuccess), it gets the download URL and stores it in the Firebase Database. This worked great before I updated to 10.0.1. I get the same error on my download tasks in another module.

Here is a screenshot to give you a better visual of my situation:

enter image description here



Solution 1:[1]

I was stuck in the same issue and suppressWarnings didn't work for me. To get the complete download Uri i used the following code:

ref.putFile(imagePath).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                @Override
                public void onSuccess(Uri uri) {
                     Log.d("URL", uri.toString());
                    // This is the complete uri, you can store it to realtime database
                }
            });
        }
    });

Hope this helps someone.

Solution 2:[2]

I had the same problem and it was gone when I have updated my Firebase version. I was using 10.0.1 and now I am using 11.0.0

Solution 3:[3]

Use

@VisibleForTesting
internal val something

or

@VisibleForTesting
internal fun foo()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shivam Pokhriyal
Solution 2 Mazen Ebeid
Solution 3 Adam Kis