Firebase xcframework integration with SPM

Overview

Firebase xcframework integration with SPM

A small mirror for https://github.com/firebase/firebase-ios-sdk, to add support for using their binary dependencies (xcframeworks) with swift package manager.

This repo contains a Package.swift file, which uses a binaryTarget for all Firebase libraries (xcframework files are hosted in github releases).

Official SPM Support

Firebase currently supports SPM integration, see the official SDK integration instructions. This repo is an alternative for integrating with their pre-built xcframeworks for faster build times. See in depth discussion for official SPM support for xcframeworks here.

Installation

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyLibrary",
    platforms: [.iOS(.v11)],
    products: [
        .library(name: "MyLibrary", targets: ["MyLibraryTarget"])
    ],
    dependencies: [
        .package(
            name: "Firebase",
            url: "https://github.com/akaffenberger/firebase-ios-sdk-xcframeworks.git",
            .exact("8.10.0")
        ),
    ],
    targets: [
        .target(
            name: "MyLibraryTarget",
            dependencies: [
                .product(name: "Google-Mobile-Ads-SDK", package: "Firebase"),
                .product(name: "FirebaseAnalytics", package: "Firebase")
            ]
        )
    ]
)

Add resource bundles

Some Firebase frameworks require resource bundles. To include those, there are two options:

  1. Use the provided script to automatically include all Firebase resources. Copy the following into a Run Script Phase:
sh "${BUILD_DIR%Build/*}SourcePackages/checkouts/firebase-ios-sdk-xcframeworks/.scripts/resources.sh"
  1. Or, manually drag and drop the specific resource bundles you need from the package into your Copy Bundle Resources Phase:

How it works

The Package.swift and Sources files are automatically generated via a script, which is set to run in a scheduled cron job via Github Actions.

The script performs the following actions:

  • Downloads the latest release from https://github.com/firebase/firebase-ios-sdk
  • Parses the Firebase.zip to generate Package.swift and Sources/
  • Commits changes on a new branch and creates a PR
  • Creates a draft release, with a tag that mirrors the Firebase release. The draft release includes the assets needed for the swift package

Run locally

  • Install github cli: $ brew install gh
  • Generate the swift package: $ cd .scripts && sh package.sh debug skip-release
