Module compiled with Swift 4.2.1 cannot be imported by the Swift 5.0 compiler

北城余情 提交于 2019-11-28 06:16:52

For Carthage users: After upgrading to Xcode 10.2, I ran into this same issue with a framework that I had been importing using Carthage.

I resolved it by rebuilding the framework:

carthage update --no-use-binaries --platform iOS

The correct solution is download Xcode 10.1, and wait for Apple patch the bug fix.

Don't waste time on fix third-party bug.


The problem of my project is we are using Alamofire which is failed to update by Carthage.

I wanted to use Swift 4.2 (which Xcode 10.2 should still support, I've set it in Swift Language Version), but it still gave me an error about the Swift 5.0 compiler. So after trying to clear everything like build folder, derived data and stuff, I came to the conclusion that it does not work on Xcode 10.2.

I reverted back to Xcode 10.1 which you can download here. This works. So until Apple fixes this bug I am forced to stay on Xcode 10.1.

This will happen if you have external libraries in your project thats still built using 4.2 compiler, whereas the new Xcode tries building your project in 5.0 compiler.

In my case, I had few libraries imported using Carthage. Luckily the libraries that I have used have released an updates in the past few days making it compatible with Swift 5.0 compilers. If those external libraries haven't updated it to support Swift 5.0 you may be out of luck for now.

On the way you might still face few issues and here are some best practices to avoid further issues.

  1. Remove the cartfile.resolved and Carthage folder completely
  2. Ensure you remove any copy of the libraries added to your project earlier.
  3. Remove the embedded libraries and Linked frameworks and libraries from your Targets> Yourapp > General .
  4. Product > Clean build folder
  5. Update the Cart file and fetch the new sources using the Carthage update command
  6. Now import the libraries back to your project.

Hopefully it works.

The developers of the framework need to provide an update, which is built in Xcode 10.2.

Explanation for framework developers:
Even if you created the framework in Xcode 10.2 or with the default version used by CI, your users may still encounter such an error. You should make sure that Xcode 10.2 is your default command line tool. You can check it in terminal with the command xcodebuild -version. Default version can be adjusted in Xcode -> Preferences -> Locations -> Command Line Tools.

My problem with Carthage was related to the xcode phase that copys binaries in "carthage copy-frameworks" phase.

I've a slightly different solution to the one commented in https://stackoverflow.com/a/55362536/721929, because that solution also updates dependencies versions in some cases.

So, I just executed "carthage build". I also include a cache clean for Carthage, to fix possible errors in subtasks (in my case, failing in git clone with "exit code 1")

rm -rf ~/Library/Caches/org.carthage.CarthageKit
carthage build --no-use-binaries --platform iOS --verbose
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!