无法为 Unity IOS 配置 Firebase 应用

Posted

技术标签:

【中文标题】无法为 Unity IOS 配置 Firebase 应用【英文标题】:Unable to configure Firebase app for Unity IOS 【发布时间】:2020-05-12 04:01:29 【问题描述】:

我一直在四处寻找,找不到任何解决方案。我用 Unity 构建了我的 ios 项目,它编译得很好。我只是遇到了似乎根本无法解决的运行时错误。

当我使用 Unity 测试模式运行时,它运行良好,(没有错误和配置加载)。

当我在我的 IOS 设备上编译和运行时,我遇到了一堆运行时错误,我什至无法通过加载屏幕,因为 Firebase 无法加载。

顶部只是所有重复错误(不止两个,但我仅包括示例),底部是“无法配置 Firebase 应用”错误。

顺便说一句:我使用 IOS Project Builder 在 Windows 上构建我的项目,所以我手动添加和链接了框架。我无法快速添加 FirebaseApp.configure b/c。

Mon 11 23:48:33.974 RemoteConsole <stderr>: objc[11431]: Class FIRAnalyticsConnector is implemented in both /private/var/containers/Bundle/Application/0080BEB1-979B-48A5-AFE9-F25C7FD60E6D/cashcrates.app/cashcrates (0x10240a3b8) and /private/var/containers/Bundle/Application/0080BEB1-979B-48A5-AFE9-F25C7FD60E6D/cashcrates.app/Frameworks/UnityFramework.framework/UnityFramework (0x10624fd10). One of the two will be used. Which one is undefined.
Mon 11 23:48:33.974 RemoteConsole <stderr>: objc[11431]: Class FIRConnectorUtils is implemented in both /private/var/containers/Bundle/Application/0080BEB1-979B-48A5-AFE9-F25C7FD60E6D/cashcrates.app/cashcrates (0x10240a408) and /private/var/containers/Bundle/Application/0080BEB1-979B-48A5-AFE9-F25C7FD60E6D/cashcrates.app/Frameworks/UnityFramework.framework/UnityFramework (0x10624fd60). One of the two will be used. Which one is undefined.


