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

27,505

Solution 1

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.

Solution 2

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

Solution 3

The provider of this library should rebuild it with BUILD_LIBRARY_FOR_DISTRIBUTION = YES; (available in Xcode 11.3 in Build Settings -> Build Options). Already asked to do it in the corresponding GitHub issue. After that PaytmNativeSDK will be compatible with every next Swift version.

It looks like the issue has been fixed in 804152caae76245d96548eb74ea87a6150239407.

Solution 4

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.

Solution 5

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.

Share:
27,505
appbootup
Author by

appbootup

I am a "bit" Geek and Nerd. I am professionally involded in Coding using Java/GWT/Angular/Adroid/Golang/Python/Hibernate/Javascript/HTML/CSS/Material Design... I am a consultant partner @ appbootup and @ equibot I was a co-founder @ Talentspear You can find me @ my tech blog , StackCareers, Linked-in profile and GitHub account. My non tech videos http://www.youtube.com/watch?v=cIAF4iDei2s http://www.youtube.com/watch?v=mq_CYdPb7E8 Apart from tech world , I am personally interested in Agriculture Renewable Energy Photography/Photo Editing Video/Audio Editing My interests vary from season to season. I read a lot on "Current Affairs" topics , Wars, Civilization , Economics and just about anything.

Updated on July 02, 2020

Comments

  • appbootup
    appbootup almost 4 years

    I am trying to implement integration of third party app into project as per instruciton https://github.com/Paytm-Payments/Paytm_iOS_App_Kit/tree/master/Swift/BitCodeDisabled/PaytmNativeSDK

    I see the following error in build

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

    I have tried toolchains https://medium.com/xcblog/switching-swift-versions-inside-xcode-using-toolchains-755b28831c43 The error changes to Reason: Incompatible library version: PaytmNativeSDK requires version 1.0.0 or later, but libswiftCore.dylib provides version 0.0.0

    How do i setup XCode or the Library to make it work . There is no chance of the vendor updating the library for Swift 5.0 and make it available on POD.

  • Alex Choi
    Alex Choi over 5 years
    this answer is more correct if you are on swift 4 and still have xcode10.1. there really isn't a good reason for you to have to rebuild your dependencies in swift 5 if your project is in swift 4.
  • Swift Rabbit
    Swift Rabbit over 5 years
    Is this considered a bug? Was it reported to Apple? Should the Swift 5.0 compiler be able to import 4.2.1 compiled frameworks?
  • droledenom
    droledenom about 5 years
    Am I wrong : If you use Xcode 10.1 you won't be compatible with iOS 12.2, no ?
  • Kishore Kumar
    Kishore Kumar about 5 years
    What is no-use-binaries means ?
  • Dan Rosenstark
    Dan Rosenstark about 5 years
    Google brought me here @KishoreKumar stackoverflow.com/questions/41442601/…