Alamofire: Module compiled with Swift 4.2.1 cannot be imported by the Swift 5.0

Created on 1 Apr 2019  ·  18Comments  ·  Source: Alamofire/Alamofire

carthage 已经改为 github "Alamofire/Alamofire" "5.0.0-beta.3"
并在终端执行 carthage update --no-use-binaries --platform mac,ios
然而打开项目依然报错如下:

Module compiled with Swift 4.2.1 cannot be imported by the Swift 5.0 compiler: /Users/......./Carthage/Build/iOS/Alamofire.framework/Modules/Alamofire.swiftmodule/x86_64.swiftmodule

请问如何解决???

support

Most helpful comment

I'm having almost the exact the same issue:

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

at import Alamofire. I deleted Derived Data, Carthage build directory, cleaned build folder, etc.

My project is still set to Swift 4.2 and builds OK with Xcode 10.1, but I'm trying to migrate it to the latest Xcode version (10.2.1).


Wait, I'm still on Alamofire 4.8; compatibility with Xcode 10.2 seems to have been added since 4.8.2. Updating now...


Nope, still happening with 4.8.2...


Update: Silly me, I still had Xcode 10.2 use the command line tools for Xcode 10.1 (which I have installed side-by-side, before I'm able to fully migrate). So carthage was building the 4.8.2 Alamofire checkout using the (old) Xcode 10.1 compiler.

After changing to the 10.2 tools, it compiles without problem:

Screen Shot 2019-04-22 at 14 04 17

All 18 comments

Running into the same issue, have tried the fixes suggested in this post, but with no success.

https://stackoverflow.com/questions/46726077/module-compiled-with-swift-4-0-cannot-be-imported-in-swift-4-0-1

You'll need to recompile all of your dependencies with the same version of the compiler.

Would you please list the details of how TO DO recompile all the dependencies for the new compiler swift 5.0?

@softdev999 Clean All -> Build.

现在已经可以了,谢谢大家

I'm having almost the exact the same issue:

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

at import Alamofire. I deleted Derived Data, Carthage build directory, cleaned build folder, etc.

My project is still set to Swift 4.2 and builds OK with Xcode 10.1, but I'm trying to migrate it to the latest Xcode version (10.2.1).


Wait, I'm still on Alamofire 4.8; compatibility with Xcode 10.2 seems to have been added since 4.8.2. Updating now...


Nope, still happening with 4.8.2...


Update: Silly me, I still had Xcode 10.2 use the command line tools for Xcode 10.1 (which I have installed side-by-side, before I'm able to fully migrate). So carthage was building the 4.8.2 Alamofire checkout using the (old) Xcode 10.1 compiler.

After changing to the 10.2 tools, it compiles without problem:

Screen Shot 2019-04-22 at 14 04 17

Thanks for posting all the details @nicolas-miari. Hopefully this will help others that run into the same issue. 🍻

just clean and rebuild

@nicolas-miari, thanks for logging details of your debugging process, it really helps and works for me by changing the xcodebuild tool version.

In my case, I was migrating from Swift 4.2 -> Swift 5.0, Xcode 10.2 to Xcode 11 beta.

I guess if there is any problem, one can rebuild all the dependencies forcefully

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

Navigate to Project Path from terminal and enter the below command

touch Cartfile

open -a Xcode-beta Cartfile (Using Xcode beta version.)

File will opened in Xcode ,give the below command and close it

github “SwiftyJSON/SwiftyJSON” ~> 4.0

Give the below command in terminal

carthage update --platform tvOS

SwiftJSON.framework will be created under project folder > Carthage > Build > SwiftJSON > tvOS > SwiftyJSON.framework for Swift 5.1

Now delete the previously create SwiftJSON.framework from the project folder and copy paste the above mentioned SwiftJSON.framework.

Change the Swift Compiler - Language to Swift 5 in Xcode - Build Settings

Clean the build and run the project

Thank to InfinityCode777 after the carthage update --platform iOS --no-use-binaries it works! :D

After macOS Catalina upgrade I was seeing:

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

This solved it for me!

  1. Clean Build Folder
  2. Rebuild project dependencies
carthage update --platform iOS
  1. Update Swift compiler version

    • Select your target, then in your Build Settings, search for "swift language" and then you will find Swift Language Version.

    • Select Swift 5

  2. Build and Run app

    • choose a scheme and a run destination in the workspace toolbar

    • click the Run button

@nicolas-miari, thanks for logging details of your debugging process, it really helps and works for me by changing the xcodebuild tool version.

In my case, I was migrating from Swift 4.2 -> Swift 5.0, Xcode 10.2 to Xcode 11 beta.

I guess if there is any problem, one can rebuild all the dependencies forcefully

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

it works for me at xcode11. migrate from Swift4.2 -> Swift5.1

Just remove all the *.framework folders, fetch and generate then just Import the new framework folders to your project.
That's what helped me.

xxx/Carthage/Checkouts/Moya/Carthage/Build/iOS/Alamofire.framework/Modules/Alamofire.swiftmodule/arm64.swiftmodule
import Alamofire
       ^

iOS 14, Xcode 12.1

@29satnam
where is the files?

Look for them in the Carthage build folder

Was this page helpful?
0 / 5 - 0 ratings