Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module compiled with Swift 5.0.1 cannot be imported by the Swift 5.1 compiler

Tags:

ios

swift

xcode11

I have a VoiceSampler.framework that was built with Xcode 10.3

I am trying to use that framework in Xcode11 in a new project. I have successfully added that framework, but when I write import VoiceSample in AppDelegate, I get the following error:

Module compiled with Swift 5.0.1 cannot be imported by the Swift 5.1 compiler: /Users/apple/Projects/CaptureAppSwift/VoiceSampler.framework/Modules/VoiceSampler.swiftmodule/arm64.swiftmodule

Is there a Build Setting I can tweak in Xcode 11 to make it work? Any other work around?

like image 442
Bharat Biswal Avatar asked Sep 27 '19 07:09

Bharat Biswal


People also ask

How do I upgrade my version of swift?

You can also update every single Swift Package in your project at once. To do this, open the Files menu, navigate to Packages and then click Update to Latest Package Versions. Afterwards, make sure to test your project to see if everything still works, especially in projects with a lot of package dependencies.

What is my swift version?

Click on your project's .Choose Build Settings. Search for “Swift language version” using the search bar. See the Swift version used by this project.

How do I compile framework in Xcode?

In Xcode, select File ▸ New ▸ Project…. Then choose iOS ▸ Framework & Library ▸ Framework. Click Next.


3 Answers

This problem is caused by the fact that you attempt to embed a pre-compiled framework that was created with a different compiler version.

Currently, pre-compiled frameworks can only be embedded if the compiler versions match! The swift compiler version that is used to compile the project must be the same version that was used to compile the framework.

Hopefully, this restriction will be removed in future Swift / compiler versions... For more information refer to the chapter on "Module Stability" here: https://swift.org/blog/abi-stability-and-more

As already mentioned in one of the comments, the solution to this problem is to up- or downgrade to the appropriate Xcode version. (Or, if possible, recompile the framework with the desired compiler version and then use the same compiler version for your project.)

like image 182
Lutz Avatar answered Oct 19 '22 13:10

Lutz


I was getting a similar problem for Sqlite.swift. Doing the following command worked for me:

carthage update --platform iOS --no-use-binaries

This was suggested here.

like image 33
Suragch Avatar answered Oct 19 '22 13:10

Suragch


Just need to set the Build Libraries for Distribution option to Yes in your framework's build settings.

like image 5
Nakul Sharma Avatar answered Oct 19 '22 11:10

Nakul Sharma