Mon 11 23:48:34.115 RemoteConsole <stderr>: 2020-05-11 23:48:34.333 cashcrates[11431:2281069] Built from '2019.3/staging' branch, Version '2019.3.12f1 (84b23722532d)', Build type 'Release', Scripting Backend 'il2cpp'
Mon 11 23:48:34.193 RemoteConsole <stderr>: 2020-05-11 23:48:34.411 cashcrates[11431:2281069] GfxDevice: creating device client; threaded=1
Mon 11 23:48:34.193 RemoteConsole <stdout>: CrashReporter: initialized
Mon 11 23:48:34.193 RemoteConsole <stdout>: -> applicationDidFinishLaunching()
Mon 11 23:48:34.193 RemoteConsole <stdout>: -> applicationDidBecomeActive()
Mon 11 23:48:34.193 RemoteConsole <stdout>: GfxDevice: creating device client; threaded=1
Mon 11 23:48:34.236 RemoteConsole <stderr>: 2020-05-11 23:48:34.412 cashcrates[11431:2281069] Initializing Metal device caps: Apple A12 GPU
Mon 11 23:48:34.236 RemoteConsole <stderr>: 2020-05-11 23:48:34.413 cashcrates[11431:2281069] Initialize engine version: 2019.3.12f1 (84b23722532d)
Mon 11 23:48:34.236 RemoteConsole <stdout>: Initializing Metal device caps: Apple A12 GPU
Mon 11 23:48:34.236 RemoteConsole <stdout>: Initialize engine version: 2019.3.12f1 (84b23722532d)
Mon 11 23:48:34.334 RemoteConsole <stdout>: CrashReporter: No pending report exists at /var/mobile/Containers/Data/Application/5CC73465-87AF-475C-BE86-AE7993321E3B/Library/Caches/CrashReports/crash-pending.plcrash
Mon 11 23:48:34.334 RemoteConsole <stderr>: 2020-05-11 23:48:34.552 cashcrates[11431:2281069] CrashReporter: No pending report exists at /var/mobile/Containers/Data/Application/5CC73465-87AF-475C-BE86-AE7993321E3B/Library/Caches/CrashReports/crash-pending.plcrash
Mon 11 23:48:34.387 RemoteConsole <stderr>: 2020-05-11 23:48:34.576 cashcrates[11431:2281069] Unbalanced calls to begin/end appearance transitions for <SplashScreenController: 0x135d62c30>.
Mon 11 23:48:36.368 RemoteConsole <stdout>: UnloadTime: 2.304417 ms
Mon 11 23:48:36.368 RemoteConsole <stderr>: 2020-05-11 23:48:36.579 cashcrates[11431:2281069] UnloadTime: 2.304417 ms
Mon 11 23:48:36.413 RemoteConsole <stdout>: Fetching data...
Mon 11 23:48:36.413 RemoteConsole <stdout>: Config:FetchDataAsync()
Mon 11 23:48:36.413 RemoteConsole <stdout>: Config:Start()
Mon 11 23:48:36.413 RemoteConsole <stdout>: 
Mon 11 23:48:36.413 RemoteConsole <stdout>: (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
Mon 11 23:48:36.413 RemoteConsole <stdout>: 
Mon 11 23:48:36.413 RemoteConsole <stderr>: 2020-05-11 23:48:36.627 cashcrates[11431:2281069] Fetching data...
Mon 11 23:48:36.413 RemoteConsole <stderr>: Config:FetchDataAsync()
Mon 11 23:48:36.413 RemoteConsole <stderr>: Config:Start()
Mon 11 23:48:36.413 RemoteConsole <stderr>: 
Mon 11 23:48:36.413 RemoteConsole <stderr>: (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
Mon 11 23:48:36.413 RemoteConsole <stderr>: 
Mon 11 23:48:36.429 RemoteConsole <stderr>: 2020-05-11 23:48:36.641 cashcrates[11431:2281069] ERROR: Unable to configure Firebase app (The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized. One way to ensure that is to call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).)
Mon 11 23:48:36.429 RemoteConsole <stderr>: 2020-05-11 23:48:36.645 cashcrates[11431:2281069] Uploading Crash Report
Mon 11 23:48:36.429 RemoteConsole <stderr>: 2020-05-11 23:48:36.646 cashcrates[11431:2281069] InitializationException:  Firebase app creation failed.
Mon 11 23:48:36.429 RemoteConsole <stderr>:  at Firebase.FirebaseApp.CreateAndTrack (Firebase.FirebaseApp+CreateDelegate createDelegate, Firebase.FirebaseApp existingProxy) [0x00000] in <00000000000000000000000000000000>:0 
Mon 11 23:48:36.429 RemoteConsole <stderr>:   at Config.FetchDataAsync () [0x00000] in <00000000000000000000000000000000>:0 
Mon 11 23:48:36.429 RemoteConsole <stderr>:  at Config.Start () [0x00000] in <00000000000000000000000000000000>:0 
Mon 11 23:48:36.429 RemoteConsole <stderr>: 
Mon 11 23:48:36.429 RemoteConsole <stderr>: (Filename: currently not available on il2cpp Line: -1)
Mon 11 23:48:36.429 RemoteConsole <stderr>: 
Mon 11 23:48:36.429 RemoteConsole <stderr>: 2020-05-11 23:48:36.647 cashcrates[11431:2281069] Unable to configure Firebase app (The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized. One way to ensure that is to call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).)
Mon 11 23:48:36.429 RemoteConsole <stderr>: Firebase.AppUtil:PollCallbacks()
Mon 11 23:48:36.429 RemoteConsole <stderr>: Firebase.Platform.FirebaseHandler:Update()
Mon 11 23:48:36.429 RemoteConsole <stderr>: 
Mon 11 23:48:36.429 RemoteConsole <stderr>: (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
Mon 11 23:48:36.429 RemoteConsole <stderr>: 
Mon 11 23:48:36.457 RemoteConsole <stdout>: Uploading Crash Report
Mon 11 23:48:36.457 RemoteConsole <stdout>: InitializationException: Firebase app creation failed.
Mon 11 23:48:36.457 RemoteConsole <stdout>:   at Firebase.FirebaseApp.CreateAndTrack (Firebase.FirebaseApp+CreateDelegate createDelegate, Firebase.FirebaseApp existingProxy) [0x00000] in <00000000000000000000000000000000>:0 
Mon 11 23:48:36.457 RemoteConsole <stdout>:  at Config.FetchDataAsync () [0x00000] in <00000000000000000000000000000000>:0 
Mon 11 23:48:36.457 RemoteConsole <stdout>:   at Config.Start () [0x00000] in <00000000000000000000000000000000>:0 
Mon 11 23:48:36.457 RemoteConsole <stdout>:  
Mon 11 23:48:36.457 RemoteConsole <stdout>: (Filename: currently not available on il2cpp Line: -1)
Mon 11 23:48:36.457 RemoteConsole <stdout>: 
Mon 11 23:48:36.457 RemoteConsole <stdout>: Unable to configure Firebase app (The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized. One way to ensure that is to call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).)
Mon 11 23:48:36.457 RemoteConsole <stdout>: Firebase.AppUtil:PollCallbacks()
Mon 11 23:48:36.457 RemoteConsole <stdout>: Firebase.Platform.FirebaseHandler:Update()
Mon 11 23:48:36.457 RemoteConsole <stdout>:  
Mon 11 23:48:36.457 RemoteConsole <stdout>: (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)

