error: using bridging headers with module interfaces is unsupported Command CompileSwiftSources failed with a nonzero exit code

3.8k views Asked by At

I have switched to Xcode12 for one of my static library apps. I am trying to make XCFramework distribution. After running build command,

xcodebuild archive -scheme "MySDK" -sdk iphoneos  -archivePath “./archives/ios.xcarchive” -SKIP_INSTALL=NO

I am getting below error when I switched Build Settings -> Build Libraries for Distribution to YES,

<unknown>:0: error: using bridging headers with module interfaces is unsupported
Command CompileSwiftSources failed with a nonzero exit code

** ARCHIVE FAILED **


The following build commands failed:
    CompileSwiftSources normal armv7 com.apple.xcode.tools.swift.compiler
    CompileSwiftSources normal armv7s com.apple.xcode.tools.swift.compiler
    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(3 failures)

This answer works but unfortunately creating .xcframework requires to set the option distribution YES.

How to resolve this issue?

1

There are 1 answers

0
johnhe4 On BEST ANSWER

Apple seems to be deprecating bridging headers in favor of modules, but their documentation regarding how to include C headers is missing. The information is instead found in the more detailed clang docs.

Try removing the bridging header from the project settings and instead create a module.modulemap file:

module MySdk {
   header "MySdk-Bridging-Header.h"
   export *
}

This has caveats, such as needing to import MySdk in your swift code and understanding that C functions will be exposed, but it got me over the hump.

One trick I discovered by trial and error is to include this modulemap file and C headers in the framework's Headers folder. This allows any app consuming the framework to automatically detect MySdk as a module.