You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift Package添加Firebase依赖报错:FirebaseCore未找到

Swift Package依赖Firebase报错排查

问题描述

我正在创建一个可跨项目复用的Swift Package,已部署到私有仓库,能成功添加到项目,但依赖项无法正常工作。当前遇到报错:

x-xcode-log: product 'FirebaseCore' required by package 'sacore' target 'SACore' not found in package 'firebase-ios-sdk'.

FirebaseCore确实存在于firebase-ios-sdk包中,我已尝试以下操作:

  • 重置包缓存
  • 解析包版本
  • 更新包
  • 注释掉FirebaseCore依赖
  • 将FirebaseCore重命名为Firebase

若移除FirebaseCore,会出现新报错:

No such module 'GoogleUtilities_NSData'

请问我哪里操作有误?

我的Package.swift代码

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

let package = Package(
    name: "SACore",
    //    platforms: [.iOS(.v16)],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "SACore",
            targets: ["SACore"]),
    ],
        dependencies: [
            // Dependencies declare other packages that this package depends on.
            .package(url: "https://github.com/krzyzanowskim/CryptoSwift", from: "1.0.0"),
            .package(url: "https://github.com/firebase/firebase-ios-sdk", from: "10.0.0"),
            .package(url: "https://github.com/kylebshr/ScreenCorners", from: "1.0.0"),
            .package(url: "https://github.com/HeroTransitions/Hero", from: "1.6.0"),
        ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "SACore",
            dependencies: [
                .product(name: "FirebaseAuth", package: "firebase-ios-sdk"),
                .product(name: "FirebaseCore", package: "firebase-ios-sdk"),
                .product(name: "FirebaseFirestoreSwift", package: "firebase-ios-sdk"),
                .product(name: "CryptoSwift", package: "CryptoSwift"),
                .product(name: "ScreenCorners", package: "ScreenCorners"),
                .product(name: "Hero", package: "Hero"),
            ],
            path: "Sources",
            sources: ["Classes", "Extensions", "Constants.swift", "Shared Assets.xcassets"]
        )
    ]
)

排查与解决方法

1. 补全平台配置

你注释掉了platforms配置,Swift Package需要明确支持的平台版本,Firebase 10.x对iOS版本有最低要求(iOS 13+),配合Swift 5.7建议指定iOS 15+,取消注释并修改:

platforms: [.iOS(.v15)],

缺少平台配置可能导致Xcode无法正确解析Firebase的产品依赖。

2. 移除冗余的FirebaseCore依赖

FirebaseAuth、FirebaseFirestoreSwift这类产品会自动依赖FirebaseCore,你不需要显式声明。直接删除.product(name: "FirebaseCore", package: "firebase-ios-sdk"),让依赖链自动处理,这样能避免手动声明带来的匹配问题。

3. 检查Firebase版本兼容性

Swift 5.7对应的Xcode版本是14.x,Firebase 10.x与Xcode 14.x是兼容的,但如果你的主项目使用更低版本的Xcode,可能会出现解析错误。确认主项目的Xcode版本≥14.0,或者降低Firebase版本到适配的范围。

4. 彻底清理缓存

常规重置缓存无效的话,尝试以下操作:

  • 关闭Xcode
  • 删除目录~/Library/Caches/org.swift.swiftpm
  • 删除项目的DerivedData文件夹(可通过Xcode的File > Project Settings找到路径)
  • 重新打开项目,执行File > Packages > Reset Package Caches,再选择Update to Latest Package Versions

5. 私有仓库的依赖传递验证

如果你的私有仓库是通过自定义源管理的,要确保主项目的Package.resolved文件能正确拉取firebase-ios-sdk的公开仓库,没有被私有源的配置限制。可以尝试直接在主项目中添加firebase-ios-sdk依赖,确认能正常解析,再测试你的私有Package。

内容的提问来源于stack exchange,提问作者CristianMoisei

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 05:37:48