Swift 包管理器 - 无法解析清单

Swift Package Manager - Failed to parse the manifest

我正在尝试将 CocoaPod 迁移到 SPM。 它应该很简单,但由于某种原因我不断收到错误“无法解析清单文件”。

带库的回购可以在这里找到:https://github.com/agcoesbenr/RBSManager/tree/swift-package-manager

// swift-tools-version:5.1
import PackageDescription

let package = Package(
    name: "RBSManager",
    platforms: [
        .iOS(.v10),
    ],
    products: [
        .library(
            name: "RBSManager",
            targets: ["RBSManager"])
    ],
    dependencies: [
        .package(url: "https://github.com/daltoniam/Starscream.git", from: "3.1.1"),
        .package(url: "https://github.com/tristanhimmelman/ObjectMapper.git", from: "4.2")
    ],
    targets: [
        .target(
            name: "RBSManager",
            dependencies: ["Starscream", "ObjectMapper"],
            path: "./RBSManager/Classes")
    ]
)

我不知道你从哪里得到的只有你的错误信息,但它是不完整的。在 Terminal.app 中,如果您这样做 $> swift build,您将收到此错误:

$>swift build
/[...]/RBSManager-swift-package-manager: error: manifest parse error(s):
/[...]/RBSManager-swift-package-manager/Package.swift:21:39: error: expected ',' separator
            path: "RBSManager/Classes"
                                      ^
                                      ,
/Users/armel/Downloads/RBSManager-swift-package-manager/Package.swift:22:13: error: argument 'dependencies' must precede argument 'path'
            dependencies: []),

所以一个可能的解决办法是:

targets: [
    .target(
        name: "RBSManager",
        dependencies: [],
        path: "RBSManager",
        sources: ["Classes"])
]

然后,你会遇到另一个错误:

error: manifest parse error(s):
Invalid semantic version string '4.2'

所以 4.2.0 对于 ObjectMapper 实际上在 the repo.

我没有完全检查文件是否正确添加到包中,但更多的是解释如何调试问题并修复它。 sources/path 我设置的值可能不正确,如果需要我会让你调试那部分。