c# - Unity Firebase 中的 InitializationException

标签 c# firebase unity3d firebase-analytics

我的 Unity 项目中的 Firebase 有问题。 Firebase SDK 导入到项目中,构建,在此过程中没有错误。

SHA-1 key 是使用 key 工具生成的,并添加到控制台中的 Firebase 项目中。

google-services.json 也被添加到 Assets 文件夹中。

初始化 Firebase 的简单脚本:

DependencyStatus dependencyStatus = DependencyStatus.UnavailableOther;
// Use this for initialization
void Start () 
{
    Debug.Log ("Start FireBase");
    dependencyStatus = FirebaseApp.CheckDependencies();

    if (dependencyStatus != DependencyStatus.Available) 
    {
        FirebaseApp.FixDependenciesAsync().ContinueWith(task => 
        {
            dependencyStatus = FirebaseApp.CheckDependencies();
            if (dependencyStatus == DependencyStatus.Available) 
            {
                InitializeFirebase();
            } 
            else 
            {
                Debug.LogError("Could not resolve all Firebase dependencies: " + dependencyStatus);
            }
        });
    } 
    else 
    {
        InitializeFirebase();
    }
}

void InitializeFirebase() 
{
    FirebaseAnalytic.Instance().setAnalyticsCollectionEnabled(true);
    FirebaseAnalytic.Instance().setUserProperty(FirebaseAnalytics.UserPropertySignUpMethod, "Google");
    FirebaseAnalytic.Instance().setUserId(SystemInfo.deviceUniqueIdentifier);
    FirebaseAnalytic.Instance().logEvent("LogIn", FirebaseAnalytics.EventLogin);
    Debug.Log ("FirebaseAnalytics Logined");
}

因此应用程序可以构建和运行而不会崩溃。但是通过 adb logcat -s Unity 我可以看到以下内容:

I/Unity   (27030): Start FireBase

I/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)
I/Unity   (27030):

I/Unity   (27030): Firebase App initializing app com.boldstatementproductions.mcpro (default 1).

I/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)
I/Unity   (27030):

W/Unity   (27030): Callback module already shut down

W/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

E/Unity   (27030): java_app

E/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

I/Unity   (27030): Firebase App initializing app com.boldstatementproductions.mcpro (default 1).

I/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

W/Unity   (27030): Callback module already shut down

W/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

E/Unity   (27030): java_app

E/Unity   (27030): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)

I/Unity   (27030): InitializationException: Failed to initialize the default Firebase App.

I/Unity   (27030):   at Firebase.FirebaseApp.CreateAndTrack (Firebase.CreateDelegate createDelegate) [0x00000] in <filename unknown>:0

I/Unity   (27030):   at Firebase.FirebaseApp.Create () [0x00000] in <filename unknown>:0

I/Unity   (27030):   at Firebase.FirebaseApp.get_DefaultInstance () [0x00000] in <filename unknown>:0

I/Unity   (27030):   at Firebase.Analytics.FirebaseAnalytics..cctor () [0x00000] in <filename unknown>:0

I/Unity   (27030): Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Firebase.Analytics.FirebaseAnalytics

I/Unity   (27030):   at FirebaseDependencyResolver.InitializeFirebase () [0x00000] in <filename unknown>:0

I/Unity   (27030):   at FirebaseDependencyResolver.Start () [0x00000] in <filename unknown>:0

I/Unity   (27030): (Filename:  Line: -1)

谷歌搜索任何这些消息都没有太大帮助。我错过了什么? 我逐步遵循了 Unity 的 Firebase 设置教程。这个错误已经让我害怕了一个星期!

最佳答案

因此,在第 1245321653214 次尝试重新导入 Firebase 并无论如何解决此问题后,我们发现之前的另一个插件 Admob 覆盖了 Firebase 使用的一些库。

我们删除了 Firebase 和 Admob 可能使用的所有 aar 和 jars,并首先重新导入 Firebase,然后有选择地重新导入 Admob。 主要规则不允许 Admob 覆盖 Firebase 使用的任何文件,例如“play-services-blah-blah.aar”。

这篇文章的主要建议是不要急于导入插件:导入一个,配置,构建,检查它是否工作(10 次),提交,导入第二个等等。这样你会清楚地看到第 3 方之间是否有冲突。

如果你已经陷入困境,你最好删除所有 3rd 方并从头开始。

因此,请务必小心处理与下图中类似的文件。

Be VEEERY careful with files similar to those

希望这有助于人们避免我们遇到的问题。

关于c# - Unity Firebase 中的 InitializationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43677353/

相关文章:

ios - 集成 Firebase SDK 后无法运行单元测试(Xcode 8GM,swift 3)

c# - Unity Hololens (UWP) 构建会生成 Standalone 构建不会产生的错误?

c# - Visual Studio 自动完成对 Unity 过于激进

c# - 多处理器机器中秒表的最佳实践?

firebase - 带有 VScode 的 Firebase 智能感知

javascript - 使用 AngularFire 和 AngularJS 登录 Firebase 后如何重定向到 URL?

c# - 如何从 child 到 parent 引用一个类(class)?

c# - Nest 版本 6.x 中的 InMemoryConnection Elasticsearch jsonSerializationException

c# - 在不同端口之间共享 Cookie

c# - 如何在 Enumerable.Distinct() 中使用 lambda 表达式