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

Created on 1 Nov 2019  Â·  18Comments  Â·  Source: Alamofire/Alamofire

What did you do?

I just updated to the non-beta version of Xcode 11.2. I opened a project I was working on and Xcode threw the error Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler. for Alamofire. I’m using Carthage as my package manager.

What did you expect to happen?

Since Swift 5.1, which has module stability, this shouldn’t be happening. Frameworks compiled with Swift 5.1 should work no problem with newer versions of Swift.

What happened instead?

I am getting an error Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.2 compiler. for Alamofire.

Alamofire Environment

Alamofire version: 4.9.1
Xcode version: 11.2 (11B52)
Swift version: 5.1.2
Platform(s) running Alamofire: iOS
macOS version running Xcode: 10.14.6 (18G103)

Demo Project

To reproduce: run carthage update --platform iOS on a project with Xcode 11.1 and then open the project in Xcode 11.2.

Possible solution

According to this stackoverflow question BUILD_LIBRARY_FOR_DISTRIBUTION = YES; has to be set in Alamofire’s project.pbxproj file.

feature request legacy

Most helpful comment

Alamofire will not be enabling module resiliency for actively developed versions due to the rather extreme restrictions it places on the library's evolution. However, it may make sense to enable it on v4, especially once we release v5. I'll keep this issue open to ensure we make that release when we release 5.0.0.

All 18 comments

Alamofire will not be enabling module resiliency for actively developed versions due to the rather extreme restrictions it places on the library's evolution. However, it may make sense to enable it on v4, especially once we release v5. I'll keep this issue open to ensure we make that release when we release 5.0.0.

Definitely feel this is needed ASAP on v4 versions of Alamofire.

Please fix it ASAP.

Just noting with Xcode 11.3

Module compiled with Swift 5.1 cannot be imported by the Swift 5.1.3 compiler.

Issue still exists with Xcode 11.4

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

What's the workaround? Setting BUILD_LIBRARY_FOR_DISTRIBUTION = YES; in Alamofire’s project.pbxproj file isn't working.

@kohlab This issue will always exist, it's how Swift's resiliency model works. The correct course of action is to recompile your dependencies with the new compiler. Alamofire will not be supporting library distribution mode, so it's dangerous to enable it yourself, since we don't guarantee compatibility and there are no build time diagnostics to ensure compatibility is maintained.

@kohlab This issue will always exist, it's how Swift's resiliency model works. The correct course of action is to recompile your dependencies with the new compiler. Alamofire will not be supporting library distribution mode, so it's dangerous to enable it yourself, since we don't guarantee compatibility and there are no build time diagnostics to ensure compatibility is maintained.

I'm getting the same issue with Xcode 11.4. What do you suggest us to do?

@thiagocenturion I suggest you do what I already suggested: recompile all of your dependencies with the same version of Xcode.

What worked for me -

  • Switch command-line tools to use the new version of Xcode in your Xcode preferences
  • Delete all files in the Carthage folder except the input file
  • Run Carthage update.
  • Delete derived data of the project
  • Clean and Build the project

Hope this helps!

What worked for me -

* Switch command-line tools to use the new version of Xcode in your Xcode preferences

* Delete all files in the Carthage folder except the input file

* Run Carthage update.

* Delete derived data of the project

* Clean and Build the project

Hope this helps!

@kinjaldua hello! could you please help me with the steps in more details (I mean how to do this exactly). Because I am the beginner and I am afraid to destroy my project with inexperienced actions.

I'm using SwiftPM (not Carthage), downgraded from 5.x to 4.9.1 because I read somewhere that v4 would eventually support Library Evolution (and that would be tracked on this issue), but still getting the warning:

Module 'Alamofire' was not compiled with library evolution support; using it means binary compatibility for...

Getting same issue with Xcode 12 Beta 4
Module compiled with Swift 5.2.4 cannot be imported by the Swift 5.3 compiler
I tried https://stackoverflow.com/questions/58654714/module-compiled-with-swift-5-1-cannot-be-imported-by-the-swift-5-1-2-compiler (BUILD_LIBRARY_FOR_DISTRIBUTION = YES;) but i didnt work.

Anyone has faced same issue ?

Getting same issue with Xcode 12 Beta 4
Module compiled with Swift 5.2.4 cannot be imported by the Swift 5.3 compiler
I tried https://stackoverflow.com/questions/58654714/module-compiled-with-swift-5-1-cannot-be-imported-by-the-swift-5-1-2-compiler (BUILD_LIBRARY_FOR_DISTRIBUTION = YES;) but i didnt work.

Anyone has faced same issue ?

Yes I am also facing the similar issue

Getting same issue with Xcode 12 Beta 4
Module compiled with Swift 5.2.4 cannot be imported by the Swift 5.3 compiler
I tried https://stackoverflow.com/questions/58654714/module-compiled-with-swift-5-1-cannot-be-imported-by-the-swift-5-1-2-compiler (BUILD_LIBRARY_FOR_DISTRIBUTION = YES;) but i didnt work.

Anyone has faced same issue ?

I also got stuck there. Does anybody resolve this case?

I have Xcode 12 Beta, Alamofire 4.9.0, BUILD_LIBRARY_FOR_DISTRIBUTION == NO, and get "Module compiled with Swift 5.2.4 cannot be imported by the Swift 5.3 compiler". So, what is the best way to resolve this issue?

Xcode 12 GM. Same problem as above.

@ss-alex

  • Command line tools: Go to Xcode Preferences > Locations and select the "command line tools" for Xcode 12.x, from the drop down menu. Remember to set it back to Xcode 11.x afterwards if you plan to e.g. run Carthage on a different project that is build with Xcode 11 (this setting is global, so it applies across all versions of Xcode that you may have installed):

Screen Shot 2020-09-17 at 19 34 09

  • Delete Carthage 1: Delete the folder Carthage in your project folder. This folder contains the checked-out sources as well as the build products (binaries) of your dependencies.
  • Delete Carthage 2: Delete the Cartfile.resolved file, but keep the (source) Cartfile.
  • Delete derived data: On the same Preferences > Location window, click the small gray circle with an arrow after the path to the Derived Data folder:

Screen Shot 2020-09-17 at 19 34 09 2

This will take you to the enclosing directory in Finder, so you can delete the Derived Data folder. Xcode will re-create it anew, right away. After doing this, all Swift Package caches are cleared so you if your project uses SwiftPM, you need to re-donwload them with File > Swift Packages > Update to Latest Package Versions

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anilios picture anilios  Â·  27Comments

michalkos picture michalkos  Â·  30Comments

Isuru-Nanayakkara picture Isuru-Nanayakkara  Â·  21Comments

moritzsternemann picture moritzsternemann  Â·  39Comments

AnthonyMDev picture AnthonyMDev  Â·  37Comments