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

8

37

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.

Ruelas answered 26/3, 2019 at 8:47 Comment(15)
Use it manually by copy paste-ing the framework and making it compatible for Swift 5. Since you said the vendor won't update it, you might as well do it like this.Imbalance
Swift doesn't have ABI stability prior to Swift 5, so you will need to use Swift 4.2.1 for your project until the vendor releases an updated framework; Change the Swift version in the project settingsBitty
I have copy pasted to folder and added manually. How to make it compatible for Swift 5Ruelas
You can't. You only have the compiled code. You would need the source code to change it to Swift 5. You will need to use Swift 4.2 for the rest of your project.Bitty
Where can i force the XCode to not use Swift 5 , in podfile i have set 4.2 and in XCode Swift Language version is set to 4.2 and yet i see the error.Ruelas
You can download and use Xcode 10.1 until you get an answer or get the framework recompiled for Swift 5.Stepper
I tried toolchain approach medium.com/xcblog/… and not yet able to make Xcode 10.2 use itRuelas
I don't want to revert to revert Xcode, why it is not possible to just change swift version in project?Descry
It looks like the maker of this framework has deprecated Cocoapods support. You might need to look for a better framework.Statfarad
@Paulw11, note that ABI stability doesn't resolve that problem. ABI stability lets you use Swift N to build an app that links against some framework, and then after compile-time, it lets you swap that framework with one built with Swift N+1, and it'll still work. Module stability, which would be the important thing here, and which is still missing, means that you can use Swift N+1 to link against a framework that was built with Swift N.Chandelier
@SSR Did you find any solution for thisContemplative
I have the same problem. Why when we ask Xcode to use Swift 4.2 in Swift language version part of Build Settings in Xcode it doesn't and keep the error ?Trip
I facing the same problem. Finally, I stay on Xcode 10.1 :'(Mccullum
github.com/Paytm-Payments/Paytm_iOS_App_Kit/tree/master/Swift/… returns 404.Hamlett
Does this answer your question? Module compiled with Swift 4.0 cannot be imported in Swift 4.0.1Mainmast
M
8

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.

Miyokomizar answered 27/3, 2019 at 2:28 Comment(3)
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.Molini
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?Boil
Am I wrong : If you use Xcode 10.1 you won't be compatible with iOS 12.2, no ?Foscalina
S
17

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
Statfarad answered 26/3, 2019 at 17:0 Comment(2)
What is no-use-binaries means ?Dive
Google brought me here @KishoreKumar stackoverflow.com/questions/41442601/…Grays
M
8

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.

Miyokomizar answered 27/3, 2019 at 2:28 Comment(3)
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.Molini
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?Boil
Am I wrong : If you use Xcode 10.1 you won't be compatible with iOS 12.2, no ?Foscalina
H
5

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.

Hamlett answered 19/12, 2019 at 9:30 Comment(0)
N
2

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.

Nalor answered 5/4, 2019 at 8:34 Comment(0)
R
2

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.

Romilda answered 18/5, 2019 at 16:36 Comment(0)
F
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.

Fortuitous answered 28/3, 2019 at 15:22 Comment(0)
C
0

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://mcmap.net/q/16462/-module-compiled-with-swift-4-2-1-cannot-be-imported-by-the-swift-5-0-compiler, 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
Corny answered 22/4, 2019 at 14:51 Comment(0)
I
0

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

For Instance:

Impoverish answered 29/3, 2020 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.