Unity Firebase is not initializing on Android

笑着哭i 提交于 2021-02-20 03:51:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!