【问题标题】:FirebaseApp.configure() crashes for unit test target单元测试目标的 FirebaseApp.configure() 崩溃
【发布时间】:2018-09-28 14:25:23
【问题描述】:

我遇到了一个奇怪的问题,FirebaseApp.configure() 调用导致我的应用程序立即崩溃,因为我的单元测试目标。它在我的标准构建中运行得很好。

任何想法为什么会发生这种情况?

这是堆栈跟踪:

2018-04-18 11:42:57.252405+0100 Avalanche[14289:124354] 4.8.1 - [Firebase/Analytics][I-ACS023007] Firebase Analytics v.40007000 started
2018-04-18 11:42:57.252454+0100 Avalanche[14289:124361] 4.8.1 - [Firebase/Core][I-COR000005] No app has been configured yet.
2018-04-18 11:42:57.252712+0100 Avalanche[14289:124354] 4.8.1 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://googl/RfcP7r)
2018-04-18 11:42:57.371588+0100 Avalanche[14289:124278] [Crashlytics] Version 3.9.3 (128)
2018-04-18 11:42:57.390507+0100 Avalanche[14289:124278] *** Terminating app due to uncaught exception 'FABException', reason: '[Fabric] Value of Info.plist key "Fabric" must be a NSDictionary.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000113c0a1e6 __exceptionPreprocess + 294
    1   libobjc.A.dylib                     0x000000011329f031 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000113c7f975 +[NSException raise:format:] + 197
    3   Avalanche                           0x000000010f654dec -[Fabric validFabricConfigFromInfoPlist:] + 353
    4   Avalanche                           0x000000010f654a16 -[Fabric fabricConfig] + 127
    5   Avalanche                           0x000000010f654bce -[Fabric APIKey] + 392
    6   Avalanche                           0x000000010f61e6d7 -[Crashlytics APIKey] + 55
    7   Avalanche                           0x000000010f62a087 -[CLSCrashReportingController APIKey] + 57
    8   Avalanche                           0x000000010f62977f -[CLSCrashReportingController startWithProfilingMark:betaToken:] + 257
    9   Avalanche                           0x000000010f61e088 __20-[Crashlytics start]_block_invoke + 637
    10  libdispatch.dylib                   0x0000000114b93779 _dispatch_client_callout + 8
    11  libdispatch.dylib                   0x0000000114b94c0a dispatch_once_f + 55
    12  Avalanche                           0x000000010f61de05 -[Crashlytics start] + 106
    13  Avalanche                           0x000000010f61e23a +[Crashlytics initializeIfNeeded] + 48
    14  Avalanche Tests                     0x0000000129cd440a __15+[Fabric with:]_block_invoke + 538
    15  libdispatch.dylib                   0x0000000114b93779 _dispatch_client_callout + 8
    16  libdispatch.dylib                   0x0000000114b94c0a dispatch_once_f + 55
    17  Avalanche Tests                     0x0000000129cd41ee +[Fabric with:] + 222
    18  Avalanche Tests                     0x0000000129cd5dea __14+[Fabric load]_block_invoke + 580
    19  Foundation                          0x0000000112cc0324 -[__NSObserver _doit:] + 298
    20  CoreFoundation                      0x0000000113ba5b8c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    21  CoreFoundation                      0x0000000113ba5a65 _CFXRegistrationPost + 453
    22  CoreFoundation                      0x0000000113ba57a1 ___CFXNotificationPost_block_invoke + 225
    23  CoreFoundation                      0x0000000113b67422 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
    24  CoreFoundation                      0x0000000113b665a1 _CFXNotificationPost + 609
    25  Foundation                          0x0000000112c80e57 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
    26  Avalanche                           0x000000010f6d41a7 +[FIRApp sendNotificationsToSDKs:] + 393
    27  Avalanche                           0x000000010f6d309e +[FIRApp configureDefaultAppWithOptions:sendingNotifications:] + 302
    28  Avalanche                           0x000000010f6d2eda +[FIRApp configure] + 380
    29  Avalanche                           0x000000010f609490 _T09Avalanche11AppDelegateCACycfc + 192
    30  Avalanche                           0x000000010f6094c3 _T09Avalanche11AppDelegateCACycfcTo + 19
    31  UIKit                               0x00000001109eb6c4 _UIApplicationMainPreparations + 1491
    32  UIKit                               0x00000001109eb087 UIApplicationMain + 111
    33  Avalanche                           0x000000010f60b447 main + 55
    34  libdyld.dylib                       0x0000000114c08955 start + 1
)
li

