Async Firebase code works in-editor but not on any devices.

I’m running into a problem where my Async code works in editor, but not on a mobile device.

The code is as follows:

using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase;
using Firebase.Auth;

public class FirebaseAuthenicator : MonoBehaviour
{
    public async Task SignInAnon()
    {
        await FirestoreController.firebaseAuth.SignInAnonymouslyAsync().ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInAnonymouslyAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInAnonymouslyAsync encountered an error: " + task.Exception);
                return;
            }

            FirebaseUser anonUser = task.Result;
            Debug.Log("User Signed-In");
        });       
    }

    public void SignOut()
    {
        FirestoreController.firebaseAuth.SignOut();
        Debug.Log("User Signed-Out");
    }
}

No problems on device when run from this:

public async Task StartUp()
    {       
        await GetComponent<FirebaseAuthenicator>().SignInAnon();
        FirestoreSaveNLoad.Load(); //loads previous carts.
        await gameObject.GetComponent<AppUpdateChecker>().CheckForUpdates(); //checks loaded carts for updates.
        GameManager.browserAssets = ResourceLoaderUnloader.LoadAssetBundle("Browser", "all-organization-logos-cart-icons"); //loads the asset bundle for browser images after the update. 
        GameManager.currentUser.AppStarts++;

        if(GameManager.currentUser.AppStarts == 1)
        {
            Debug.Log("First launch logged");
            GameManager.currentUser.LaunchDate = DateTime.Now.ToString();
           
        }
        else
        {
            GameManager.currentUser.RecentDate = DateTime.Now.ToString();
        }

        //starts the main menu timer.
        gameObject.GetComponent<SceneTimer>().Timer.Stop();
        gameObject.GetComponent<SceneTimer>().Timer.Reset();
        gameObject.GetComponent<SceneTimer>().Timer.Start();

        if(GameManager.allCarts.Count > 0) //if there is at least one cart installed, go to the carousel screen.
        {
            gameObject.GetComponent<MakeCarousel>().CreateCarouselCarts();
            LocalProgressJSONManager.JSONM.AD.cartDownloaded = true;
            LocalProgressJSONManager.JSONM.Save();
        }
        else //otherwise start the browser.
        {
            gameObject.GetComponent<FirestoreOrgBrowser>().StartOrgBrowser();
        }

        FirestoreSaveNLoad.Save();
    }

However, when I run the function from a device. I get this null-exception error:

AndroidPlayer(samsung_SM-G960U@192.168.1.19) NullReferenceException: Object reference not set to an instance of an object.
at FirebaseAuthenicator+d__0.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0
at FirebaseAuthenicator.SignInAnon () [0x00000] in <00000000000000000000000000000000>:0
at AppStartUp+d__1.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0
at AppStartUp.StartUp () [0x00000] in <00000000000000000000000000000000>:0
at AppStartUp.Start () [0x00000] in <00000000000000000000000000000000>:0
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <00000000000000000000000000000000>:0
at AppStartUp+d__1.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0
at AppStartUp.StartUp () [0x00000] in <00000000000000000000000000000000>:0
at AppStartUp.Start () [0x00000] in <00000000000000000000000000000000>:0
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.UnitySynchronizationContext.ExecuteTasks () [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.WorkRequest:Invoke()
UnityEngine.UnitySynchronizationContext:Exec()
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

(Filename: currently not available on il2cpp Line: -1)

Any help would be much appreciated.

Since this works normally but not with your new-fangled async code, it certainly seems like an initialization error rather than a library binding error.

Are you sure that all of the things in line 14 of your async example have been initialized by the time this runs? To prove it, print each one of them out with Debug.Log() BEFORE you use them and watch for them to happen before your exception.

Problem solved. Apparently I installing the unity packages manually as told to by Google’s Firebase documentation wasn’t the best way to install it. The I ended up with 2 different versions of Firebase in the same app that caused the conflict. Installing it through the Package manager was the way. This also fixed the null exception as well.

but how you managed to delete the old ones

so let me post a fix here if you run a adb to test your device and use this to specifically test unity app on android
adb logcat -s Unity ActivityManager PackageManager dalvikvm DEBUG FirebaseApp
and then you notice in the log that it showed firebase must be launched before using any of its resources or something similar and then you see firebase has initiazed it means the issue is with how you initialized firebase in your script and not firebase itself. Do the check dependency and initialization in one script and then start any other command or script after it has been initialized e.g
void Start()
{
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
{
if (task.IsCompleted)
{
if (task.Result == DependencyStatus.Available)
{
FirebaseApp app = FirebaseApp.DefaultInstance;
FirebaseDatabase database = FirebaseDatabase.GetInstance(app, databaseUrl);
databaseReference = database.RootReference;

Debug.Log(“Firebase initialized successfully.”);

// Check if user is remembered
if (PlayerPrefs.HasKey(“RememberMe”) && PlayerPrefs.GetInt(“RememberMe”) == 1)
{
// Automatically log in the remembered user
string rememberedUsername = PlayerPrefs.GetString(“RememberedUsername”);
string rememberedPassword = PlayerPrefs.GetString(“RememberedPassword”);
StartCoroutine(LoginUser(rememberedUsername, rememberedPassword, true));
}

// Save the original position of the UI element
uiElement = GetComponent();
originalPosition = uiElement.localPosition;
}
else
{
Debug.LogError("Could not resolve all Firebase dependencies: " + task.Result);
}
}
else
{
Debug.LogError("Failed to check and fix Firebase dependencies: " + task.Exception);
}
});
}

after this line Debug.Log(“Firebase initialized successfully.”); you can do Initilizationconfirmationtext.text = “Firebase has completed initialization”; make sure you have a public Text Initilizationconfirmationtext; and the attach the text to it so when the app starts it should show the initialization completed and now you can test others and make sure this script has initialized before running other functions or else it wont work even if you do everything in the world. Do this and see the magic plus if this doesnt work use firebase 9.4.0, i will upgrade back to 12.0.0 later today after launching my app