Swift包管理器。错误:找到名为...的多个包裹??

时间:2017-11-29 19:35:16

标签: swift swift-package-manager

让我们说:

B是一个依赖于CommonLib的库 应用程序依赖于B和CommonLib

以下是他们的主要活动

B的Package.swift:

import PackageDescription
let package = Package(
    name: "B",
    products: [
        .library(
            name: "B",
            targets: ["B"]),
    ],
    dependencies: [
      .package(url: "https://.../CommonLib", from: "1.0.0"),
   ],
    targets: [
        .target(
            name: "B",
            dependencies: ["CommonLib"]),
        .testTarget(
            name: "BTests",
            dependencies: ["B"]),
    ]
)

App的Package.swift

import PackageDescription
let package = Package(
    name: "App",
    dependencies: [
      .package(url: "https://.../CommonLib", from: "1.0.0"),
      .package(url: "https://.../B", from: "1.0.0"),
   ],
    targets: [
        .target(
            name: "App",
            dependencies: ["CommonLib", "B"]),
        .testTarget(
            name: "AppTests",
            dependencies: ["App"]),
    ]
)

swift build
error: Found multiple packages with the name CommonLib...

如果App和B都依赖于CommonLib,并且我将B和CommonLib导入App 发现错误找到名为...的多个包...

Apple Swift版本4.0.2(swiftlang-900.0.69.2 clang-900.0.38) 目标:x86_64-apple-macosx10.9

有谁知道如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

如果要将这些手动导入库,您将看到此错误。您不能拥有同名的多个包。

对于解决方案,您必须更改清单并删除其中一个清单。但是我认为如果你使用CocoaPod可以解决这个问题,CocoaPod是管理软件包的完美工具。库。您还可以从CocoaPod轻松更改清单。

答案 1 :(得分:0)

删除Package.pins并重新运行swift build。查看它尝试获取的包。检查.build/checkouts.build/dependencies-state.json - 分别写入哪些标签和哪些版本的CommonLib。