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.