【问题讨论】:

您找到解决方案了吗?我有同样的问题。适用于 Unity、Firebase 的 iOS 项目生成器,同样的“无法配置”错误,发生在我的任何脚本实际在我的测试应用程序中运行之前。我什至尝试使用 mechahamster 演示应用程序并遇到同样的问题。真的希望我不必在 Mac 上开发就可以使用 firebase,而实际上我编写的所有其他代码都可以通过 Windows 运行。 【参考方案1】:

如果您不能使用External Dependency Manager for Unity (EDM4U),这会有点棘手,但您的问题可能是您缺少 GoogleService-Info.plist。通常,这将作为 EDM4U 运行的一部分自动复制,但由于您要绕过它,因此您需要手动进行。配置步骤应该作为调用FirebaseApp.DefaultInstance(或初始化任何其他依赖它的单例)的一部分自动发生。

您可以尝试将文件放在Assets/StreamingAssets 下,看看是否可以修复它,否则您必须将其作为手动连接框架的一部分移动。如需重新下载,请查看this。

如果这不能解决问题,请确保您遵循了getting started guide for iOS(听起来您已经完成了)。不要害怕使用 CocoaPods,EDM4U literally does this。

另外,不要忽略统一包放在Assets/Plugins/iOS/Firebase 下的文件(例如:Assets/plugins/iOS/Firebase/libFirebaseCppApp.a)。我知道版本控制系统通常会排除 .a 文件,以避免跟踪构建工件。这些文件大致映射到 the C++ SDK,Firebase Unity SDK 使用它与底层框架进行通信。 C# 层主要使用SWIG 构建以生成正确的绑定,并进行了一些额外的工作以使其在 Unity 中使用更方便。

最后,虽然我认为从 Windows 生成 iOS 项目并没有进行广泛的测试,但我可以看到有一些需求。提交一个询问 here 的错误并概述到目前为止您必须制定的解决方法会很有帮助。此外,提交feature request 也是一种获得支持的好方法(这适用于任何找到此答案的人,而不仅仅是 OP - 噪音越大越好)。

如果有帮助,请告诉我!

--帕特里克

【讨论】:

谢谢,我尝试将它放在 Assets/StreamingAssets 中但没有运气,但似乎 Firebase 也无法找到 GoogleService-Info.plist 和我的证书,所以这可能只是原因。你知道我可以在哪里手动放置这些文件,因为 Asset 文件夹在编译后似乎不起作用。 IOS 通常会在哪里检查这些文件? 官方说明是把它移到你的XCode项目的根目录下(拖放到侧边栏——firebase.google.com/docs/ios/setup#add-config-file)。我做了一些实验,发现放在哪里似乎并不重要,只要 XCode 可以在项目中看到它(medium.com/firebase-developers/…).. 我到处都试过了,但仍然无法正常工作。我有 .xcodeproj 文件,所以我必须在 project.pbxproj 中写什么吗?那似乎是那里唯一的文件。 Tue 12 23:56:09.778 RemoteConsole &lt;stdout&gt;: cash-crates-14c93236a173 was not found. Also looked in /private/var/containers/Bundle/Application/CEF94124-1463-4A60-9059-B24AE71FD4DC/cashcrates.app/Data/Editor Default Resources/cash-crates-14c93236a173 我也可以在 Unity 中调用 FirebaseApp.configure() 吗? 哦,对了!我一直忘记你没有安装 XCode(对不起!)。您可以使用 postprocessbuild 挂钩 (docs.unity3d.com/ScriptReference/…) 来编辑生成的 XCode 项目。您需要创建一个新的 PBXProject (docs.unity3d.com/ScriptReference/iOS.Xcode.PBXProject-ctor.html),从 postprocessbuild 回调的路径中加载它(docs.unity3d.com/ScriptReference/… 和 docs.unity3d.com/ScriptReference/…) 添加文件 (docs.unity3d.com/ScriptReference/…) 并将其写回 (docs.unity3d.com/ScriptReference/…)。

以上是关于无法为 Unity IOS 配置 Firebase 应用的主要内容,如果未能解决你的问题,请参考以下文章

关于 Cocoapods 和 Firebase/Messaging 的 Unity iOS 构建错误

iOS 上的 Firebase 身份验证失败(Unity、Xcode)

Unity + Firebase + iOS = 错误

Unity 中的 Firebase / Google VR 链接器错误 - iOS

Firebase 和 Unity?

Firebase Analytics iOS/Unity 推送通知?