Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase configuration fails - Swift

In my application I'm successfully using Firebase and in AppDelegate I do the setup:

// ### Initialize Firebase
FIRApp.configure()

Now I do some unit tests on related target and when I launch it I get errors:

2017-04-14 14:53:22.351 MyProject[28753] <Error> [Firebase/Core][I-COR000004] App with name __FIRAPP_DEFAULT does not exist.
2017-04-14 14:53:22.354 MyProject[28753] <Error> [Firebase/Messaging][I-IID001000] Firebase is not set up correctly. Sender ID is nil or empty.
2017-04-14 14:53:22.356 MyProject[28753] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.3800000 started
2017-04-14 14:53:22.356 MyProject[28753] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
2017-04-14 14:53:22.381 MyProject[28753:712475] *** Terminating app due to uncaught exception 'com.firebase.instanceid', reason: 'Could not configure Firebase InstanceID. Google Sender ID must not be nil or empty.'

Versions:

Firebase/Core (3.16.0)
Firebase/Messagging (3.16.0)

Any advice?

like image 628
Luca Davanzo Avatar asked Apr 14 '17 13:04

Luca Davanzo


2 Answers

I just noticed it's started happening to me and my travis builds are failing with Firebase 3.16. I downgraded to 3.7.1 which was the version I had previously on the project and it's working again.

I haven't had time to look into it more but it's a quick fix. It may be a Firebase bug or they might have changed something and the setup is different now.

Edit: Apparently rolling back to 3.15 works well enough.

like image 167
Michal Klein Avatar answered Oct 21 '22 16:10

Michal Klein


Beginning in Firebase 3.16.0, it seems Google Firebase isn't picking up the GoogleService-Info.plist from the unit test build, even if the plist is included in both the app and unit test targets. This doesn't seem to be resolved in 3.17.0. As others have noted, downgrading to 3.15.0 seems to sidestep the issue.

But for many, initialization of Firebase during unit tests may not be necessary, and actually unintended --for example, you probably don't want Firebase reporting on unit test crashes. In these scenarios, you can easily add a guard around FIRApp.configure() to not initialize it while running unit tests via the following:

import Foundation

func isUnitTesting() -> Bool {
    return ProcessInfo.processInfo.environment["TEST"] != nil
}

if !isUnitTesting() {
    FIRApp.configure()
}

Then be sure to define the environment variable TEST=1 only in your testing scheme.

like image 12
markshiz Avatar answered Oct 21 '22 16:10

markshiz