firebase / firebase-ios-sdk

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

FR: Support for Swift Package Manager #3136

Closed WarSunsOfPeace closed 3 years ago

WarSunsOfPeace commented 5 years ago

With iOS support for Swift Package Manager in Xcode 11 can we please get that added to this project.

google-oss-bot commented 5 years ago

I found a few problems with this issue:

ryanwilson commented 5 years ago

Hey @w0mba7 - thanks for the report šŸ˜„

We're excited and looking into the best way we can support this as soon as we can, but there are a few dependencies and file structure changes we may need to do. We started experimenting with support on a branch at https://github.com/firebase/firebase-ios-sdk/tree/spm-master a few weeks ago and have a better idea of the approach we need.

We also started a discussion on binary framework distribution on the Swift forums but it looks like we may get some more information from a WWDC session this week titled Binary Frameworks in Swift .

This won't be something we can do overnight but want to support it as soon as we can, there are a few bugs to work out as well (like SR-10707 that I discovered while working on adding support).

possen commented 5 years ago

https://github.com/firebase/firebase-ios-sdk/issues/2135 linking issues.

possen commented 5 years ago

My experiment was to take the Carthage Binaries and add this to the Targets section but complains that the module map is in the wrong place:

error: package has unsupported layout;modulemap '/Users/user/Projects/RideCore/Carthage/Build/iOS/nanopb.framework/Modules/module.modulemap' should be inside the 'include' directory

