c# – Unity Firebase中的InitializationException

前端之家收集整理的这篇文章主要介绍了c# – Unity Firebase中的InitializationException前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的Unity项目中的Firebase存在问题. Firebase SDK已在项目中导入,已构建,在此过程中没有错误.

SHA-1密钥是使用keytool生成的,并添加到控制台中的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可能使用的所有aars和jar,首先重新导入Firebase,然后选择性地重新导入Admob.
主要规则是不允许Admob覆盖Firebase使用的任何文件,例如“play-services-blah-blah.aar”.

这篇文章的主要建议是不要急于导入插件:导入一个,配置,构建,检查它是否有效(10次),提交,导入秒等等.这样你就可以清楚地看到第三方之间有混淆.

如果你已经陷入困境,你最好删除所有第三方并从头开始.

因此,请小心使用与下图中类似的文件.

希望这可以帮助人们预防我们遇到的问题.

猜你在找的C#相关文章