错误:不支持将桥接标头与模块接口一起使用命令 CompileSwiftSources 失败,退出代码非零

Saz*_*han 3 xcode xcodebuild ios xcframework xcode12

我已切换到Xcode12我的静态库应用程序之一。我正在尝试制作 XCFramework 发行版。运行构建命令后,

\n
xcodebuild archive -scheme "MySDK" -sdk iphoneos  -archivePath \xe2\x80\x9c./archives/ios.xcarchive\xe2\x80\x9d -SKIP_INSTALL=NO\n
Run Code Online (Sandbox Code Playgroud)\n

Build Settings -> Build Libraries for Distribution当我切换到时出现以下错误YES

\n
<unknown>:0: error: using bridging headers with module interfaces is unsupported\nCommand CompileSwiftSources failed with a nonzero exit code\n\n** ARCHIVE FAILED **\n\n\nThe following build commands failed:\n    CompileSwiftSources normal armv7 com.apple.xcode.tools.swift.compiler\n    CompileSwiftSources normal armv7s com.apple.xcode.tools.swift.compiler\n    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler\n(3 failures)\n
Run Code Online (Sandbox Code Playgroud)\n

这个答案有效,但不幸的是创建.xcframework需要设置选项 distribution YES

\n

如何解决这个问题?

\n

joh*_*he4 6

Apple 似乎不赞成使用桥接标头,转而使用模块,但他们缺少有关如何包含 C 标头的文档。这些信息可以在更详细的clang 文档中找到。

尝试从项目设置中删除桥接头并创建一个module.modulemap文件:

module MySdk {
   header "MySdk-Bridging-Header.h"
   export *
}
Run Code Online (Sandbox Code Playgroud)

这有一些警告,例如需要import MySdk在你的 swift 代码中并理解 C 函数将被公开,但它让我克服了困难。

我通过反复试验发现的一个技巧是将此模块映射文件和 C 头文件包含在框架的文件Headers夹中。这允许使用该框架的任何应用程序自动检测MySdk为模块。