Skip to content

[Bug] FirebaseAuth anonymous sign-in fails after Application.Unload() on Android #1417

Open

Description

@NicolasDebeurme

Description

Description:
After signing in anonymously and querying Firestore, calling Application.Unload() prevents subsequent sign-ins.

Expected vs Actual:
Expected: sign in successfully after unload.
Actual: user stays nul

What i've tried:
Calling Dispose() on FirebaseApp or FirebaseAuth before Application.Unload() does not allow a successful re-sign-in.

Reproducing the issue

Sign In Anonymously → works.
Query Firestore Document → works.
Application.Unload().
ReOpen the app.
Try Sign In Anonymously again → user remains null (stuck in the Task & no error thrown)

Firebase Unity SDK Version

Tested on 13.9.0 and 12.10.1

Unity editor version

6000.0.59f2

Installation Method

.unitypackage

Problematic Firebase Component(s)

Authentication

Other Firebase Component(s) in use

Firestore

Additional SDKs you are using

I am using the .tgz files.

Targeted Platform(s)

Android

Unity editor platform

Windows

Scripting Runtime

IL2CPP

Release Distribution Type

Open-source from this repo

Relevant Log Output

16:39:41.878  I  [FIREBASE_DEBUG] Start() - Firebase will not sign in automatically.
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
16:39:44.958  I  [FIREBASE_DEBUG] Button: Sign In
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:OnGUI()
16:39:44.958  W  [FIREBASE_DEBUG] Auth is null, initializing Firebase...
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:SignInAnonymously()
                 DebugSceneController:OnGUI()
16:39:44.959  I  [FIREBASE_DEBUG] InitializeFirebase() called
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:InitializeFirebase()
                 DebugSceneController:SignInAnonymously()
                 DebugSceneController:OnGUI()
16:39:45.020  I  [FIREBASE_DEBUG] Firebase initialized. App name: __FIRAPP_DEFAULT
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:SignInAnonymously()
                 DebugSceneController:OnGUI()
16:39:45.021  I  [FIREBASE_DEBUG] Starting anonymous sign-in...
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:SignInAnonymously()
                 DebugSceneController:OnGUI()
16:39:45.272  I  [FIREBASE_DEBUG] User signed in: IyjqQUO6yLdBHz5jmyzVE42C2TK2
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:<SignInAnonymously>b__8_0(Task`1)
                 Firebase.Extensions.<>c__DisplayClass4_1`1:<ContinueWithOnMainThread>b__1()
                 Firebase.<>c__DisplayClass5_0`1:<RunAsync>b__0()
                 Firebase.ExceptionAggregator:Wrap(Action)
                 Firebase.Dispatcher:PollJobs()
                 Firebase.Platform.FirebaseHandler:Update()
16:40:00.376  I  [FIREBASE_DEBUG] Button: Query Firestore Document
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:OnGUI()
16:40:00.377  I  [FIREBASE_DEBUG] Running Firestore test query document...
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:QueryTestFirestore()
                 DebugSceneController:OnGUI()
16:40:00.714  I  [FIREBASE_DEBUG] Firestore query success. Document exists: True
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 <>c:<QueryTestFirestore>b__9_0(Task`1)
                 Firebase.Extensions.<>c__DisplayClass4_1`1:<ContinueWithOnMainThread>b__1()
                 Firebase.<>c__DisplayClass5_0`1:<RunAsync>b__0()
                 Firebase.ExceptionAggregator:Wrap(Action)
                 Firebase.Dispatcher:PollJobs()
                 Firebase.Platform.FirebaseHandler:Update()
16:40:10.243  I  [FIREBASE_DEBUG] Button: Application.Unload()
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:OnGUI()
16:40:14.746  I  [FIREBASE_DEBUG] Start() - Firebase will not sign in automatically.
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
16:40:20.196  I  [FIREBASE_DEBUG] Button: Sign In
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:OnGUI()
16:40:20.196  W  [FIREBASE_DEBUG] Auth is null, initializing Firebase...
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:SignInAnonymously()
                 DebugSceneController:OnGUI()
16:40:20.197  I  [FIREBASE_DEBUG] InitializeFirebase() called
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:InitializeFirebase()
                 DebugSceneController:SignInAnonymously()
                 DebugSceneController:OnGUI()
16:40:20.198  I  [FIREBASE_DEBUG] Firebase initialized. App name: __FIRAPP_DEFAULT
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:SignInAnonymously()
                 DebugSceneController:OnGUI()
16:40:20.199  I  [FIREBASE_DEBUG] Starting anonymous sign-in...
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:SignInAnonymously()
                 DebugSceneController:OnGUI()
16:40:38.624  I  [FIREBASE_DEBUG] Button: Query Firestore Document
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:OnGUI()
16:40:38.624  W  [FIREBASE_DEBUG] Cannot query Firestore: user not signed in
                 UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
                 DebugSceneController:OnGUI()

If using CocoaPods for Apple platforms, the project's Podfile.lock

Expand Podfile.lock snippet
👀 Replace this line with the contents of your Podfile.lock!