Comments
  • Package collision for SwiftProtobuf

    Package collision for SwiftProtobuf

    Attempted to add a dependency on another library that uses SwiftProtobuf and get the following collision error:

    multiple targets named 'SwiftProtobuf' in: 'firebase-ios-sdk-xcframeworks', 'swift-protobuf'
    

    Any thoughts on how these could be reconciled? The dependency in question is Algolia InstantSearch https://github.com/algolia/instantsearch-ios, which relies on the https://github.com/apple/swift-protobuf package.

    I imagine other important dependencies may pop up with a similar issue.

    opened by sejr 7
  • Missing FirebaseFirestoreSwift product

    Missing FirebaseFirestoreSwift product

    When pulling in the official Firebase package directly, there is a product called FirebaseFirestoreSwift available that adds support for the @DocumentID property wrapper, and Codable based write methods like .setData(from: Codable).

    Would it be possible to include that product in this package?

    enhancement 
    opened by tylerjbarnes 7
  • Google Sign In button doesn't render correctly

    Google Sign In button doesn't render correctly

    Hi - hoping someone might have some ideas on how to address this issue.

    I had previously wrapped the UIKit Google Sign In button in my SwiftUI app. When I was using the standard (not pre-compiled) Firebase packages, this rendered well. Now that I've switched to these pre-compiled packages, the button does not render any images or text: Broken Google Sign In Button

    I tried to switch to the now-existing SwiftUI implementation in the Google library, but import GoogleSignInSwift doesn't seem to exist in these pre-compiled packages, I can't find it in the list of frameworks/libraries to add. I would separately import the GoogleSignIn-iOS package, but it offers a library/framework/etc. of the same name GoogleSignIn as what's provided in this repo, so Xcode won't let me use both Swift packages at the same time.

    Whose issue is this: the pre-compiled Firebase package (for not providing the GoogleSignInSwift module and/or breaking the UIKit button implementation somewhere between the last version I was using and 9.1.0), this Swift package wrapping them (for interfering with exposing the Swift module and/or the rendering of the UIKit button), or mine (for... misconfiguring something I guess)? How can I start to tease that out? And is there a way to work around this where I can import the separate GoogleSignIn-iOS package?

    In case it matters, here's the UIKit wrapper that's broken:

    import SwiftUI
    import GoogleSignIn
    
    struct GoogleSignInButton: View {
        @Environment(\.colorScheme) var colorScheme
    
        var body: some View {
            Group {
                if colorScheme == .light { // (2)
                    GoogleSignInButtonInternal(colorScheme: .light)
                }
                 else {
                    GoogleSignInButtonInternal(colorScheme: .dark)
                }
            }
        }
    }
    
    fileprivate struct GoogleSignInButtonInternal: UIViewRepresentable {
        var colorScheme: ColorScheme
    
        func makeUIView(context: Context) -> GIDSignInButton {
            let button = GIDSignInButton()
            switch colorScheme {
                case .dark:
                    button.colorScheme = .dark
                    return button
                case .light:
                    button.colorScheme = .light
                    return button
                @unknown default:
                    fatalError()
            }
        }
    
        func updateUIView(_ uiView: UIViewType, context: Context) {
        }
    }
    

    Any ideas would be greatly appreciated!

    opened by ionothanus 5
  • InAppMessaging bundle is missing

    InAppMessaging bundle is missing

    8.15.0 - [Firebase/InAppMessaging][I-IAM400009] Display ran into error for message 3978956120715808093: Error Domain=com.firebase.inappmessaging.display Code=1 "(null)" UserInfo={message=resource bundle is missing}

    Screenshot 2022-04-26 at 12 30 27

    I can't get the in app messages to work.

    How are .bundles working with SPM and Firebase?

    Firebase seems to be using, for getting the resources for InAppMessaging

    + (NSArray *)relevantBundles {
      return @[ [NSBundle mainBundle], [NSBundle bundleForClass:[self class]] ];
    }
    

    Correct me if I'm wrong: SPM puts all the resources into the main app bundle, but mainBundle called from .xcframework won't be the app bundle, it'll be the framework bundle, hence it can't find the needed resources. That's as far as I've gone with my investigation.

    I'm trying to understand how to fix this issue as we really enjoy using this mirror. Could it have regressed? Or maybe I configured something incorrectly.

    bug 
    opened by michalciurus 5
  • Undefined symbol: _OBJC_CLASS_$_FIRCrashlytics ...

    Undefined symbol: _OBJC_CLASS_$_FIRCrashlytics ...

    I've added this package as a dependency to another swift package I have created MyPackage, and from Xcode's Project/ProjectDependency settings, I've added https://github.com/me/mypackage as a dependency.

    Now, when attempting to compile my project, I receive the following errors:

    Build target MyPackage
    Package MyPackage | Configuration Staging | Destination My iPhone | SDK iOS 15.5
    Link MyPackage_PackageProduct (arm64)
    Undefined symbols for architecture arm64:
      "_OBJC_CLASS_$_FIRCrashlytics", referenced from:
          objc-class-ref in NanitCore.o
      "_OBJC_CLASS_$_FIRRemoteConfigSettings", referenced from:
          objc-class-ref in NanitCore.o
      "_OBJC_CLASS_$_FIRRemoteConfig", referenced from:
          objc-class-ref in NanitCore.o
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    

    image

    I'm not sure what I'm missing, but it seems that when attempting to compile MyPackage which has firebase-ios-sdk-xcframeworks as a dependency, it fails ... Any ideas?

    opened by cohen72 2
  • Set AppAuth dependency instead of referencing binaryTarget

    Set AppAuth dependency instead of referencing binaryTarget

    When using your (very helpful) package, I encountered a conflict using AppAuth in SPM. Because this package is using binary target, SPM is not able to resolve AppAuth dependency if you use it too.

    Using AppAuth package solves the issue, but please note that I don't use GoogleSignIn. GoogleSignIn package refers to the same AppAuth version, so it shouldn't cause any issue. https://github.com/google/GoogleSignIn-iOS/blob/main/Package.swift

    opened by AdrienCog 2
  • FirebaseFirestore unsafe build flags

    FirebaseFirestore unsafe build flags

    Since updating to version 9.0.0 I am unable to build the project. I get the following error:

    The package product 'FirebaseFirestore' cannot be used as a dependency of this target because it uses unsafe build flags.
    
    bug 
    opened by dineshvijaykumar 2
  • `ld: framework not found FBLPromises`

    `ld: framework not found FBLPromises`

    opened by imWildCat 2
  • bazel + spm

    bazel + spm

    it's possible to use spm + bazel with some scripts by @cgrindel

    I want to do it with firebase - there's a long discussion here - and Google haven't been able to come to the party.... I'm thinking with your xcframework approach - it maybe possible. I don't expect you to invest too much time - https://github.com/firebase/firebase-ios-sdk/issues/6115

    here's a top level write up with spm + bazel https://chuckgrindel.com/swift-packages-in-bazel

    
    load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
    
    http_archive(
        name = "cgrindel_rules_spm",
        sha256 = "03718eb865a100ba4449ebcbca6d97bf6ea78fa17346ce6d55532312e8bf9aa8",
        strip_prefix = "rules_spm-0.11.0",
        urls = [
            "http://github.com/cgrindel/rules_spm/archive/v0.11.0.tar.gz",
        ],
    )
    
    load(
        "@cgrindel_rules_spm//spm:deps.bzl",
        "spm_rules_dependencies",
    )
    
    spm_rules_dependencies()
    
    load(
        "@build_bazel_rules_swift//swift:repositories.bzl",
        "swift_rules_dependencies",
    )
    
    swift_rules_dependencies()
    
    load(
        "@build_bazel_rules_swift//swift:extras.bzl",
        "swift_rules_extra_dependencies",
    )
    
    swift_rules_extra_dependencies()
    
    
    load("@cgrindel_rules_spm//spm:defs.bzl", "spm_pkg", "spm_repositories")
    
    spm_repositories(
        name = "swift_pkgs",
        dependencies = [
            spm_pkg(
                "https://github.com/firebase/firebase-ios-sdk.git",
                from_version = "8.10.0",
                products = ["Firebase"],
            ),
        ],
    )
    

    unfortunately -

    
    spm_repositories(
        name = "swift_pkgs",
        dependencies = [
            spm_pkg(
                "https://github.com/akaffenberger/firebase-ios-sdk-xcframeworks.git",
                from_version = "8.10.0",
                products = ["Firebase"],
            ),
        ],
    )
    

    couldn't get it to work with your spm either.

    "@swift_pkgs//Firebase:Firebase",

    opened by wweevv-johndpope 1
  • No such module 'xxx' errors.

    No such module 'xxx' errors.

    Hi, @akaffenberger Thank you for creating a great library!

    I'm new to Swift Package. I'm stuck on the following problems. Would you mind telling me how to fix them?

    Description

    I've got No such module 'xxx' errors.

    image

    I think the cause is my project can't get source files from firebase-sdk-ios because there is still a dummy file in each product in the following screenshot. I know package.sh will get those files, but I don't understand how I should run that script. (Copy the script into my project and run it?)

    image

    What I did

    • Add the package

    image

    Here is my package.swfit.

    // swift-tools-version:5.3
    // The swift-tools-version declares the minimum version of Swift required to build this package.
    
    import PackageDescription
    
    let package = Package(
        name: "FirebaseSDK",
        platforms: [.iOS(.v11)],
        products: [
            .library(name: "FirebaseSDK", targets: ["FirebaseSDK"])
        ],
        dependencies: [
            .package(
                name: "Firebase",
                url: "https://github.com/akaffenberger/firebase-ios-sdk-xcframeworks.git",
                .exact("9.5.0")
            ),
        ],
        targets: [
            .target(
                name: "FirebaseSDK",
                dependencies: [  // products that I want to use
                    .product(name: "FirebaseAnalytics", package: "Firebase"),
                    .product(name: "FirebaseAuth", package: "Firebase"),
                    .product(name: "FirebaseFirestore", package: "Firebase"),
                    .product(name: "FirebaseCrashlytics", package: "Firebase"),
                    .product(name: "GoogleSignIn", package: "Firebase")
                ]
            )
        ]
    )
    
    • Add -ObjC to Build Settings -> Other Linker Flags

    image

    • Copy the script into a Run Script Phase:

    image

    opened by kamimi01 1
  • Combine community extensions missing

    Combine community extensions missing

    The packages FirebaseAuthCombine-Community & FirebaseFirestoreCombine-Community that are part of the official Firebase SDK are not included into the Package.swift of this repository.

    https://github.com/firebase/firebase-ios-sdk/blob/master/Package.swift

    Line 65:

        ...
        .library(
          name: "FirebaseAuthCombine-Community",
          targets: ["FirebaseAuthCombineSwift"]
        ),
        .library(
          name: "FirebaseFirestoreCombine-Community",
          targets: ["FirebaseFirestoreCombineSwift"]
        ),
        ...
    

    I am wondering if there is a specific limitation that prevent us from including those into the FirebaseFirestore and FirebaseAuth targets ?

    opened by ncltg 1
  • SwiftUI Previews are not working

    SwiftUI Previews are not working

    Hello, thanks for creating this package, it really helps with build times. Just one problem, I can't get the Swiftui Previews to work. The official firebase package works without problems. Do you know if it is something specific with this mirror?

    opened by dancarvajc 6
