【问题标题】:FirebaseApp.configure() crashes app on launchFirebaseApp.configure() 在启动时使应用程序崩溃
【发布时间】:2020-04-14 10:57:14
【问题描述】:

我正在开发一个使用 Firebase 进行分析、崩溃分析和远程配置获取的 iOS 项目。对于依赖管理,我使用 cocoapods 并且项目中的 Firebase 的当前版本是最新的 - 6.22.0

这里的问题是,应用程序在每次新启动配置 Firebase 的代码行(ObjC -> [FIRApp configure];)时都会崩溃。我已经看过一些类似的帖子,但没有一个对我有帮助,除非我遗漏了什么。

项目的部分结构如下图所示。红色表示主要目标和应用程序的主要xcodeproj 文件。蓝色表示自定义框架的xcodeproj 文件,其中包含帮助程序,包括用于分析日志记录的FirebaseAnalytics 包装器,这意味着它具有其依赖关系pod Firebase/Analytics。此自定义框架用于以红色标记的主应用程序目标。 (pod install 之后我总是打开xcworkspace,所以这是在xcworkspace)。

下面是为Podfile 中的每个项目/目标定义的 pod。

target 'TheApp' do
    platform :ios, '11.0'
    project 'TheApp/TheApp.xcodeproj'
    use_frameworks!
    pod 'Firebase/Auth'
    pod 'Firebase/Core'
    pod 'Firebase/Messaging'
    pod 'Firebase/RemoteConfig'
end

target 'TheCustomFramework' do
    platform :ios, '11.0'
    project 'TheCustomFramework/TheCustomFramework.xcodeproj'
    use_frameworks!
    pod 'Firebase/Analytics'
end

我在应用程序委托中添加了 Firebase 配置方法,如 google 文档中所示。

另外,我在项目中添加了GoogleService-Info.plist 文件,如谷歌文档所述。

但是应用程序在 AppDelegate 中的 didFinishLaunchingWithOptions 方法调用的 Firebase 配置上不断崩溃。当我在卡住的跟踪中输入更深时,我在 Firebase 库中标有红色矩形的 364th 代码行上崩溃:

Xcode 控制台中此崩溃的异常消息是:

Terminating app due to uncaught exception 'com.firebase.installations', reason: '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).'

这可能是什么问题?感谢您的帮助和回答。

附言很抱歉发了这么长的帖子。

【问题讨论】:

  • 如果这是问题中的 Swift 标签所指示的 Swift 项目,而不是 ObjC。删除 [FIRApp configure]; 并将其替换为 FirebaseApp.configure()。然而,它看起来可能是屏幕截图中的 ObjC。将代码和结构包含为 文本 是一个好主意,而不是链接和图像。这样,如果答案中需要它们,可以复制和粘贴它们。最后,图片不可搜索,这可能会妨碍未来的读者找到问题。
  • 这不是一个 Swift 项目。有些代码是用 ObjC 编写的,有些是用 Swift 编写的。我已经更新了标签。
  • 您可能需要返回入门指南setup。您的 podfile 与文档不匹配不再需要 Firebase iOS 库 Firebase/Core。。我也没有看到@import Firebase;,看起来您有两个不同的目标/项目?如果您能进一步澄清,我们可能会提供帮助。
  • 我已将 Firebase/Core pods' from project and still getting the same result as before. Also, I added @import Firebase;` 删除到文件中。

标签: ios objective-c firebase crash config


【解决方案1】:

回答我自己的问题。我基本上通过从Podfile 中的每个项目/目标中删除Firebase/Core pod 并添加与主应用程序目标相关的所有Firebase 来解决这个问题,包括Firebase/Analytics pod(这意味着从所有其他项目/目标中删除它)。

在运行pod install 之后,我将所有使用 FirebaseAnalytics 的文件从自定义框架移至主项目(目标)。现在一切正常,调用[FIRApp configure]; 不会导致应用程序崩溃。

Podfile 现在看起来像这样:

target 'TheApp' do
    platform :ios, '11.0'
    project 'TheApp/TheApp.xcodeproj'
    use_frameworks!
    pod 'Firebase/Analytics'
    pod 'Firebase/Auth'
    pod 'Firebase/Messaging'
    pod 'Firebase/RemoteConfig'
end

target 'TheCustomFramework' do
    platform :ios, '11.0'
    project 'TheCustomFramework/TheCustomFramework.xcodeproj'
    use_frameworks!
end

【讨论】:

  • 太棒了。很高兴我的评论有帮助!
  • 谢谢兄弟。你做到了。
猜你喜欢
  • 2019-12-05
  • 2018-07-23
  • 2016-09-02
  • 1970-01-01
相关资源
最近更新 更多