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

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.

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

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.

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.

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.

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.

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.
Remove the cartfile.resolved and Carthage folder completely
Ensure you remove any copy of the libraries added to your project earlier.
Remove the embedded libraries and Linked frameworks and libraries from your Targets> Yourapp > General .
Product > Clean build folder
Update the Cart file and fetch the new sources using the Carthage update command
Now import the libraries back to your project.
Hopefully it works.

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

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:

Related

Migrating from Cocoapods to Swift Package Manager but import module failed

recently I'm refactoring a project which uses Cocoapods to manage dependencies (a lot of dependencies...), since Xcode 11 integrated Swift Package Manager, I want to migrate progressively some dependencies to SPM staring from the framework Alamofire.
After I removed the Alamofire from the Podfile (delete and run pod install) and added it into SPM,
I got the error No such module 'Alamofire'.
I've already tried to clean build and removed derived data but none of them can fix it.
Did anyone have this problem too?
After few days searching, I found out this https://stackoverflow.com/a/57312755/863020.
Seems that SPM could be only used for Debug and Release configurations, if we want to use it with more configurations then we should write a pre-action. And it is also a known issue on Xcode so I would not use SPM for now :(
UPDATED on dec. 12
So I come back to my question after the new release of Xcode 11.3, it fixed this issue and now I can build the project with custom build configuration :)

Xcode 9.1 : module compiled with Swift 4.0 cannot be imported in Swift 3.2.2

I updated xCode from 9.0.1 to 9.1. Everything was ok before, but now, I have this error when I try to build my project (with Carthage) :
module compiled with Swift 4.0 cannot be imported in Swift 3.2.2 (or 4.0.2 for SWIFT 4 users)
Don't need to let you know the module because it doesn't depend on it (because when I comment the import line concerned, the mistake his misplaced to the next import, so for another module).
I tried everything I saw :
Clean the project
Clean the Carthage folder
Clean Derived Data folder:
rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData
Update with Carthage: carthage update --platform iOS (with or not --no-use-binaries)
Update Modules
Build again
Close and Reopen Xcode
pray
Carthage (0.26.2) and MacOS (High Sierra) are up to date.
So, my last supposition (as I can read) is that Xcode 9.1 not allow us to use modules not build with Xcode 9.1. So I can come back to Xcode 9.0.1 but I will unable to deliver my project to Xcode 9.1 users. I cannot imagine to wait the update of all the modules. So do you have an idea, please ?
Thanks you !
Yes, you have to upgrade every framework you are using to 9.1.
"As I said, it doesn't depend on the module because if I comment one import, it's the import of another one who have troubles"
That's because the next one has the exact same problem. Just replace all your frameworks in the "Embedded Binaries" with versions that have been compiled with 9.1. To prove it to yourself, do it on the first one it complains about, and Xcode will then tell you the second one is now the problem, etc.

PubNub - iOS - Carthage only?

Question for someone who's quite fresh with PubNub and iOS-Swift,
as of today can you put PubNub in a project, entirely, absolutely not using cocoapods in any way? So, pure Carthage?
(PubNub's own doco is a little confused on the matter, at a quick glance.)
(Strictly iOS 10, no legacy)
Docs looks pretty clear about how to use Carthage way of integration.
To run this command you don't need CocoaPods (platform can be any: macos, tvos, ios and watchos or w/o platform to build all):
carthage update --platform ios
The only thing is required is Cartfile at the same directory from which you will call command from above. It should contain at leas this line (depending from version which you need):
github "pubnub/objective-c" ~> 4.1
As result you will get .framework bundle under Carthage/Build/{platform-name}/PubNub.framework. As mentioned in docs you can drag&drop it into your project and don't forget to add it to Embedded Binaries.
It looks like the project builds standalone frameworks, so you could add it as a Carthage dependency.
Carthage just downloads the project and builds it according to the project settings. All the consuming project needs to do is add the specific built product to you project.

Module file was created by an older version of the compiler

Using Carthage to manage my dependencies, everything runs fine in the simulator.
However, when building for a device I get the following error:
Module File was created by an older version of the compiler; rebuild Alamofire and try again: .../DerivedData/Build/Products/Debug-iPhones...
I have tried what others suggested to similar issues: deleting my derived data, reinstalling Carthage and rebuilding the frameworks. However, the error has been persistent.
Are you using the right version of xcodebuild? What do you see when you run xcode-select -p? It should be pointed at Xcode 7 if you want to use the frameworks in Xcode 7.
Remove all the derive data rm -rf ~/Library/Developer/Xcode/DerivedData/ && carthage build
Also, When you use carthage update without --no-use-binaries option then it downloads the pre built frameworks which may be built using the old version of xcodebuild.
Alternative way is to use carthage update --no-use-binaries. This way it will compile all the frameworks with the latest Xcode build installed on your Mac.
I am using cocoapods.I just right-click the wrong framework,show it in Finder,remove it,and build the project again,solve the problem.
You can try rebuilding the framework by command line:
Open Terminal
cd project/directory
carthage build
then clean the xcode project and run!

Xcode 5 "Missing compiler spec LLVM 4.2" error

I am currently trying to build my project in Xcode 5. Build fails with error:
Dependency Analysis Error:
missing compiler specification <XCCompilerSpecification: Some memory address here :'com.apple.compilers.llvmgcc42':MISSING:Default> for file
for all code files in project.
The project used to be built in Xcode 4.6 with LLVM 4.2 and now Xcode 5 only supports LLVM 5. So there is obviously something related to that here.
I have set the build settings in Xcode 5 to use LLVM 5 and the build still fails for the same reason. Has anyone encountered this before and know how to stop Xcode 5 from looking for LLVM 4.2 which it no longer supports?
This question is as a result of iOS 6 vs 7 appearance build settings
I had a same problem and I found that under Project-> Build Rules, gcc compiler was being used which no longer exist with Xcode 5.
I found something similar in an old project I have today. What happened is that there was a subproject in my project and that one wasn't set to llvm5.
You may want to do a search in your directory to find a file specifying llvm 4.2, like such:
MyMac:~/path/to/my/project $ grep -rHin llvm *
MyProject.xcodeproj/project.pbxproj:334: GCC_VERSION = com.apple.compilers.llvmgcc42;
MyProject.xcodeproj/project.pbxproj:348: GCC_VERSION = com.apple.compilers.llvmgcc42;
If that's the case, try updating that subproject or removing it altogether, see if you can at least clean your build.
Hope this helps.
first, if you use virtual machine, maybe it's the problem when it doesn't have grant to access into your project
if not check your file Maybe you miss any file?

Resources