我们说:
B是一个依赖于CommonLib的库
应用程序依赖于B和CommonLib
这是他们的主要活动
B包.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"]),
    ]
)

应用程序包.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
找到多个名称为的包时出错。。。
苹果Swift 4.0.2版(swiftlang-900.0.69.2 clang-900.0.38)
目标:x86_64-apple-macosx10.9
有人知道怎么解决这个问题吗?

最佳答案

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

10-06 05:11