问题
I have a Firebase Unity project for Android. I'm currently using Unity 2019.3.1 and using Firebase SDK 6.15.2. Below is the code I used to connect to Firebase:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using Firebase;
using Firebase.Auth;
using Firebase.Firestore;
using Firebase.Extensions;
public class FirebaseManager : MonoBehaviour
{
public static FirebaseManager instance;
private FirebaseApp app;
private async void Awake()
{
if (instance == null)
{
DontDestroyOnLoad(gameObject);
instance = this;
var dependencyResult = await FirebaseApp.CheckAndFixDependenciesAsync();
if (dependencyResult == DependencyStatus.Available) app = FirebaseApp.DefaultInstance;
else Debug.LogError($"Failed to initialize Firebase with {dependencyResult}");
}
else Debug.LogWarning($"An instance of {nameof(FirebaseManager)} already exists!");
}
void Start()
{
Debug.Log("FirebaseManager.Start()");
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
{
var dependencyStatus = task.Result;
Debug.Log("var dependencyStatus = task.Result;");
if (dependencyStatus == DependencyStatus.Available) InitializeFirebase();
else Debug.LogError("Could not resolve all Firebase dependencies: " + dependencyStatus);
});
}
}
Firebase works on Unity. However, when I build the apk and tested it out, it did not go to Debug.Log("var dependencyStatus = task.Result;");
. I tried using many solutions found online such as using a different Unity version or the latest Firebase SDK or re-importing Firebase but none of them work.
Edit: It seems that the Start()
function ends at FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread
and will not go any further than that even if there is a Debug.Log after the function.
Am I doing something wrong or is there some other fix I have missed?
来源:https://stackoverflow.com/questions/63294408/unity-firebase-is-not-initializing-on-android