Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler

我们两清 提交于 2019-12-17 18:11:18

问题


I have a framework (in this instance it's RxSwift) which I've compiled using Xcode 11.0 into the traditional RxSwift.framework style package

This imported fine into Xcode 11.0 and also 11.1 never had any problems with it

Today, upon Apple's release of Xcode 11.2, I upgraded, and I am presented with the error:

Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler

I'm used to swift compiler mismatches, and I'm aware I can just recompile RxSwift using Xcode 11.2 and carry on, but the headline feature of Swift 5.1 was module stability.

I was under the impression that now that we have module stability, frameworks won't need to keep getting recompiled with every new Xcode release, yet this is clearly not the case.

If anyone can explain what is going on here I would much appreciate it. Is Xcode 11.2 exhibiting a bug? or did I somehow need to tell it I wanted module stability when I originally compiled with Xcode 11.0?


回答1:


OK, Turns out if you watch the WWDC video, they explain it: https://developer.apple.com/videos/play/wwdc2019/416/

You need to set the Build Libraries for Distribution option to Yes in your framework's build settings, otherwise the swift compiler doesn't generate the neccessary .swiftinterface files which are the key to future compilers being able to load your old library.

This ends up in your project.pbxproj file as:

BUILD_LIBRARY_FOR_DISTRIBUTION = YES;

After setting this flag, a framework I compiled using Xcode 11.0 (swift 5.1) was able to be compiled with Xcode 11.2 (swift 5.1.2) and everything appears to be working correctly.

Hopefully this question/answer will serve as a useful reference for everyone who hasn't watched all the WWDC videos




回答2:


I started seeing the same issue and found out that I was using the incorrect xcode Command Line Tools. Went to Preferences > Locations and changed the command line tools from Xcode 11.1 to 11.2.1. Just to be safe, I also cleared the derived data directory and ran carthage build.




回答3:


I had the same error importing 3rd party libraries. I fixed it using toolchains in Xcode and taking the release September 19 2019 from here https://swift.org/download/#releases. After that I had to re-import my libraries and it worked.




回答4:


You can use Carthage to add the RxSwift framework.

Basically, Carthage gives you a similar traditional RxSwift.framework style package.

Then try carthage update --no-use-binaries.



来源:https://stackoverflow.com/questions/58654714/module-compiled-with-swift-5-1-cannot-be-imported-by-the-swift-5-1-2-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!