37
votes

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.

8
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.Paulw11
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.appbootup
I don't want to revert to revert Xcode, why it is not possible to just change swift version in project?Viktor Vostrikov
@SSR Did you find any solution for thisBoggarapu
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 ?Freddlow

8 Answers

17
votes

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
8
votes

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.

5
votes

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.

2
votes

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.

2
votes

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.

1
votes

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.

0
votes

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://stackoverflow.com/a/55362536/721929, 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
0
votes

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: