Module compiled with Swift 4.0 cannot be imported in Swift 4.0.1 - ios

However I have recompiled the framework using the same Xcode and it still gives me this error.
Base SDK iOS 11.1 for both
Swift Language Version Swift 4.0 for both
Not using Pods/Carthage
I hope someone might know

Update:
For release versions of Xcode:
This error (and similar errors involving Swift 4.1, 4.2, etc.) will occur when opening a project with Xcode 9.1, 9.2, 9.3, 9.4, 10, etc. that uses frameworks that were built with earlier Xcode tools.
To fix the issue, update and rebuild your frameworks using Carthage ( carthage update --platform iOS), Cocoapods (pod update or pod install), or manually, with the new updated Xcode tools. The tools should be updated automatically when you update Xcode, but if not, you can follow the steps outlined below in the original answer.
You may also need to clean your project cmd + shift + k and possibly your build folder cmd + option + shift + k to get Xcode to not use cached framework builds.
In some cases you may also need to delete your derived data folder (Easily found by going to Xcode Preferences -> Locations -> Derived Data Folder
(Thanks Stunner)
For beta versions of Xcode:
See original answer below and then follow steps above.
Original Answer:
You probably still have your xcodebuild tools set to Xcode 9.0 which builds with Swift 4.0 and is incompatible with Xcode 9.1 beta's Swift 4.0.1.
Check in the terminal using the command:
xcodebuild -version
Or just go into Xcode preferences -> Locations and check/change the command line tools to Xcode 9.1. You should be set then.

My issue was due to an external framework not being compiled for Swift 4.0.2. I had added this file via Carthage, so running:
carthage update --platform iOS
And then cleaning the project cmd + shift + k and build folder cmd + option + shift + k and deleting the derived data folder (merely moving it to trash works as well) worked for me.

In my case, I downloaded xCode 11 Beta version to test SwiftUI. When i run my project, i got "Module compiled with Swift 5.1 cannot be imported by the Swift 5.0.1 compiler:..." error.
To do fix this issue. i changed xCode command line tool to new xCode 11 comment line tool. After that, you can create new xcode project with SwiftUI.
Xcode -> Preferences -> Location -> XCode command Line Tool
i hope, this will help someone who want to test with new freamework :)

Install Xcode Toolchain of specific Xcode version which was working for you from here.
An Xcode toolchain includes a copy of the compiler, lldb, and other related tools needed to provide a cohesive development experience for working in a specific version of Swift.
Open Xcode's Preferences, navigate to Components > Toolchains , and select the installed Swift toolchain.
This will let you compile and run the app for now.

I hit this issue with Xcode 10 beta, which adds Swift 4.2. My issue was unrelated to Carthage or any external dependencies.
Go to YourTarget > Build Settings > Swift Language Version for all of your Xcode targets.
Mine were all set to Swift 4.
After adding a Copy Files Build Phase, I started getting the error
:0: error: module compiled with Swift 4.1.2 cannot be imported by the Swift 4.2 compiler: /Users/user/Library/Developer/Xcode/DerivedData/MyApp-faskfrihumfcdibjxisjvbfshppp/Build/Intermediates.noindex/MyApp.build/Debug/MyAppExtension.build/Objects-normal/x86_64/MyClass~partial.swiftmodule
Command MergeSwiftModule failed with a nonzero exit code
I then set each target's Swift Language Version to Swift 4.2, which eliminated the error.
I'm not sure why the error was occuring in the first place, though, as having all targets set to Swift 4 should be equally as valid.

In my case (Xcode 9.2):
I went to Xcode Preferences > Locations > Derived Data
I then deleted the data and did a clean build and was ok.

In my case, I used CocoaPods with plugin cocoapods-binary to prebuild libraries to binaries. After I upgrade Xcode from 10 to 11, Xcode gives me this error:
Module compiled with Swift 5.0.1 cannot be imported by the Swift 5.1 compiler
I fix it by removing the /Pods directory and running pod install.