bc++abi.dylib:以 NSException 类型的未捕获异常终止

在崩溃之前,我还看到了大量的日志条目,例如:

objc[14289]: Class RCNKeyValue is implemented in both /Users/sammcneilly/Library/Developer/CoreSimulator/Devices/E62EC87E-0B07-4A83-A165-819E693AEB87/data/Containers/Bundle/Application/6C3F993F-4CEB-462F-9257-0F3C8E088BC0/Avalanche.app/Avalanche (0x10f7bdd50) and /Users/sammcneilly/Library/Developer/Xcode/DerivedData/Avalanche-ewiqmxxekhpknrhhfuyljlekgzat/Build/Products/Development-iphonesimulator/Avalanche.app/PlugIns/Avalanche Tests.xctest/Avalanche Tests (0x129e075d8). One of the two will be used. Which one is undefined.

我已经通过 CocoaPods 安装了 Firebase 和 Firebase/Crashlytics。 我不确定这是否与 Xcode 9.3 相关 - 这发生在两个单独的项目中,我相当确定以前的旧项目没有发生这种情况。

我已打印出捆绑包的内容,GoogleService-Info.plist 文件似乎在那里。

任何帮助将不胜感激!

【问题讨论】:

  • 您对Info.plist 文件的问题 --> [Fabric] Value of Info.plist key "Fabric" must be a NSDictionary.
  • 我认为这不是 Firebase (firebase.google.com/docs/crashlytics/get-started) 所必需的吗?此外,我不确定缺少该值将如何导致单元测试目标崩溃?

标签: ios swift firebase crashlytics xcode9.3


【解决方案1】:

好的,事实证明这是由错误配置的 Pod 文件引起的。 我的主要目标和单元测试目标配置为使用以下 pod:

pod 'Crashlytics', '~> 3.10.1'
pod 'Fabric', '~> 1.7.6'
pod 'Firebase/Core', '~> 4.8'
pod 'FirebaseRemoteConfig', '~> 2.1'

仅删除测试目标的额外 Firebase pod(Firebase/Core 除外)并再次运行 pod install 会有所帮助。

我不完全确定为什么这有效,所以如果有人可以向我解释这一点,我将不胜感激。

"${PODS_ROOT}/Fabric/run" 构建阶段脚本是在我的主要目标上配置的,详见 Google 文档:https://firebase.google.com/docs/crashlytics/get-started,将其添加到测试目标也无济于事...

感谢大家的意见,但手动将Fabric 详细信息添加到Info.plist 文件只会导致构建错误。我相信 Firebase 会自动处理此步骤。

【讨论】:

  • 非常感谢,从测试目标中删除 Crashlytics 和 Fabric 解决了它
【解决方案2】:

我们在运行 XCTest 时遇到了同样的崩溃。我们使用以下方法来解决它。

        if NSClassFromString("XCTest") != nil {
            return true
        } else {
            FirebaseApp.configure()
        }

【讨论】:

    【解决方案3】:

    将此代码放入info.plist中

    <key>Fabric</key>
        <dict>
            <key>APIKey</key>
            <string>YOUR APIKEY</string>
            <key>Kits</key>
            <array>
                <dict>
                    <key>KitInfo</key>
                    <dict/>
                    <key>KitName</key>
                    <string>Crashlytics</string>
                </dict>
            </array>
        </dict>
    

    希望对你有帮助!

    【讨论】:

    • 看起来 OP 通过 Firebase 使用 Fabric,它不提供 Fabric 密钥。
    猜你喜欢
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多