firebase_storage/unauthenticated User is unauthenticated. Authenticate and try again error even in the release build

I'm using firebase_storage and firebase_app_check. I get the error in the following code.

await FirebaseAuth.instance.signInWithEmailAndPassword(email: '[email protected]', password: '********');
FirebaseStorage.instance.ref('images/foo.png').putFile(file)

[firebase_storage/unauthenticated] User is unauthenticated. Authenticate and try again.

I've added the debug secret token to the console and the debug version of the app works fine, however, if I run the release version of the app on a physical Android device I get the error. Why is that so?

AppCheck Settings:

enter image description here

Project Settings

I've uploaded both debug and release certificates on the Firebase Project Settings page.

enter image description here


Solution 1:

One more time thanks to the Docs for not providing enough information.

For release mode, in my build.gradle(app):

implementation 'com.google.firebase:firebase-appcheck-safetynet:16.0.0-beta04'

I also need to add in my MainActivity.java:

FirebaseApp.initializeApp(this);
FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance();
firebaseAppCheck.installAppCheckProviderFactory(SafetyNetAppCheckProviderFactory.getInstance());