In my case, I re-compiled the framework with whatever version it was complaining about.
To recompile, run pod update or update the carthage (which ever one you're using), and build the project.
Then search for the framework in finder. Copy-paste the theFramework.framework to your project and make sure to "Copy items if needed."Build the project again and it should work.

Related

Is Mapbox Navigation compatible with Swift 5.0

Can anyone confirm that Mapbox Navigation works with Swift 5.0 or for that matter they are still a going concern? I have now tried building the frameworks in Carthage using Xcode 11.3 and a fresh install of Xcode 11.6 on a brand new Mac running the latest OS and in both cases when trying to import framework:
Module compiled with Swift 4.2.1 cannot be imported by the Swift 5.2.4 compiler:
According to some answers to this SO question, this happens when Developer has not yet released their app for Swift 5, although the Mapbox changelog claims they have
Have tried contacting Mapbox through every conceivable channel and radio silence. Hopefully they are still in business and supporting the software but I'm not sure.
Module compiled with Swift 4.2.1 cannot be imported by the Swift 5.1.3
compiler:
/Users/M/Desktop/War/idaru/MapboxCoreNavigation.framework/Modules/MapboxCoreNavigation.swiftmodule/arm64.swiftmodule
This error appears because you still have a built copy of MapboxCoreNavigation on your system and Xcode is linking against it instead of building from scratch. It’s always necessary to do a clean build when upgrading Xcode.
If you encounter this error message within Xcode when building your application target, please clean your build products using Product ‣ Clean Build Folder and build again. If you're seeing this error on the command line when running carthage update, you can try cleaning your Carthage caches using the following command:
rm -rf ~/Library/Caches/carthage/ ~/Library/Caches/org.carthage.CarthageKit/binaries/

Xcode 11 Beta and Carthage bootstrap

I'm trying to compile my project with Xcode 11. If I build the project I get this message:
Module compiled with Swift 5.0 cannot be imported by the Swift 5.1
I tried to rebuild dependencies running carthage bootstrap but I'm getting another error message from carthage:
Unable to determine local Swift version.
Which is the best flow to run Apps built with swift 5 on Xcode 11 beta? (taking into account that I'm using carthage as dependency manager?)
Open Xcode and goto Preferences. Now select the tab Locations and select Xcode 11.0 in the dropdown menu at Command Line Tools. Afterwards run Carthage again and the project should build in Xcode beta.
you need to select the default version of XCode,
to do that just open Terminal and write this :
$ sudo xcode-select -s <path/to/>Xcode.app
make sure you put the exact path to the desired version of XCode,
or simply drag and drop it on terminal.

Xcode 10 - Module compiled with Swift 4.1.2 cannot be imported by the Swift 4.2 compiler

Existing project working in Xcode 9.3 and suddenly giving error in Openpay Framework while run in Xcode 10 (not beta version).
My swift version is 4.2, if i changed to Swift 4 or Swift 3 then also same error.
I have tried following things but not worked..
pod file update
clean and build project
delete derived data and clean-build project
quit xcode. open again, clean and build.
sudo xcode-select -switch /Applications/Xcode.app
carthage update --platform iOS --no-use-binaries
You are adding Openpay.frameworkin your project (using the link from their readme). The framework is built using Xcode 9.4 - you can check it in Info.plist file inside framework (just open it as folder). Here you have several options - ask them to release new version or do it yourself - looks like it is open source library, so you can clone it and build the framework yourself using Xcode 10

Module compiled with Swift 4.1.2 cannot be imported by the Swift 4.2 compiler

Short story: Xcode 10 is set to Swift 4, but it is using Swift 4.2.
Long story: Our project is not ready for Swift 4.2, since our dependent frameworks are not Swift 4.2, yet. But, I would like to, at least, use Xcode 10.
I have Xcode 9.4.1 and Xcode 10 installed.
I have Command Line Tools set to use Xcode 9.4.1:
In Xcode 10, I have the project setting, Swift Language Version, set to
Swift 4.
I have verified on the command line the Swift version the shell is
using is 4.1.2:
"swift --version Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)"
I've run carthage update.
I've quit Xcode 10 and relaunched.
I have deep cleaned and deleted Derived Data.
I build and I get this error:
"Module compiled with Swift 4.1.2 cannot be imported by the Swift 4.2
compiler:
.../App/Carthage/Build/iOS/RealmSwift.framework/Modules/RealmSwift.swiftmodule/arm64.swiftmodule"
To me, this indicates that I have my intended Swift version (4.1.2) set correctly and Xcode is still trying to use the wrong version of Swift (4.2).
Does anyone have suggestions on how to resolve this? Am I missing something? Xcode bug?
I'm not positive, but my guess is that this is the reason:
I have Command Line Tools set to use Xcode 9.4.1
You have to recompile your Swift 4 dependencies using Xcode 10, because Swift is not ABI-stable, i.e. binaries compiled with different compiler versions are not compatible. And even Swift 4.0 binaries compiled with different versions of Xcode may not be compatible.
I don't have much experience with Carthage, but my guess is that you should use Xcode 10 as a command-line tool, but you have to set a different Swift language version to be used by Xcode 10. It should probably be specified in the project (in this case RealmSwift), or using environment variables, but you'll need someone else to answer with more details, I'm afraid.
Using Realm with Xcode 10 requires building it from source. In Terminal write:
git clone --recursive https://github.com/realm/realm-cocoa.git
cd realm-cocoa
sh build.sh ios-swift
you can use multiple swift toolchains. download url swift toolchain download after you install some version. restart your xcode, in xocde menu you can see toolchains option.
I had the same problem and then I realised I had not selected Xcode 10 as my Xcode. Try:
sudo xcode-select -s /Applications/Xcode10.app
Also, if you will be switching between Xcode9 and 10, I recommend you the following: If you change from 9 to 10, run mv Carthage Carthage9 and then rebuild Carthage. Whenever you want to switch back, move Carthage to Carthage10 and do mv Carthage9 Carthage. This will save you lots of time building.

Swift does not support the SDK 'iPhoneSimulator9.3.sdk'?

I have just installed the xcode 8.0 and upgrade my project to swift 3. I was using swift 2.2 and xcode 7.3.1.
But getting following error:
Swift does not support the SDK 'iPhoneSimulator9.3.sdk'
Command
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc
failed with exit code 1
This happened to me when I had simultaneously installed both Xcode 7 and 7.3 and after automatic update I was left with 8.0 only.
One indication that something got messed up was output of xcodebuild -sdk -version in terminal:
DVTSDK: Warning: SDK path collision for path '<DVTFilePath:0x7fd810db4c50:'/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS3.0.sdk'>': SDK with name 'watchos3.0' being superceded by SDK with 'watchos3.0'.
Solution:
Quit Xcode
go to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
remove the iPhoneOS9.3.sdk folder from that directory. Be sure to make an external copy if you still need it so you can put it back later.
restart Xcode, clean, and build
???
PROFIT
UPDATE:
According to #tsafrir comment, delete also 'iPhoneOS9.3.sdk' for simulator folder:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhon‌​eSimulator.platform/‌​Developer/SDKs
The iPhoneOS9.3.sdk for the simulator is at Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs.
quit xcode
delete
clean
build again.
Not the best solution, but selecting - "Use Legacy Compiler Version": Yes, removed that warning for me.
It happen due to old xcode still in system and you updated new one.
For fixing this use following step.
Quit Xcode
go to
Simulator and iPhoneOS. platform
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
3. remove the iPhoneOS9.x.sdk folder from that directory. Be sure to
make an external copy if you still need it so you can put it back
later.
Copy old xcode sdk (iPhoneOS9.x(Updated SDK))
Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/ iPhoneOS9.3(Updated SDK)
5> Paste this SDK in new XCODE 8 in this folder
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
6> Clean and Build.
Fixed
Open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs

Resources