简体   繁体   English

XCFramework's.swiftinterface 在使用 Swift Package Manager 导入时会中断编译

[英]XCFramework's .swiftinterface breaks compile when imported with Swift Package Manager

Created a Swift Package (// swift-tools-version:5.3.0) for an XCFramework.为 XCFramework 创建了 Swift Package (// swift-tools-version:5.3.0)。 The package has dependencies on 4 other Swift packages (2 of them using swift-tools-version < 5 and 2 are >= 5.0). package 依赖于其他 4 个 Swift 包(其中 2 个使用 swift-tools-version < 5 和 2 >= 5.0)。 It builds and runs in the project's Demo app target.它在项目的 Demo 应用程序目标中构建和运行。 The generated XCFramework copied into a Swift Package repo and hosted on GitHub.生成的 XCFramework 复制到 Swift Package 存储库并托管在 GitHub 上。

I then create a new project and the Swift Package can be successfully imported into it thru SPM.然后我创建一个新项目,Swift Package 可以通过 SPM 成功导入。 The dependencies are also imported.依赖项也被导入。

When building the new project, my framework fails to compile due to an error in my framework's generated.swiftinterface file, 'XMLIndexerDeserializable' is not a member type of 'SWXMLHash':在构建新项目时,由于框架的 generated.swiftinterface 文件中的错误,我的框架无法编译,“XMLIndexerDeserializable”不是“SWXMLHash”的成员类型: “XMLIndexerDeserializable”不是“SWXMLHash”的成员类型

Can anyone shed some light on this failure?谁能解释一下这个失败? Not sure if it an issue with my packaged framework, a config issue with the new project that imports it, or an error due to the difference in the Swift tools version of the dependencies.不确定这是我打包的框架的问题,导入它的新项目的配置问题,还是由于依赖项的 Swift 工具版本的差异而导致的错误。

Some Background Details On My Config and Process我的配置和流程的一些背景细节

My Swift Package config:我的 Swift Package 配置:

// swift-tools-version:5.3.0
import PackageDescription
let package = Package(
    name: "MyPackage",
    platforms: [
        .iOS(.v9)
    ],
    products: [
        .library(
            name: "MyPackage", 
            targets: ["MyPackage"])
    ],
    dependencies: [
        .package(name: "CryptoSwift", url: "https://github.com/krzyzanowskim/CryptoSwift", .upToNextMinor(from: "1.2.0")),
        .package(name: "Alamofire", url: "https://github.com/Alamofire/Alamofire", .upToNextMinor(from: "4.8.2")),
        .package(name: "AEXML", url: "https://github.com/tadija/AEXML", .upToNextMinor(from: "4.4.0")),
        .package(name: "SWXMLHash", url: "https://github.com/drmohundro/SWXMLHash", .upToNextMinor(from: "4.9.0"))
    ],
    targets: [
        .binaryTarget(
            name: "MyPackage",
            path: "MyPackage.xcframework")
    ]
)

Watched the WWDC 2019 and 2020 sessions on building XCFrameworks/binaries for SPM, along with other various tutorials.观看了关于为 SPM 构建 XCFrameworks/二进制文件的 WWDC 2019 和 2020 会议,以及其他各种教程。 Used the following sh script to build the XCFramework that would be used for my hosted Swift Package:使用以下 sh 脚本构建将用于我托管的 Swift Package 的 XCFramework:

xcodebuild archive \
  -scheme MyPackage \
  -sdk iphoneos \
  -archivePath "./XCFrameworkArchives/ios_devices.xcarchive" \
  BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
  SKIP_INSTALL=NO
  
xcodebuild archive \
  -scheme MyPackage \
  -sdk iphonesimulator \
  -archivePath "./XCFrameworkArchives/ios_simulators.xcarchive" \
  BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
  SKIP_INSTALL=NO

xcodebuild -create-xcframework \
  -framework ./XCFrameworkArchives/ios_devices.xcarchive/Products/Library/Frameworks/MyPackage.framework \
  -framework ./XCFrameworkArchives/ios_simulators.xcarchive/Products/Library/Frameworks/MyPackage.framework \
  -output ./XCFrameworkArchives/MyPackage.xcframework

The XCFramework is copied into my Swift Package repo, pushed up to GitHub and tagged. XCFramework 被复制到我的 Swift Package 存储库中,推送到 GitHub 并标记。

I then created a new project, used SPM to add a dependency and pulled in MyPackage along with it's dependencies.然后我创建了一个新项目,使用 SPM 添加一个依赖项,并将 MyPackage 连同它的依赖项一起拉入。

Add code to import MyPackage and make use of it.添加代码以导入 MyPackage 并使用它。 Attempt to build the project throws the compile error that lead me to ask for help.尝试构建项目会引发编译错误,导致我寻求帮助。 If you can help and need more info, happy clarify and provide more info if I can.如果您可以提供帮助并需要更多信息,请尽可能澄清并提供更多信息。

I manually edited the.swiftinterface files generated in the XCFramework for both the device and simulator versions.我为设备和模拟器版本手动编辑了在 XCFramework 中生成的 .swiftinterface 文件。 I simply replaced all occurrences of the framework's name from those files.我只是从这些文件中替换了所有出现的框架名称。 So changing, SWXMLHash.XMLIndexerDeserializable -> XMLIndexerDeserializable solved the issue for me.如此变化, SWXMLHash.XMLIndexerDeserializable -> XMLIndexerDeserializable为我解决了这个问题。

Also, look at the latest comments to my question, this looks like a known issue.另外,请查看对我的问题的最新评论,这看起来像是一个已知问题。 Going through some of those links and bug issues, my solution common, but is not the "recommended" solution.通过其中一些链接和错误问题,我的解决方案很常见,但不是“推荐”解决方案。 Recommendation is to not name your framework the same as the classes within.建议不要将您的框架命名为与其中的类相同的名称。 In my situation, it is a Swift package dependency I imported, so I don't have control over that.在我的情况下,它是我导入的 Swift package 依赖项,所以我无法控制它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM