'FABException', reason: '[Fabric] Value of Info.plist key "Fabric" must be a NSDictionary.' when using Firebase and Crashlytics
Asked Answered
F

6

26

I have a rather peculiar scenario when working with Firebase in our app. Without adding Crashlytics and Fabric to the project, when I run unit tests for the project the following code is hit:

@try {
        [FIRApp configure];
} @catch (NSException *exception) {
        DLog(@"**** Unable to configure Firebase due to exception %@", exception.description);
}

When debugging the unit tests an exception isn't raised and so I assume firebase is configured and all is Working. Tests pass and there are no issues.

I then very simply just add Crashlytics with Fabric to the project. I add this as a run script to my build phases "${PODS_ROOT}/Fabric/run" for the project and then run unit tests again. The unit tests fail and I get:

Terminating app due to uncaught exception 'FABException', reason: '[Fabric] Value of Info.plist key "Fabric" must be a NSDictionary.'

as an error, when I run the project however everything is fine. The issue only arises when running tests. I have tried the following:

  1. Add Crashlytics and Fabric to the project target and I get the same error.
  2. I do step 1 and also to the unit tests target and I still get the same error.
  3. I do step 2 and then I also add Firebase Core to the unit tests target and I still get the same error.
  4. I do step 3 and then also add "${PODS_ROOT}/Fabric/run" to a run script but on the unit tests target and still get the same error.

I think Firebase isn't being initialized correctly and this in turn causes Fabric to not be initialized correctly and hence the failure. But I'm not to sure how to fix the issue. Any guidance and suggestions would be appreciated.

Farnese answered 10/5, 2018 at 13:42 Comment(3)
Are not you following the Firebase Crashlytics documentation? There is a mistake in configuring the Fabric.Brownout
@Brownout he is following the documentation. I got around this issue by removing the pod 'Fabric' and 'Crashlytics' from the test target. However, i'm also interested in a better solution.Infanticide
Can you recreate the situation in a newly created project?Prescind
K
10

I just check one thing. If you registered your app in Firebase console, your AppDelegate.swift file should have Firebase.configure() code in didFinishLaunchingWithOptions function.

like this.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    print("[caution] : didFinishLaunchingWithOptions")
    FirebaseApp.configure()
    Messaging.messaging().delegate = self
    Fabric.with([Crashlytics.self])
    return true
}

I suffered the same problem. I just add that code and problem solved. I wish you too.

Karlie answered 11/6, 2018 at 2:32 Comment(1)
The key here is to call FirebaseApp.configure() first so it gets configured with the info from the GoogleService-Info.plist. Then you can safely remove the [Fabric] keys from the Info.plist.Grew
T
10

change this configuration:

def main_pods
    pod 'Fabric'
    pod 'Crashlytics'
    pod 'Firebase/Core'
end

target 'TargetName' do
    project 'Project.xcodeproj'
    main_pods
end

target 'OneMoreTargetName' do
    project 'Project.xcodeproj'
    main_pods
end

target 'TargetNameTests' do
    project 'Project.xcodeproj'
    main_pods
end

target 'TargetNameSwiftTests' do
    project 'Project.xcodeproj'
    main_pods
end

target 'TargetNameUITests' do
    project 'Project.xcodeproj'
    main_pods

    pod 'Utils', '~> 0.3.3'
    pod 'Pod', '~> 1.4.1'
end

to this:

def main_pods
    pod 'Fabric'
    pod 'Crashlytics'
    pod 'Firebase/Core'
end

target 'TargetName' do
    project 'Project.xcodeproj'
    main_pods

    # Move tests inside target block
    target 'TargetNameTests' do
        inherit! :search_paths # add custom flag
    end

    target 'TargetNameSwiftTests' do
        inherit! :search_paths # add custom flag
    end

    target 'TargetNameUITests' do
        inherit! :search_paths # add custom flag

        pod 'Utils', '~> 0.3.3'
        pod 'Pod', '~> 1.4.1'
    end
end

target 'OneMoreTargetName' do
    project 'Project.xcodeproj'
    main_pods
end
Tremain answered 5/10, 2018 at 9:56 Comment(1)
link to inherit! :search_paths description #37060565Tremain
D
2

I was upgrading Crashlytics and I've reproduced the error. In my case, the problem has been solved when I've removed the following code:

//[Fabric with:@[[Crashlytics class]]];
Diacid answered 20/2, 2019 at 7:56 Comment(0)
Q
1

The error message is quite straight forward.

Your Fabric keys in your Info.plist are in incorrect format.

It must be a dictionary as state in its document:

https://fabric.io/kits/ios/crashlytics/install

<key>Fabric</key>
    <dict>
        <key>APIKey</key>
        <string>YOUR_FABRIC_API_KEY</string>
        <key>Kits</key>
        <array>
            <dict>
                <key>KitInfo</key>
                <dict/>
                <key>KitName</key>
                <string>Crashlytics</string>
            </dict>
        </array>
    </dict>
Quita answered 10/5, 2018 at 13:48 Comment(6)
I shouldn’t need to do this for firebase implementations if I’m correct. I didn’t need to do this for my normal project target build. Why then should I be doing this for tests only?Farnese
you said: I then very simply just add Crashlytics with Fabric to the projectQuita
See the docs: firebase.google.com/docs/crashlytics/get-started nothing about configuring a plistFarnese
cool.. so don't know why are you questioning. I gave you the solution based on the error message. Glad you could handle it by yourselfQuita
No, I’ve followed everything in the guide and it’s still not working...Farnese
For my case even though I dont have FABRIC API KEY, just inserted my google api key and it worked. Thanks.Zloty
C
1

I had a project with a @testable import of the main target in the unit tests and when I include Fabric in the Podfile for the unit tests, it crashed with the aforementioned error message. But when I removed Fabric from the unit test target in the Podfile, then everything proceeded without incident.

Claudine answered 31/1, 2020 at 23:42 Comment(0)
A
0

Xcode 9

for my case I created the unit test target before firebase integration and before creating other non test targets. What worked for me is,

  1. delete the unit test target
  2. create a new one
Arnie answered 22/6, 2018 at 20:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.