Releases(10.3.0)
Owner
Ashleigh Kaffenberger
Ashleigh Kaffenberger
iOS Open-Source Telematics App with Firebase© integration

Open-source telematics app for iOS. The application is suitable for UBI (Usage-based insurance), shared mobility, transportation, safe driving, tracking, family trackers, drive-coach, and other driving mobile applications

Damoov 17 Dec 11, 2022
Firebase Analytics Firebase Notification Alamofire KingFisher Ombdb API

MovieOmdbApp Firebase Analytics Firebase Notification Alamofire KingFisher Ombdb

Kaya 0 Dec 20, 2021
Aplikasi iOS Advanced Level To Do List dengan Firebase Auth, SwiftUI, MVVM Design Pattern, dan Firebase Firestore

Aplikasi Tasker adalah aplikasi iOS To Do List yang dibuat menggunakan Autentikasi Firebase / Firestore dan MVVM Design Pattern.

DK 10 Oct 17, 2022
A swift package(SPM) with iOS UI component that loads and displays images from remote urls or local assets and displays in a slide-show form with auto scroll feature.

MDBannersView A swift package with an iOS UI component that loads and displays images from remote urls, local assets and displays in a slide-show form

Madhav Deva 2 Feb 5, 2022
DEVOTE In this SwiftUI tutorial, we will develop a task manager iOS application with Core Data integration.

