【问题标题】:Flutter iOS App crashes in Xcode, when adding FirebaseApp.configure() to implement Firebase integrationFlutter iOS App 在 Xcode 中崩溃,添加 FirebaseApp.configure() 以实现 Firebase 集成
【发布时间】:2020-03-13 20:07:41
【问题描述】:

我正在尝试按照步骤将 Firebase 连接到 Flutter 生成的 iOS 应用。

在最后一步中,将 FirebaseApp.configure() 行添加到 AppDelegate.swift 文件中时,应用程序构建正常,但随后在执行时崩溃,表明 Signal Abortion on线程 1... 线程 1:信号 SIGABRT

AppDelegate.swift 中的代码如下:

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    FirebaseApp.configure()
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    };
}

Xcode 提供的完整错误日志如下:

2019-11-18 07:11:34.664822-0500 Runner[82048:876634]  - <AppMeasurement>[I-ACS036002] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2019-11-18 07:11:34.849351-0500 Runner[82048:876630] 6.13.0 - [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
2019-11-18 07:11:34.860414-0500 Runner[82048:876433] *** Terminating app due to uncaught exception 'com.firebase.core', reason: '`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find a valid GoogleService-Info.plist in your project. Please download one from https://console.firebase.google.com/.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23c4f02e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50b97b20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23c4ee6c +[NSException raise:format:] + 188
    3   Runner                              0x00000001040bf51a +[FIRApp configure] + 138
    4   Runner                              0x00000001040baea4 $s6Runner11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtF + 212
    5   Runner                              0x00000001040bb1f4 $s6Runner11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtFTo + 212
    6   UIKitCore                           0x00007fff47846788 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 232
    7   UIKitCore                           0x00007fff47848197 -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 3980
    8   UIKitCore                           0x00007fff4784dce6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1281
    9   UIKitCore                           0x00007fff46f843c9 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 122
    10  UIKitCore                           0x00007fff47471be1 _UIScenePerformActionsWithLifecycleActionMask + 83
    11  UIKitCore                           0x00007fff46f84edb __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 198
    12  UIKitCore                           0x00007fff46f848ea -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 296
    13  UIKitCore                           0x00007fff46f84d08 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 818
    14  UIKitCore                           0x00007fff46f8459d -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 345
    15  UIKitCore                           0x00007fff46f88bcb __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke_2 + 178
    16  UIKitCore                           0x00007fff4739769b +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 865
    17  UIKitCore                           0x00007fff4749051f _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 240
    18  UIKitCore                           0x00007fff46f888e6 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 153
    19  UIKitCore                           0x00007fff47490422 _UISceneSettingsDiffActionPerformActionsWithDelayForTransitionContext + 84
    20  UIKitCore                           0x00007fff46f88754 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 381
    21  UIKitCore                           0x00007fff46ddf123 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 657
    22  UIKitCore                           0x00007fff46dddca8 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 248
    23  UIKitCore                           0x00007fff46ddee4d -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 210
    24  UIKitCore                           0x00007fff4784c343 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 535
    25  UIKitCore                           0x00007fff473b920d -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
    26  FrontBoardServices                  0x00007fff36555225 -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 442
    27  FrontBoardServices                  0x00007fff3657b598 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 + 102
    28  FrontBoardServices                  0x00007fff3655fd05 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220
    29  FrontBoardServices                  0x00007fff3657b229 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 355
    30  libdispatch.dylib                   0x00000001070ebd48 _dispatch_client_callout + 8
    31  libdispatch.dylib                   0x00000001070eecb9 _dispatch_block_invoke_direct + 300
    32  FrontBoardServices                  0x00007fff365a143e __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    33  FrontBoardServices                  0x00007fff365a112c -[FBSSerialQueue _queue_performNextIfPossible] + 441
    34  FrontBoardServices                  0x00007fff365a163b -[FBSSerialQueue _performNextFromRunLoopSource] + 22
    35  CoreFoundation                      0x00007fff23bb2221 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    36  CoreFoundation                      0x00007fff23bb214c __CFRunLoopDoSource0 + 76
    37  CoreFoundation                      0x00007fff23bb1924 __CFRunLoopDoSources0 + 180
    38  CoreFoundation                      0x00007fff23bac62f __CFRunLoopRun + 1263
    39  CoreFoundation                      0x00007fff23babe16 CFRunLoopRunSpecific + 438
    40  GraphicsServices                    0x00007fff38438bb0 GSEventRunModal + 65
    41  UIKitCore                           0x00007fff4784fb48 UIApplicationMain + 1621
    42  Runner                              0x00000001040bb45b main + 75
    43  libdyld.dylib                       0x00007fff51a1dc25 start + 1
    44  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

上面的错误日志中很有趣的一行:

由于未捕获的异常“com.firebase.core”而终止应用,原因:“[FIRApp configure];(Swift 中为FirebaseApp.configure()在您的项目中找不到有效的 GoogleService-Info.plist .请从https://console.firebase.google.com/下载一个。'

所以... 该消息清楚地表明 GoogleService-Info.plist 可能存在一些问题,就像它不存在一样......除了它确实存在,从 Firebase 新下载,它位于在正确的文件夹中,我已经彻底检查了 plist 的内容,以验证 Bundle ID、Team ID 和所有其他信息是否正确...

有人可以提出一些建议来解决这个问题吗?

谢谢

【问题讨论】:

  • 您是否确保 GoogleService-Info.plist 包含在您的目标中?
  • 是的!感谢您的评论...确实,阅读该错误消息,这是人们会想到的第一件事...但是,GoogleService-Info.plist 确实存在,是从 Firebase 新下载的,它位于正确的文件夹中,并且我已经彻底检查了 plist 的内容,以验证 Bundle ID、Team ID 和所有其他信息是否正确......这就是我认为这个问题有点奇怪的原因,也是我想问的原因这里的社区......
  • 此错误通常发生在文件不包含在目标中时。只是将文件放在项目中的正确位置并不意味着它包含在您的目标中。
  • 非常感谢你,安德鲁。你的评论确实很有价值。如果您愿意帮助我更好地理解,如何确保该文件包含在目标中?我对 Xcode 完全陌生,在我熟悉的 AndroidStudio 中似乎不会发生这样的事情......

标签: ios swift xcode firebase flutter


【解决方案1】:

当我尝试将 FirebaseApp.configure() 语句添加到我的 AppDelegate.swift 文件时,项目将不再构建。所以我删除了这些语句并继续使用 Firebase/Analytics 设置。我的应用最终能够在没有该声明的情况下与 Firebase 服务器通信。看起来firebase插件必须为我们做这件事。我将 firebase_core 和 firebase_analytics 添加到我的 pubspec.yaml 中:

  firebase_core: ^0.4.0+9
  firebase_analytics:

【讨论】:

    【解决方案2】:

    要检查您是否已将文件包含在目标中,请执行以下操作

    1. 单击您正在检查的文件
    2. 点击文件检查器
    3. 检查文件是否包含在所需的目标中。大多数应用只有一个目标。

    【讨论】:

    • 先生。安德鲁,我最诚挚地感谢您的好意,花时间详细说明这个美丽的简单的 1、2、3 步说明图......谢谢!您的解决方案确实指出了问题所在...主要是,我做错的是我正在使用 Finder 将 GoogleService-Info.plist 粘贴到项目中...而且事实证明,它不是在 Xcode 中甚至不可见...所以,我必须通过 Xcode 添加文件,而不是复制/粘贴,而是专门使用下拉菜单将文件添加到项目中,然后它工作正常...再次,谢谢! !!
    • 这就像当您了解一个有趣的谜语的答案时...回想起来似乎很明显...但是,作为 Xcode 的新手,我真的不知道必须添加文件,只使用程序的内部功能...
    • 相比之下,在使用AndroidStudio时,如果你只是将一个文件复制粘贴到文件夹中,然后你打开项目,系统就会选择你的文件,它是可见的和功能的,你不需要验证目标或类似的东西......
    • 猜我只是变得有点懒惰,太习惯于 AndroidStudio 的编程风格,我觉得这很简单,直观且直接......可能,如果我有我的方式,我永远不会选择为 iOS 编程,我会非常乐意单独为 Android 提供......但是,正如目前所发生的那样,当您开发应用程序时,您的客户强烈要求您也提供 iOS 版本,就像它是一种生活或者死亡命令...这就是我学习 Flutter 和学习 Xcode 有趣的晦涩(对我而言)方式的原因...再次,Andrew 先生,非常感谢您!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 2019-12-05
    • 1970-01-01
    • 2021-10-09
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多