firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

FirebaseApp.configure(options: ) raises an exception inconsistent with the documentation of the options type

Open SwiftNativeDeveloper opened this issue 1 year ago • 2 comments

Description

I want to initialize my FirebaseOptions programmatically because, like many of the other open issues related to FirebaseOptions, I have multiple versions of the same app code that make use of CI/CD deployment scripts to connect different environments and more. I do not want my GoogleService-Info.plist file sitting in the compiled output of my app. I want these values injected via XCConfig and build parameters instead.

The swift doc helper for this initializer states:

init(googleAppID:gcmSenderID:) Initializes a customized instance of FirebaseOptions with required fields. Use the mutable properties to modify fields for configuring specific services. Note that it is not possible to customize FirebaseOptions for Firebase Analytics which expects a static file named GoogleServices-Info.plist - https://github.com/firebase/firebase-ios-sdk/issues/230.

The keywords from this required fields.

So the following code is assumed to work:

  let options = FirebaseOptions(
      googleAppID: "valid-id-goes-here",
      gcmSenderID: "valid-id-goes-here-also"
  )
  FirebaseApp.configure(options: options)

However, this is not the case, and instead raises an exception and crashes on launch.

*** Terminating app due to uncaught exception 'com.firebase.installations', reason: '[FirebaseInstallations][I-FIS008000] Could not configure Firebase Installations due to invalid FirebaseApp options. The following parameters are nil or empty: FirebaseOptions.APIKey, FirebaseOptions.projectID. If you use GoogleServices-Info.plist please download the most recent version from the Firebase Console. If you configure Firebase in code, please make sure you specify all required parameters.'

The referenced keys from the output above, if required as it suggests, should be in the parameterized initializer as required.

Additionally, the values of the configuration should not be immutable non-optional strings if they're required, and their documentation should state they're required and not providing a valid value will result in the library raising an exception.

apiKey An API key used for authenticating requests from your Apple app, e.g. The key must begin with “A” and contain exactly 39 alphanumeric characters, used to identify your app to Google servers.

var apiKey: String? { get set }

projectID The Project ID from the Firebase console, for example @“abc-xyz-123”.

var projectID: String? { get set }

The documentation to configure multiple projects also compounds the problem by applying every property available on the configuration. It is really hard to tell, from documentation, which fields are actually required. https://firebase.google.com/docs/projects/multiprojects

  1. Please update the documentation to state what properties are actually required with a FirebaseOptions object in a clear developer guide as well as source code comments for auto doc in Xcode.
  2. Please update the initializer to require all required properties (create a new one, mark the old one as deprecated if you must).
  3. Please assess https://github.com/firebase/firebase-ios-sdk/issues/6415 from 2020 to remove any no longer needed properties from the parameterized initializer.
  4. Please update the documentation for the multi projects to use the updated initializer that takes all required properties at initialization, and optionally sets the optional properties.

Reproducing the issue

  let options = FirebaseOptions(
      googleAppID: "valid-id-goes-here",
      gcmSenderID: "valid-id-goes-here-also"
  )
  FirebaseApp.configure(options: options)

Firebase SDK Version

10.22.1

Xcode Version

15.3

Installation Method

Swift Package Manager

Firebase Product(s)

Analytics, Crashlytics, Performance

Targeted Platforms

iOS, visionOS

Relevant Log Output

*** Terminating app due to uncaught exception 'com.firebase.installations', reason: '[FirebaseInstallations][I-FIS008000] Could not configure Firebase Installations due to invalid FirebaseApp options. The following parameters are nil or empty: `FirebaseOptions.APIKey`, `FirebaseOptions.projectID`. If you use GoogleServices-Info.plist please download the most recent version from the Firebase Console. If you configure Firebase in code, please make sure you specify all required parameters.'

If using Swift Package Manager, the project's Package.resolved

Cannot share Package.resolved as it contains information about private repositories.

Rest assured, all checkmarks green for Firebase and it's dependencies.

If using CocoaPods, the project's Podfile.lock

n/a - using Swift Package Manager.

SwiftNativeDeveloper avatar Apr 01 '24 18:04 SwiftNativeDeveloper

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Apr 01 '24 18:04 google-oss-bot

Thanks for reporting, @SwiftNativeDeveloper. Based on this, the API key, project ID, and Application ID are the required fields in Firebase Options. I understand that the documentation seems confusing. I'll be raising this to our engineers and see what we can do here.

rizafran avatar Apr 17 '24 18:04 rizafran