firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.55k stars 1.45k forks source link

Cannot add the `-ObjC` linker flag when integrating Firebase Analytics via SPM #8567

Closed yakovmanshin closed 3 years ago

yakovmanshin commented 3 years ago

Step 1: Describe your environment

Step 2: Describe the problem

The SPM integration guide mentions the -ObjC linker flag which must be added when Firebase Analytics is used.

However, when Firebase is integrated via a Swift package and once this flag is added to the package’s target, it’s no longer possible to use the package in the iOS app due to the The package product 'MyPackage' cannot be used as a dependency of this target because it uses unsafe build flags error.

Steps to reproduce:

  1. Declare a Swift package in an iOS app project and add it to the app target;
  2. In Package.swift, add Firebase Analytics as one of the package’s targets’ dependency;
  3. Specify the -ObjC flag in linkerSettings for that target (see below);
  4. The app target builds with the aforementioned error.
.target(
    name: "MyAnalyticsTarget",
    dependencies: [
        .product(name: "FirebaseAnalytics", package: "Firebase"),
    ],
    linkerSettings: [.unsafeFlags(["-ObjC"])]
),
google-oss-bot commented 3 years ago

I found a few problems with this issue:

paulb777 commented 3 years ago

The -ObjC option needs to be added to the app's build settings. It should not be added to a Package.swift. See the screenshot in https://github.com/firebase/firebase-ios-sdk/blob/master/SwiftPackageManager.md