Skip to content

"app has not yet been configured" exception when calling FirebaseApp.configure() #5075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LeffelMania opened this issue Mar 11, 2020 · 4 comments

Comments

@LeffelMania
Copy link

LeffelMania commented Mar 11, 2020

Step 1: Describe your environment

  • Xcode version: 11.3.1 (11C504)
  • Firebase SDK version: 6.19.0
  • Firebase Component: Analytics
  • Component version: 6.3.1
  • Installation method: CocoaPods

Step 2: Describe the problem

After upgrading my pod 'Firebase/Analytics' from 6.13.0 to 6.19.0, calling FirebaseApp.configure() throws an exception stating that The default Firebase app has not yet been configured. Add [...]. This is obviously circular, so I don't know what to do.

When I set a breakpoint on that logged error in FIRApp.m::245, you can see that the stack trace originates at [FIRApp configure] and then throws the error inside [FIRApp defaultApp] after trying to configure FIRInstallations (which seems like a new thing since my pod upgrade).

image

Inspecting sDefaultApp at this breakpoint does in fact print out nil, but sDefaultApp was set to an instance up in [FIRApp configureWithName:options:], and if I go up one frame into [FIRInstallations installations], printing sDefaultApp prints the expected instance, which I find very strange.

// At breakpoint, frame #0 [FIRApp defaultApp]
(lldb) po sDefaultApp
 nil
(lldb) up
frame #1: 0x000000010c890f5f RemindEvents`+[FIRInstallations installations](self=FIRInstallations, _cmd="installations") at FIRInstallations.m:157:24
   154 	#pragma mark - Public
   155 	
   156 	+ (FIRInstallations *)installations {
-> 157 	  FIRApp *defaultApp = [FIRApp defaultApp];
    	                       ^
   158 	  if (!defaultApp) {
   159 	    [NSException raise:kFirebaseInstallationsErrorDomain
   160 	                format:@"The default FirebaseApp instance must be configured before the default"
(lldb) po sDefaultApp
<FIRApp: 0x600000250240>

Steps to reproduce:

I've attached a project that reproduces the issue and follows the same initialization pattern that our production app uses (ObjC/Swift mixed initialization with Firebase eventually initialized in Swift code). It appears that this happens when a second target that also depends on the Firebase/Analytics pod is added as a dependency on the main target. That is, I was not able to reproduce the issue with a blank project with only one target, but once I added a second target the exception was thrown.

Relevant Code:

FirebaseTest.zip

Podfile (included in the zip above, but just for transparency to others):

# Uncomment the next line to define a global platform for your project
platform :ios, '11.0'
use_frameworks!

def firebase
  pod 'Firebase/Analytics'
end

target 'FirebaseTest' do
  # Pods for FirebaseTest
  firebase
end

target 'Events' do
  firebase
end
@google-oss-bot

This comment has been minimized.

@ryanwilson
Copy link
Member

Thanks for the report and example project! This is definitely a configuration issue and Firebase being a static framework instead of a dynamic framework.

When running the example I see this log (among other identical ones for different classes):

 Class FIRApp is implemented in both ~/Library/Developer/Xcode/DerivedData/FirebaseTest-crygxlhukxdcwiessirdyyejbwhl/Build/Products/Debug-iphonesimulator/Events.framework/Events (0x10c9ba7f8) and ~/Library/Developer/CoreSimulator/Devices/8FF50C78-4312-4F5E-A8D8-C9A6F546D92E/data/Containers/Bundle/Application/BC8A1D75-68C4-4B92-810C-954F449F1AD9/FirebaseTest.app/FirebaseTest (0x10c446fb0). One of the two will be used. Which one is undefined.

Here's a good example of what can be done to avoid this: #4777 (comment)

The code to assign the sDefaultApp is before the addAppToAppDictionary call, as seen here:
https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseCore/Sources/FIRApp.m#L197-L202

There's also an issue tracking the decision to avoid hardcoding static frameworks in #2022

@niyazahmed
Copy link

niyazahmed commented Mar 16, 2020

We are facing this exact same issue and the comment solution is not working for the Pod set up we have. Will there be any fixes or workaround for this?

@LeffelMania
Copy link
Author

To close my side of the loop on this, the configuration issue that was pointed out was indeed an issue. We attempted to rework our Podfile in the way recommended by #4777 (comment). However, we ran into a second issue after updating our Podfile because of the use_frameworks! setting. We were unable to get Firebase to work with that setting included, but we were unable to get RealmSwift to work without it.

In the end, we did make the suggested structural changes to our Podfile, but we nevertheless ended up removing the Firebase/Analytics pod from our Podfile and instead integrated the static library distribution manually into our project.

If I have time this week I'll see if I can reproduce the Firebase/Realm incompatibility issue in my sample project for your consideration.

@firebase firebase locked and limited conversation to collaborators Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants