30

With new Xcode 8 beta 4 we started experiencing the following error during CopySwiftLibs build phase:

Effective srcDirs: {(

    <DVTFilePath:0x7f865961e970:'/Volumes/Data/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator'>,

    <DVTFilePath:0x7f8657d02b20:'/Volumes/Data/Xcode-beta.app/Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/lib/swift/iphonesimulator'>

)}

error: The following binaries use incompatible versions of Swift:

/Users/user/Projects/git/iphone-swift-1/DerivedData/myApp/Build/Products/Debug-iphonesimulator/myApp.app/myApp

/Users/user/Projects/git/iphone-swift-1/myApp/myAppApi.framework/myAppApi

myAppApi is a subproject in the workspace that contains some shared code (it uses Alamofire).

One thing to note: originally we converted project from Swift 2.2 to Swift 2.3, and then manually upgraded to 3.0.

Does anyone have any idea what might be causing this error?

Thanks!

iGA
  • 301
  • 1
  • 3
  • 5
  • The binaries are built for older versions of swift i.e., `Swift 2.2`. It isn't compatible with `Swift 2.3`or `Swift 3`. It should be changed and compiled using `Swift 2.3` or `Swift 3.0`. – Mtoklitz113 Aug 05 '16 at 17:11
  • I've already converted the project to the latest swift syntax. Is there a setting I can change to force it to build for Swift 2.3? – aasatt Aug 05 '16 at 19:16
  • 1
    Note that "Swift 2.3 and Swift 3 are not binary compatible so your app's entire code base needs to pick one version of Swift." ([source](https://developer.apple.com/swift/blog/?id=36)) – cpimhoff Aug 05 '16 at 23:11
  • Xcode 10.2.1, Swift 5, I had to recompile the frameworks that are getting the error in the new Xcode for them to be recognized in my case. – Juan Boero May 06 '19 at 14:07

11 Answers11

67

I had the same problem, but managed to fix it by:

  1. Clean the project.
  2. Close project and quit Xcode.
  3. Clean derived data.
  4. Open the project again and it's there, all nice and working.

I did this on Xcode 8 using Swift 3.

ossmalpha
  • 881
  • 6
  • 10
  • 1
    please what do you mean about derived data? I have the same error – amjad Nov 05 '16 at 22:17
  • 1
    @amjad: go to Xcode -> Preferences -> Locations. You will find the DerivedData folder referenced there somewhere. You may even click the small grey arrow next to it and it will get open in Finder. Locate your app's folder inside, and delete it. Voila, you just "cleaned derived data". – Florin Odagiu Nov 07 '16 at 10:48
  • 1
    Future readers, to clean "derived data" I used: rm -rf ~/Library/Developer/Xcode/DerivedData – timon_the_destroyer Nov 25 '16 at 02:00
  • Is it important to clean derived data (step 3) after you close Xcode (step 2) or is it ok to deleted derived data folder while Xcode running as comments suggest then close and reopen Xcode? – Yarn Mar 27 '19 at 15:49
  • @Yarn I suggest closing Xcode and then cleaning derived data. – ossmalpha Apr 24 '19 at 19:09
17

You can also get this problem, if you have the scenario of your container app's code is Swift 2.3 and you're creating a new extension in Xcode 8.

To solve the above scenario...

Note: All code has to be in the same swift (compatible) version to compile without failure.

That being said, one way you could solve this problem is by sticking to Swift 2.3 and then setting your Extension Target's Use Legacy Swift Language Version to "Yes".

You can find that option while Xcode 8 is open as follows:

  1. Select your app project root in the Project Navigator (on the left-hand side)
  2. On the right-hand side, select your extension under the TARGETS section
  3. Once the extension is selected, click on the Build Settings tab
  4. Scroll down and find Use Legacy Swift Language Version and set it to Yes from its drop-down menu.
  5. You can now build the project

Note: You might need to fix the overridden code in the extension templates since they were originally in Swift 3.

iAmcR
  • 859
  • 11
  • 10
  • The framework was set to "Unsupported version:3.0" while the main app was "Yes" to Use Legacy Swift Language Version option and when I changed the setting in framework, I got 170+ errors – Shravya Boggarapu Feb 28 '17 at 10:38
7

Before doing anything...

(If you can use Xcode 8.0-compatible with your project)

By default your project is set to Xcode 3.2-compatible

  • Select your app project in the Navigator (on the left-hand side)
  • Select Project Document in the Utilities Panel (on the right-hand side)
  • Change Project Format to Xcode 8.0-compatible

Try to build your project.

If it doesn't work, try the other solutions proposed.

Note:You can even switch back to Xcode 3.2-compatible after fixing the error and it should work, but you "might" have other build problems later.

Recommendation: Before debugging an existing project. Close your project and zip a copy of your project file if you did not create a Git repository when you created your project.

ShakeMan
  • 481
  • 1
  • 5
  • 10
  • 2
    This worked for me. My project was a really old one - it was set to 3.2 compatible. The code is actually over 10 years old but migrated parts of it. Thanks. – ioquatix Nov 25 '16 at 22:28
7

I just had the same problem after updating Xcode to 9.3. I fixed the problem simply by just cleaning the build folder. You can do this with Command-Option-Shift-K or in the option menu "Product" -> "Clean" (see screenshot)

You can clean the build folder with Command-Option-Shift-K or in the option menu "Product" -> "Clean"

Smair
  • 342
  • 5
  • 9
4

I fixed this by deleting the embedded binaries in the project. To do this:

  1. Open your workspace/ project in Xcode.
  2. Navigate to the actual project file (with the General, Capabilities, etc. ribbon).
  3. Go to General > Embedded Binaries, remove by selecting on the ones you don't want and then clicking the minus sign.

Note 1: You shouldn't have to delete them from the "Linked Frameworks and Libraries" section (they should automatically be removed when you remove them from the "Embedded Binaries").

Note 2: I have a lot of dependencies and am using CocoaPods. I have nothing in the "Embedded Binaries" and only the "Pods_[YourApplicationName].framework" in the "Linked Frameworks and Libraries" section.

Clayton J Roberts
  • 347
  • 1
  • 5
  • 19
2

I had various libraries integrated via carthage. However during the process I switched some of them to cocoapods and forgot to remove the old .frameworks file from the project target.

Removing them solved the build error.

ph1lb4
  • 1,982
  • 17
  • 24
1

I had the same problem. My solution was to rename the 'myApp'-directory to 'myAppmyApp' and then I ran the app again. A new 'myApp'-directory was made a the app did run very well again on my iPhone.

A difference with your situation might be this: the name of my app, let's say 'myApp' in the directory 'DerivedData' was myApp concatenated with: '-'

Maybe this will help you.

Shamas S
  • 7,507
  • 10
  • 46
  • 58
0

You need to switch all the dependencies to swift 3. In your case, Alamofire need to be switched to Swift 3 branch

Martin Romañuk
  • 1,039
  • 10
  • 14
0

I had the same error message after adding a Swift 3 version of a framework.

My target framework search path was still configured to find both swift 2 and swift 3 version of the same framework, so my project got stuck on swift 2.3 version.

For me, the solution has been to remove the old framework from my project directory and delete its folder reference from the framework search path.

vmeyer
  • 1,998
  • 21
  • 23
0

So I just post the solution I found so far after an hour debugging.

Since Xcode 9, this can be tracked by the compiler log.

If you scroll down to the bottom of the compiler log, you will find this issue is caused by type checking crash.

enter image description here

Zigii Wong
  • 7,766
  • 8
  • 51
  • 79
-1

Just had this pop up after upgrading to Xcode 10.2 ... one of my pods uses Swift. Fix was to:

pod repo update
rm -rf Pods
pod install
David Hersey
  • 1,049
  • 11
  • 13