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

SPM中为XCFramework添加本地依赖报错:找不到MobileCoreFramework

解决SPM本地依赖找不到MobileCoreFramework的问题

问题根源

你的MobileCoreSPM配置里,只对外发布了MobileCoreSPM这个library产品,并没有把MobileCoreFramework单独声明为可被外部依赖的产品。SPM的规则是:一个包只能引用另一个包明确在products里定义的产物,不能直接引用对方内部的target(比如你这里的MobileCoreFramework是MobileCoreSPM的内部binary target)。

修复步骤

1. 修改MobileCoreSPM的Package.swift,暴露MobileCoreFramework为独立产品

调整products部分,新增一个library产品专门对外提供MobileCoreFramework:

name: "MobileCoreSPM",
products: [
    // 保留原有的组合库(如果需要的话)
    .library(
        name: "MobileCoreSPM",
        targets: ["MobileCoreSPM","MobileCoreFramework"]),
    // 新增这一行,单独暴露MobileCoreFramework
    .library(
        name: "MobileCoreFramework",
        targets: ["MobileCoreFramework"]),
],
dependencies: [

],
targets: [
    .target(
        name: "MobileCoreSPM",
        dependencies: ["MobileCoreFramework"]),
    .binaryTarget(name: "MobileCoreFramework", path: "Artifacts/MobileCoreFramework.xcframework"),
]

2. 修改BillpaySPM的Package.swift,正确引用依赖

不需要直接写MobileCoreFramework作为依赖,而是通过MobileCoreSPM包提供的产品来引用:

let package = Package(
    name: "BillpaySPM",
    products: [
        .library(
            name: "BillpaySPM",
            targets: ["BillpaySPM"]),
    ],
    dependencies: [
        .package(path: "/Users/com/Documents/POC/Try2/MobileCoreLib"),
    ],
    targets: [
        .target(
            name: "BillpaySPM",
            dependencies: [
                "BillpayFramework",
                // 改成引用MobileCoreSPM包中的MobileCoreFramework产品
                .product(name: "MobileCoreFramework", package: "MobileCoreSPM")
            ]),
        .binaryTarget(name: "BillpayFramework", path: "Artifacts/BillpayFramework.xcframework"),
    ]
)

3. 验证依赖

修改完成后,清理Xcode的DerivedData,重新打开项目让SPM重新解析依赖,即可解决找不到产品的错误。

额外说明

如果BillpayFramework已经静态链接了MobileCoreFramework,则无需在BillpaySPM里重复声明该依赖;但如果是动态依赖,或者需要上层项目能访问MobileCoreFramework的API,就必须按上述方式暴露并引用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 02:30:43