DEVOTE In this SwiftUI tutorial, we will develop a task manager iOS application with Core Data integration. This is not a project with a boring user interface. This iOS and iPadOS application provides a personal touch and feel.

Noye Samuel 1 Dec 21, 2021
Simple Todo Application using SwiftUI / Firebase / Redux.

Simple Todo Application using SwiftUI/Firebase/Redux/Combine. Light _ _ _ _ Dark _ _ _ Feature Use SwiftUI fully. Use Firebase. Authentication Cloud F

Suguru Kishimoto 337 Dec 25, 2022
Completed Project for Authentication in SwiftUI using Firebase Auth SDK & Sign in with Apple

Completed Project for Authentication in SwiftUI using Firebase Auth SDK & Sign in with Apple Follow the tutorial at alfianlosari.com Features Uses Fir

Alfian Losari 43 Dec 22, 2022
SwiftUI, Firebase, Kingfisher, googleapis

SwiftUI-KokaiByWGO Xcode Version 12.0 SwiftUI, Firebase, Kingfisher, googleapis Learn Thai with pictures and sounds Note : This version have no CMS so

Waleerat S. 0 Oct 6, 2021
Instagram clone with firebase and swift

Instagram clone with firebase and swift

Murat Çiçek 1 Nov 20, 2021
A grocery list app for families written in Swift using Firebase Realtime Database

FamiList | Grocery list app in Swift FamiList is a grocery list app for families written in Swift using Firebase Realtime Database. You can add differ

Wasan Ibrahim 2 Jul 31, 2022
The app demonstrates how to use Firebase in a SwiftUI iOS app

Firebase SwiftUIDemo app This app demonstrates how to use Firebase in a SwiftUI iOS app. Firebase Setup Go to firebase.com Click new project. Copy app

Andrew Gholson 0 Nov 28, 2021
The ToDoList application using FireBase allows you to register users

ToDoFirebase Приложение ToDoList с использовавнием FireBase позволяет зарегистри

Vasiliy Chistyakov 0 Dec 19, 2021
A detailed clone of the Instagram app built with Firebase

[This repository is no longer being maintained] InstagramClone A detailed clone

null 0 Dec 26, 2021
Learning App with Firebase Auth

Learning App Displays how to make a learning app with Swift, iOS's programming l

Andrew Gholson 0 Jan 9, 2022
Firebase Quickstart Samples for iOS

Firebase Quickstarts for iOS A collection of quickstart samples demonstrating the Firebase APIs on iOS. Each sample contains targets for both Objectiv

Firebase 2.5k Jan 1, 2023
A SwiftUI component which handles logging in with Apple to Firebase

Login with Apple Firebase SwiftUI I made this SwiftUI component to handle logging in with Apple to Firebase. Demo Gif Usage in SwiftUI struct ContentV

Joe Hinkle 153 Dec 23, 2022
Warning pushNotification - Using push notification with Firebase Cloud Messaging

재난문자 푸시 알림 구현 1) 구현 기능 2) 기본 개념 (1) Remote Notification 불시에 발생한 업데이트 불특정 시간 예측 불

null 0 Jan 24, 2022
Ready use service for Firebase. Included interface, recored devices and notifications.

SPProfiling Ready use service with using Firebase. Included interface, manage auth process, recored devices and profile data. Installation Ready for u

Ivan Vorobei 13 Oct 29, 2022
IOS mobile application that uses URLSession and Firebase

DogApp IOS mobile application that uses URLSession and Firebase. First a dog ima

null 0 Feb 13, 2022