Swift Version Conflict: this SDK is not supported by the compiler - using BUILD_LIBRARY_FOR_DISTRIBUTION setting. What could be the issue?

Viewed 1353

I'm building a Swift static library with:

  • Xcode 13.2 (Swift compiler 5.5.2)
  • iOS Deployment target 12.0
  • Build library for distribution YES
  • Skip install NO
  • Swift language version 5 and tried with 4.2 Dependency managed with CocoaPods:
  • Japx 3.0.0
  • Alamofire 5.2.2
  • RxSwift

When I try to add it to an iOS project with this setup:

  • Xcode 13.3 (Swift compiler 5.6)
  • iOS Deployment target 12.0
  • Swift language version 5 and tried with 4.2 and build I get this error:
Failed to build module 'LibraryX'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.5.2 effective-4.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)', while this compiler is 'Apple Swift version 5.6 effective-4.2 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)'). Please select a toolchain which matches the SDK.

These are the headers in the .swiftinterface

// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.5.2 effective-4.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
// swift-module-flags: -target arm64-apple-ios12.0 -enable-objc-interop -enable-library-evolution -swift-version 4.2 -enforce-exclusivity=checked -Onone -module-name LibraryX

Obviously if I build the project with the same compiler version or building the library with the iOS project everything works fine. But the purpose here is to release a precompiled library and not its source code.

Every time that I lookup this error online I've found "You have to set Build library for distribution to Yes"

I tried to add the source code of the static library to a new Framework project, but I get the same result.

1 Answers

I also had this error, in my case it was unable to import a sub-dependency of my XCFramework during reading .swiftinterface file, however was showing this absolutely misleading error.

After repeatedly cleaning up DerivedData and trying different Xcode versions (13.0, 13.4.1) I've seen 2 errors: "this SDK is not supported by the compiler", and "No module named 'AnotherLib'" which was an incorrectly specified dependency inside of my Swift Package.

So, maybe only first part of the message is correct "Failed to build module 'LibraryX'", but the reason is something else, NOT the difference in compiler versions.

Related