moving things around in the folders and renaming did not seem to help.

     targets: [
        .target(
            name: "Core",
            dependencies: ["stuff"],
            path: "Carthage/Build/iOS",
            linkerSettings: [
                LinkerSetting.linkedFramework("FirebaseAnalytics"),
                LinkerSetting.linkedFramework("FirebaseCore"),
                LinkerSetting.linkedFramework("FirebaseDatabase"),
                LinkerSetting.linkedFramework("FirebaseMessaging"),
                LinkerSetting.linkedFramework("GoogleUtilities"),
                LinkerSetting.linkedFramework("leveldb-library"),
                LinkerSetting.linkedFramework("GoogleAppMeasurement"),
                LinkerSetting.linkedFramework("GTMSessionFetcher"),
                LinkerSetting.linkedFramework("nanopb"),
                LinkerSetting.linkedFramework("Protobuf")
            ]
morganchen12 commented 5 years ago

Related to #2135

paulb777 commented 5 years ago

Follow the progress at https://github.com/firebase/firebase-ios-sdk/commits/spm-master. Suggestions and PRs welcome!

paulb777 commented 5 years ago

Much of Firebase Unit Testing relies on OCMock which does not yet support Swift PM. That could be a great place for someone in the community to contribute to accelerate the migration.

paulb777 commented 5 years ago

For Firebase to support Swift Package Manager, there will need to be several changes to both Swift Package Manager and Firebase. See https://github.com/firebase/firebase-ios-sdk/commits/spm-master for the prototype implementation which successfully built a few of the Firebase libraries with SwiftPM. Below is a summary of some of the key requirements:

Binary library support Some of the Firebase libraries may not open source. Thus for Firebase to completely move to SwiftPM, binary library support must be added, including support for depending on a source-based Package from a binary package. See the Swift forum discussion. The pitch to support framework search paths could provide a workaround.

Resource support Firebase ML, Firebase In App Messaging and Firebase Firestore require resource support. There may be a workaround for Firestore, but not for the others. See Swift bug.

Separately versioned libraries per repo Firebase currently separately versions its libraries from a single mono-repo. This could be accomplished with SwiftPM by adding multiple package support to a repo or by adding the ability to version libraries within a package. Xcode would also need to be similarly updated.

Firebase could consider abandoning separately versioning its libraries like it already does for binary and Carthage distributions. This would be especially unfortunate for managing new libraries with zero major versions of semantic versioning.

Build Settings Some Firebase libraries rely upon being able to build some of their sources with and without Automatic Reference Counting (ARC). There does not seem to be a way to do this. See Forum discussion and Swift build setting proposal.

Module Map Generation Objective-C modules aren't generated for Objective-C targets. This causes us to rely on changing our import statements to use local header paths instead of framework paths. See https://bugs.swift.org/browse/SR-10707

Testing - OCMock Most of Firebase unit testing relies upon OCMock which does not yet have Swift Package Manager support.

Subspec support Firebase relies upon subspecs so that different library combinations can choose different subsets of the GoogleUtilities support library. Now that static libraries/frameworks are better supported, it is probably feasible to split each GoogleUtilities subspec into a separate library.

Private Headers Firebase uses the CocoaPods/Xcode private headers feature to share non-public APIs across libraries. It might be feasible for Firebase to abandon the use of this feature in favor of repo-relative import paths.

possen commented 5 years ago

Thanks for your work on this!

possen commented 5 years ago

The latest Xcode Beta 4 says under resolved issues "Swift packages that use unsafeFlags build settings canā€™t be used as a dependency. (50354068)" this could be a breakthrough in getting prebuilt binaries to work. It may allow "-F" to be passed as well as "no-objc-arc". Haven't tried it yet but thought I would let you know.

ivanvorobei commented 4 years ago

Trying install spm-master branch via SPM, get this error:

Screenshot 2019-08-06 at 11 18 23

$(SRCROOT) in Package.swift

ryanwilson commented 4 years ago

@ivanvorobei thanks for testing! Which version of Xcode are you using?

ivanvorobei commented 4 years ago

@ryanwilson I am use last beta of 11 Xcode.

julienbodet commented 4 years ago

Trying install spm-master branch via SPM, get this error:

Screenshot 2019-08-06 at 11 18 23

$(SRCROOT) in Package.swift

I got the same error using Xcode Version 11.0 beta 5 (11M382q) when trying to add the package to my project. After a quick look at the documentation, it seems the path has to be relative to the project directory:

/// - Parameters:
///   - path: The path of the directory that contains the  headers. The path is relative to the target's directory.
///   - condition: A condition that restricts the application of the build setting.
public static func headerSearchPath(_ path: String, _ condition: PackageDescription.BuildSettingCondition? = nil) -> PackageDescription.CSetting
paulb777 commented 4 years ago

@ivanvorobei @julienbodet Thanks for the reports! Something has changed between Xcode 11 beta 2 and beta 5 that leads to this issue.

I've asked a question about it on the SwiftPM forum.

paulb777 commented 4 years ago

FYI, a forum discussion today about adding the -fno-objc-arc option to library builds. Firebase needs this in libraries that depend on Protobuf.

vmanot commented 4 years ago

Any update on this?

paulb777 commented 4 years ago

We'll do a full reassessment with the latest Xcode 11 in the next week or two, but it doesn't seem there has been much progress on most of the open issues.

mmgrt commented 4 years ago

Any update on this?

paulb777 commented 4 years ago

There's essentially no change from the July 9th comment above. There have been some proposals and discussions about some of the necessary features in the Swift Package Manager Forums, but not much tangible progress yet.

MihaelIsaev commented 4 years ago

Any chance to use firebase through SPM now?

notoriouspawn commented 4 years ago

still no update? its been so long

rhysforyou commented 4 years ago

While it's great to see everyone so excited to adopt Swift Package Manager in their projects, there's currently nothing the Firebase team can do to support it. Once SPM supports binary frameworks I'm sure they'll give us an update, but until then all the comments asking for updates aren't particularly useful.

inPhilly commented 4 years ago

It's difficult if you don't use CocoaPods... I have a legacy Objective-C project that I'm trying to integrate Firebase into. It doesn't use CocoaPods because there were so many issues. I just spent an hour manually integrating Firebase and Crashlytics and get this error:

*** Terminating app due to uncaught exception 'FIRAnalyticsVersionMismatch', reason: 'Google Analytics for Firebase version (60105000) does not match with Google App Measurement (60103000) version. Please update.'

I have the latest firebase manual download and the latest Crashlytics manual download. So with manual, it won't work; Swift Package Manager isn't happening; and there is no Carthage support. So basically, unless you use CocoaPods, you are out of luck. Discouraging.

paulb777 commented 4 years ago

@inPhilly It looks like you have a FirebaseAnalytics.framework and GoogleAppMeasurement.framework from two different distributions.

Firebase does have an experimental Carthage distribution. See https://github.com/firebase/firebase-ios-sdk/blob/master/Carthage.md

bdrelling commented 4 years ago

Until SE-0272 is integrated, there's nothing Firebase can do here... I'm eagerly awaiting for SPM support as a consumer as well, but they literally can't do anything when SPM is missing a feature that Firebase depends on.

Be reasonable, people.

tychop commented 4 years ago

Why don't they use linked binary frameworks? See https://forums.swift.org/t/binary-frameworks-with-swiftpm/26225/2

paulb777 commented 4 years ago

@tychop Missing support for binary dependencies is just one of several missing Swift Package Manager features necessary to support Firebase. See above.

iZooto-sdk commented 4 years ago

Any one suugest to me ,I want the Firebase initialise without Google-Service.plist?

floriangbh commented 4 years ago

@amit6061 I'm not sure this is the great place to ask this kind of questions.

Please stop spamming this issue (every post will notify by email a lot of people), I'm pretty sure Firebase engineers will updated us once SPM will be more compliant with Firebase.

iZooto-sdk commented 4 years ago

I have send the notification from Firebase Cloud Messaging Panel . I am getting the error ,Please help me

objc[600]: Class FIRMessagingPersistentSyncMessage is implemented in both /private/var/containers/Bundle/Application/E28A6E76-BC27-4207-AD6C-03C7D95ADBA6/iZootoTesting.app/Frameworks/iZooto_release.framework/iZooto_release (0x1013a0920) and /var/containers/Bundle/Application/E28A6E76-BC27-4207-AD6C-03C7D95ADBA6/iZootoTesting.app/iZootoTesting (0x100968950). One of the two will be used. Which one is undefined.

Umar-M-Haroon commented 4 years ago

@amit6061 Please make a separate issue. Your issues arenā€™t relevant to the actual SPM thread and I can imagine others arenā€™t too happy getting notifications over this... (ironically Iā€™m sending emails to a ton of people too, which I apologize in advance for)

iZooto-sdk commented 4 years ago

ok

On Wed, Dec 4, 2019 at 2:05 PM Umar Haroon notifications@github.com wrote:

@amit6061 https://github.com/amit6061 Please make a separate issue. Your issues arenā€™t relevant to the actual SPM thread and I can imagine others arenā€™t too happy getting notifications over this...

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-ios-sdk/issues/3136?email_source=notifications&email_token=ANSGFZX77RS6OZ65DRGMIBLQW5TULA5CNFSM4HS7ALKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF4FJYY#issuecomment-561534179, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANSGFZURJBTAK7M7X7I4ETTQW5TULANCNFSM4HS7ALKA .

--

Thanks and Regards, Amit Kumar Gupta Android/iOS Developer 3rd Floor, A-35, Sector 2- Noida 201301 Contact: 7905717240 www.izooto.com

inPhilly commented 4 years ago

I'm just now revisiting this and would really like to use Firebase Crashlytics, but I read on another thread that you will not ultimately be supporting Carthage because of Swift Package Manager; especially with there being so many problems with Swift Package Manager, and because Carthage is another choice that is not going away anytime soon, I fail to see why you would not want to pursue officially supporting Carthage. Because I cannot use CocoaPods, and can't keep up with manually integrating and updating Firebase, I for one am forced to look elsewhere, when I would really like to use Firebase in my apps.

paulb777 commented 4 years ago

@inPhilly If it helps, I would expect us to continue Carthage experimental support at least until Swift Package Manager is available.

rynaardb commented 4 years ago

My experiment was to take the Carthage Binaries and add this to the Targets section but complains that the module map is in the wrong place:

error: package has unsupported layout;modulemap '/Users/user/Projects/RideCore/Carthage/Build/iOS/nanopb.framework/Modules/module.modulemap' should be inside the 'include' directory

moving things around in the folders and renaming did not seem to help.

     targets: [
        .target(
            name: "Core",
            dependencies: ["stuff"],
            path: "Carthage/Build/iOS",
            linkerSettings: [
                LinkerSetting.linkedFramework("FirebaseAnalytics"),
                LinkerSetting.linkedFramework("FirebaseCore"),
                LinkerSetting.linkedFramework("FirebaseDatabase"),
                LinkerSetting.linkedFramework("FirebaseMessaging"),
                LinkerSetting.linkedFramework("GoogleUtilities"),
                LinkerSetting.linkedFramework("leveldb-library"),
                LinkerSetting.linkedFramework("GoogleAppMeasurement"),
                LinkerSetting.linkedFramework("GTMSessionFetcher"),
                LinkerSetting.linkedFramework("nanopb"),
                LinkerSetting.linkedFramework("Protobuf")
            ]

@possen Did you ever figure out how to get it working? I'm also looking into a similar approach but ran into the exact same issue.

rhysforyou commented 4 years ago

A quick update for anyone still watching this thread: proposal SE-0272 has been accepted by the Swift Evolution team. This proposal involves adding support for binary dependencies to the Swift Package Manager and, once implemented, will mean that the Firebase SDK can hopefully be distributed as a Swift package.

productdevbook commented 4 years ago
Screen Shot 2020-01-12 at 10 42 02

xcode 11.3

rhysforyou commented 4 years ago

@mkalayci35 Firebase isn't available via Swift Package Manager yet, that's what we're discussing in this issue.

epontes commented 4 years ago

Same error here, no firebase sdk in package manager yet!

paulb777 commented 4 years ago

@floriangbh The sentiment is fine in the previous comment, but the language is not. I'm deleting. Please keep subsequent comments along the lines of https://github.com/firebase/firebase-ios-sdk/issues/3136#issuecomment-560365440.

Others, the appropriate way to indicate your desire for this feature is to thumbs-up the issue and/or work on contributions to Swift Package Manage and this repo to address the known issues discussed above.

OldCrab commented 4 years ago

Interesting. You want us to migrate from Fabric, but you can't support the main way to add dependencies now.

Sherlouk commented 4 years ago

Looks like part/all of SE-0272 (Binary Dependencies in SPM) has been implemented, finalised with this PR: https://github.com/apple/swift-package-manager/pull/2514/

Also looks like good progress on resources APIs has been done - fingers crossed for another great update to SPM coming soon šŸ‘ šŸ¤ž

DevAndArtist commented 4 years ago

Unless Apple will release Xcode 11.5 before WWDC, I don't see this happening before Xcode 12 is released together with all new OS's. The required features mentioned upthread won't be part of Swift 5.2 and therefore of Xcode 11.4.

ryanwilson commented 4 years ago

The Swift 5.3 Release Process was just posted, stating that the branch for SwiftPM will be cut tomorrow. We'll use that once it's cut to test and try to get support working before the next Xcode release (presumably WWDC timeline, but nothing was confirmed in this post for release timeline). Once we have something functional I'll update here and folks can test, hopefully we can get a lot of testers in before the release so we can get cherry-picks for any fixes needed.

juanjoseluisgarcia commented 4 years ago

I am putting Firebase, Crashlytics and app distribution on hold until this is resolved. Pods are a no go.

fabriciomasiero commented 4 years ago

Overwriting Crashlytics/Fabric to Firebase. Same error here

Screen Shot 2020-05-06 at 23 13 50
ryanwilson commented 4 years ago

@fabriciomasiero I believe you commented on the wrong issue - please re-open a new issue or comment on the original one you intended to as I've marked the comment as off-topic. No need to respond to this message.

@juanjoseluisgarcia we're eagerly awaiting the release of binary framework support for SwiftPM as well, but in the meantime we do offer Carthage and Zip distribution for those that don't want to integrate with CocoaPods.

stuffmc commented 4 years ago

Hi @ryanwilson ā€”Ā is Xcode 11.5 GM (11E608c), holding Swift version 5.2.4, the right thing? I'm afraid not, as you mentioned Swift 5.3, which seems to be hold for WWDC I'm afraid :(

DevAndArtist commented 4 years ago

Swift 5.3, which seems to be hold for WWDC I'm afraid

@stuffmc that's expected.