Activity

  1. niccolo-hare commented on Mar 25, 2026

    @niccolo-hare

    Hi @NicolasDebeurme, thanks for bringing this to our attention, and sorry for the wait. I tried setting up a sample app, but I couldn't reproduce the issue you encountered.

    To test this, I used our quickstart project for Firebase Firestore (here) then added some code to allow me to sign-in anonymously via Firebase Authentication and to unload the application from memory (Application.Unload). Though I did force-stop the application from the device's Settings before launching it again, and I was able to sign-in anonymously after.

    I think I might be missing some detail here to correctly reproduce the behavior you encountered. Could you share a code snippet or MCVE to help me investigate this further? In particular, I'm curious about how you implemented the Dispose() and Unload() functions.

    Let me know how it goes. Thanks.

  2. NicolasDebeurme commented on Mar 26, 2026

    @NicolasDebeurme
    Author

    Hi, thanks for your answer!

    In your test, you mentioned:

    "I did force-stop the application from the device's Settings before launching it again"

    This fully kills the Android process right ?

    However, my issue occurs specifically when using:

    • Application.Unload() in Unity
    • WITHOUT killing the Android process
    • relaunching the unKilled process

    Here is the method called when the unload action is performed:

    private void UnloadAction()
        {
            Debug.Log($"{LOG_TAG} Button: Application.Unload()");
            auth.SignOut();
            user = null;
            auth = null;
            app.Dispose();
            app = null;
            Application.Unload();
        } 

    Here is the method called to initialized called when trying to signInAnonymously is FirebaseApp is null:

        private void InitializeFirebase()
        {
            if (app != null)
            {
                Debug.LogWarning($"{LOG_TAG} InitializeFirebase skipped (app already exists)");
                return;
            }
    
            Debug.Log($"{LOG_TAG} InitializeFirebase() called");
    
            FirebaseApp.LogLevel = LogLevel.Verbose;
    
            app = FirebaseApp.Create(DebugAppOptions.ConnectionOptions);
            auth = FirebaseAuth.GetAuth(app);
            firestore = FirebaseFirestore.GetInstance(app);
    
            Debug.Log($"{LOG_TAG} Firebase initialized. App name: {app.Name}");
        }

    After reloading:

    FirebaseApp is recreated successfully
    FirebaseAuth is non-null
    BUT SignInAnonymouslyAsync() never completes (no success, no error, no cancel)

    This does not happen if the app is force-stopped, only when staying in the same process.

    Let me know if this lifecycle (Unity unload/reload without process restart) is officially unsupported, or if there is a recommended way to fully reset Firebase in this scenario.

    Thanks!

  3. niccolo-hare commented on Mar 26, 2026

    @niccolo-hare

    Hi @NicolasDebeurme, thanks for sharing your sample code. I noticed that some of this is code used to initialize the Firebase Admin SDK for C#, in particular this line:
    app = FirebaseApp.Create(DebugAppOptions.ConnectionOptions);

    So it looks you're trying to unload then re-initialize the Admin SDK on a server environment, instead of the client app SDK. Could you confirm my understanding of your use-case correct?

    Otherwise, the above code may not be the most recommended method for client app implementations. In addition, I don't think it's necessary to manually remove Firebase app from memory through Dispose(). For additional guidance on this, I would suggest checking the Get Started guides for Auth and Firestore (here and here). And if you need a code example, you could try checking the quickstart app for Auth and Firestore as well, or you may use them as the base for your app during development.

  4. google-oss-bot commented on Apr 2, 2026

    @google-oss-bot

    Hey @NicolasDebeurme. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

    If you have more information that will help us get to the bottom of this, just add a comment!

  5. guerwan commented on Apr 3, 2026

    @guerwan

    Hello @niccolo-hare we are still facing the issue but we need more time to investigate.

  6. niccolo-hare commented on Apr 3, 2026

    @niccolo-hare

    Hi @guerwan. No worries, we can keep this issue open for now while you investigate. Though I would like to note that the issue automatically closes when it becomes stale. But feel free to reach back out anytime, even if this is closed, and we can re-open it to take another look.

  7. google-oss-bot commented on Apr 9, 2026

    @google-oss-bot

    Hey @NicolasDebeurme. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

    If you have more information that will help us get to the bottom of this, just add a comment!

  8. guerwan commented on Apr 10, 2026

    @guerwan

    Hey @niccolo-hare here is a sample project you can use to reproduce the issue: https://drive.google.com/drive/folders/1W9eR8VFfwckpBEQagsuVzkLqAhummCbB?usp=sharing
    It includes a README with instructions on how to reproduce the issue.

  9. google-oss-bot commented on Apr 16, 2026

    @google-oss-bot

    Hey @NicolasDebeurme. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

    If you have more information that will help us get to the bottom of this, just add a comment!

  10. niccolo-hare commented on Apr 16, 2026

    @niccolo-hare

    Hi @guerwan, sorry for the confusion. Just wanted to let you know that I was able to download your sample and that I'm still investigating this. I'll update you as soon as I have more information or if I have additional questions for you.

  11. niccolo-hare commented on Apr 17, 2026

    @niccolo-hare

    Hi @guerwan, thanks for sharing your sample project. I tried it a few times and the SignInAnonymouslyAsync call does seem to just stop working or giving a response after unloading the app. There doesn't seem to be any errors in the logs based on my initial testing, but I did receive one error after I enabled verbose logging via the following code:
    Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;

    The error message I received was:

    Failed to get service from broker. 
    java.lang.SecurityException: Unknown calling package name 'com.google.android.gms'.
    

    It looks like this error may be related to some issue with the Google service broker and might possibly have been caused by unloading the app. With that, I've raised this to our engineers to confirm whether this is expected behavior or if it's a bug on the SDK. I'll update you again once I receive a response.

    Let me know if you have any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy