41

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bharat Biswal
  • 1,755
  • 2
  • 15
  • 23
  • 2
    what is VoiceSampler.framework? if it is Carthage then you have to update Carthage. – kishan vekariya Sep 27 '19 at 08:01
  • VoiceSample.framework is a library from another developer for sampling of MP3 pitch/frequency. I have been using this library with my projects in Xcode 10.3 without any issues. What is Carthage? and how/where do i update Carthage? – Bharat Biswal Sep 27 '19 at 08:20
  • The problem is with the Xcode as xcode 11 support swift 5.1 and your framework is written in swift 5.0.1 to solve this issue either downgrade your Xcode version to 10.3 or get the latest version of your VoiceSample.framework. – Adi.S Sep 27 '19 at 09:13

8 Answers8

32

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.)

Lutz
  • 1,734
  • 9
  • 18
  • 4
    I have recompiled the SDK in 5.1 and upload it, But when I install SDK thru cocoapods its again getting back to 5.0.1. Is there any way to solve the issue? – Albi Oct 21 '19 at 08:41
  • 5
    From April 2020, if you downgrade the Xcode then app will not be submitted. And if you set `YES` to `Build libraries for distribution` then it will give you tons of other errors. So any solution for this? – Niraj Apr 01 '20 at 06:57
6

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.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • The assumption that everything is shipped by Carthage is invalid. Some providers, unfortunately, provide their frameworks by mail or fat binary download on a webpage. – Nat Nov 25 '19 at 13:22
5

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

Jai Chauhan
  • 4,035
  • 3
  • 36
  • 62
Nakul Sharma
  • 600
  • 1
  • 16
  • 23
  • 6
    After I've turned `Build Libraries for Distribution` switch on, then it gives me another type of error which is `:0: error: using bridging headers with module interfaces is unsupported`. – zionpi May 09 '20 at 06:23
  • @zionpi did you get any solution yet? I am also facing the same – Ankit Goyal May 24 '21 at 12:42
  • @AnkitGoyal Here is my two cents.If your project reference the `third party library` that caused this kind of problem,then ask the `third party library` provider to give you the correct version,or downgrade your XCode version to match the `third party library's` swift version. – zionpi May 25 '21 at 14:48
2

enter image description here If you using React Native to build your App, go to Xcode and click on File->Workspace Settings...-> if you notice there is a small arrow that is the path to the DerivedData folder, click on that and the actual folder will appear with other iOS related folders, DELETE the DerivedData folder and rebuild your App. everything will work smoothly now... thank me later

Cya
  • 117
  • 2
  • 9
1

As I have already described here, the provider of VoiceSample should rebuild the framework with BUILD_LIBRARY_FOR_DISTRIBUTION = YES;. In such case, you will be able to use VoiceSample with all Swift versions.

Roman Podymov
  • 4,168
  • 4
  • 30
  • 57
1

The following commands resolved the compiler error

  1. carthage bootstrap --platform ios
  2. brew bundle
  3. pod repo update
Rinni
  • 121
  • 1
  • 3
0

In my case problem will be in carthage. So, I, in Finder, deleted these files from your project's root folder:

Cartfile.resolved, Carthage/

Then started carthage bootstrap --platform iOS(because I didn't need update carthage).

But if you need update carthage so you don't need to remove files. Only write command carthage update --platform iOS fix this problem.

Taras
  • 1,485
  • 1
  • 16
  • 31
0

You need to set the Build Libraries for Distribution option to Yes in your framework's build settings, otherwise the swift compiler doesn't generate the necessary .swiftinterface files which are the key to future compilers being able to load your old library.

This ends up in your project.pbxproj file as:

BUILD_LIBRARY_FOR_DISTRIBUTION = YES;

After setting this flag, a framework I compiled using Xcode 11.0 (swift 5.1) was able to be compiled with Xcode 11.2 (swift 5.1.2) and everything appears to be working correctly.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68