我在我的Unity项目中遇到了Firebase的问题。Firebase SDK已经导入到项目中,并且构建过程中没有出现任何错误。
使用keytool生成了SHA-1密钥,并添加到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设置教程一步一步进行了操作,但这个错误已经困扰我一个星期了!