Xcode 8 beta 4: Build fails with "The following binaries use incompatible versions of Swift:" error - ios

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!

I had the same problem, but managed to fix it by:
Clean the project.
Close project and quit Xcode.
Clean derived data.
Open the project again and it's there, all nice and working.
I did this on Xcode 8 using Swift 3.

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:
Select your app project root in the Project Navigator (on the left-hand side)
On the right-hand side, select your extension under the TARGETS
section
Once the extension is selected, click on the Build Settings tab
Scroll down and find Use Legacy Swift Language Version and set it
to Yes from its drop-down menu.
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.

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.

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)

I fixed this by deleting the embedded binaries in the project. To do this:
Open your workspace/ project in Xcode.
Navigate to the actual project file (with the General, Capabilities, etc. ribbon).
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.

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.

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.

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

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.

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.

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

Related

Xcode 10 convert to Swift 4.2 fails

I am getting this error trying to migrate to Swift 4.2 using the Xcode provided conversion tool. How do I fix it? The code builds fine otherwise.
Do you have any libraries in your project? I think you are trying to covert your project with dependencies and there are problems in them with new swift version. Try to uncheck all dependencies except your project and convert to new version of Swift
I had similar problem, solved it by
1- Change swift lang version in build setting of all app and test targets to 4.2
2- build app, errors will happen like UIControlState renamed to UIControl.state
3- fix all of the build errors
4- I updated all recommended settings by xcode
5- then I asked xcode to convert to swift4.2
It's always a good idea to upgrade all dependencies (e.g. via Cocoapods) to its latest version that support Swift 4.2. In my case, I also need to manually change the Swift Language Version build settings for a pod library from Swift 4 to Swift 4.2 as that lib uses some APIs in 4.2 only.
I have problem too. I find solution to fix this problem in web
https://ericasadun.com/2018/09/13/converting-projects-by-hand-to-4-2/
First
You try delete pod in pod file and install pod again and pod update in your folder project in command then conversion to Swift 4.2.
if it's not work do this in second.
Second
you try follow do this picture in build setting project or try follow do in link web.
As described here,
There may have been issues with processing the targets that will
negatively impact the migration process. Switch to the Report
Navigator and select the Convert entry that was added; this is the
conversion build log. Check the log for errors that may have showed
up.
If you see errors about not being able to code-sign the target, try
disabling code-signing from the build settings of the target. If you
see other errors, please file a bug report and include the details.
You are strongly encouraged to attach a project that illustrates the
faulty migration if possible.

Xcode 9 Swift Language Version (SWIFT_VERSION)

I've recently updated xcode to version 9. Before that in Xcode 8.x whenever I use to do pod update it shows me an update code to convert the code to Swift 3 and doing that solve the errors. But now it is giving me this error:
The “Swift Language Version” (SWIFT_VERSION) build setting must be set
to a supported value for targets which use Swift. This setting can be
set in the build settings editor.
For this error I've tried Build Settings > Swift Language Version and it was Swift 3.2
But as the update call has re-installed some of the pods like Alamofire and it says to install Xcode 8.x to convert the code to Swift 3 so do I need to install an additional version with the latest Xcode? If yes, then how can I install Xcode 8 with Xcode 9?
Answer to your question:
You can download Xcode 8.x from Apple Download Portal or Download Xcode 8.3.3 (or see: Where to download older version of Xcode), if you've premium developer account (apple id). You can install & work with both Xcode 9 and Xcode 8.x in single (mac) system. (Make sure you've Command Line Tools supporting both version of Xcode, to work with terminal (see: How to install 'Command Line Tool'))
Hint: How to migrate your code Xcode 9 compatible Swift versions (Swift 3.2 or 4)
Xcode 9 allows conversion/migration from Swift 3.0 to Swift 3.2/4.0 only. So if current version of Swift language of your project is below 3.0 then you must migrate your code in Swift 3 compatible version Using Xcode 8.x.
This is common error message that Xcode 9 shows if it identifies Swift language below 3.0, during migration.
Swift 3.2 is supported by Xcode 9 & Xcode 8 both.
Project ► (Select Your Project Target) ► Build Settings ► (Type 'swift' in Searchbar) Swift Compiler Language ► Swift Language Version ► Click on Language list to open it.
Convert your source code from Swift 2.0 to 3.2 using Xcode 8 and then continue with Xcode 9 (Swift 3.2 or 4).
For easier migration of your code, follow these steps: (it will help you to convert into latest version of swift supported by your Xcode Tool)
Xcode: Menus: Edit ▶ Covert ▶ To Current Swift Syntax
For Objective C Projects created using Xcode 8 and now opening in Xcode 9, it is showing the same error as mentioned in the question.
To fix that, Press the + button in Build Settings and select Add User-Defined Setting as shown in the image below
Then in the new row created add SWIFT_VERSION as key and 3.2 as value like below.
It will fix the error for objective c projects.
I just got this after creating a new Objective-C project in Xcode 10, after I added a Core Data model file to the project.
I found two ways to fix this:
The Easy Way: Open the Core Data model's File Inspector (⌥⌘-1) and change the language from Swift to Objective-C
Longer and more dangerous method
The model contains a "contents" file with this line:
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14460.32" systemVersion="17G5019" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
In there is a sourceLanguage="Swift" entry. Change it to sourceLanguage="Objective-C" and the error goes away.
To find the "contents" file, right click on the .xcdatamodeld in Xcode and do "Show in Finder". Right-click on the actual (Finder) file and do "Show Package Contents"
Also: Changing the model's language will stop Xcode from generating managed object subclass files in Swift.
This can happen when you added Core Data to an existing project.
Check the:
<Name>/<Name>.xcdatamodeld/<Name>.xcdatamodel/contents file.
This file contains an entry "sourceLanguage" that (by default) might have been set to "Swift". Change it to "Objective-C".
I just click on latest swift convert button and set App target build setting-> Swift language version: swift 4.0,
Hope this will help.
This Solution works when nothing else works:
I spent more than a week to convert the whole project and came to a solution below:
First, de-integrate the cocopods dependency from the project and then start converting the project to the latest swift version.
Go to Project Directory in the Terminal and Type:
pod deintegrate
This will de-integrate cocopods from the project and No traces of CocoaPods will be left in the project. But at the same time, it won't delete the xcworkspace and podfiles. It's ok if they are present.
Now you have to open xcodeproj(not xcworkspace) and you will get lots of errors because you have called cocoapods dependency methods in your main projects.
So to remove those errors you have two options:
Comment down all the code you have used from cocoapods library.
Create a wrapper class which has dummy methods similar to cocopods library, and then call it.
Once all the errors get removed you can convert the code to the latest swift version.
Sometimes if you are getting weird errors then try cleaning derived data and try again.
maybe you need to download toolchain.
This error occurs when you don't have right version of swift compiler.
In my case, all warn disappeared after I directly changed swift version from 2.x to 4.0 in build settings except two warn.
These warning related to myprojectnameTests and myprojectnameUITests folder. I didn't notice and I thought its relate to direct immigration from Xcode 7 to Xcode 9 and I thought I couldn't solve this problem and I should install missed Xcode 8 version.
In my case, I deleted these folders and all warns disappeared, but you can recreate this folder and contains using this:
file > new > target > (uitest or unittest extensions)
and use this article for create test cases:
https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/04-writing_tests.html

MagicalRecord/MagicalRecordXcode7CompatibilityMacros.h file not found in Xcode 7.2

I downloaded and integrate copy of MagicalRecord sdk 2.3.3 in my project.i am not using cocoa pods. why because cocoa pods does not provide magical record 2.3.3 sdk. but I cannot compile the My project. i am using Xcode 7.2. I get the following compile error:
MagicalRecord/MagicalRecordXcode7CompatibilityMacros.h file not
found
Deleting derived data and cleaning worked for me
Is the file visible in your navigator on the left? If so and the file is in red text color, then you can add this file by dragging it from the finder (search for the file with Spotlight) right into your project. If Xcode asked if it needs to copy the files if needed, check that box.
This issue happened to me when I accidentally left Build Location set to Legacy (I set it when working on another project). Go to Preferences (Cmd+,) -> Locations -> Advanced... and check if Build Location is set to Unique.

'Framework not found' in Xcode

I know this has been asked a couple of times. I followed instructions from these ones:
Adding frameworks to project in Xcode 5 and having *relative* paths added
xcode4: Linker error: Directory not found for option
Still Xcode is giving this error:
Here's my current configuration:
The bolts framework is so I can use the Parse SDK. I downloaded the blank project from here: https://parse.com/apps/quickstart#parse_data/mobile/ios/native/new
It's working. I tried to copy every config option, but it still doesn't work.
Try deleting Bolts.framework from linked framework and re-add it. Also, in your Framework Search Path keep path until Bolts.framework like $(PROJECT_DIR)/Bolts if it is inside Bolts folder at your project directory path.
I'm pretty new to iOS development. Apparently this problem for me was a result of opening the .xcodeproj Xcode project instead of the .xcworkspace Xcode workspace. I opened the workspace instead and the error has gone away.
error: Framework not found
If you use CocoaPods try to run:
pod deintegrate
pod update
Also use .xcworkspace instead of .xcodeproj
Delete the framework link from the Xcode project setting.
Move the framework to the Project Folder.
Re-add the framework in the Xcode project setting.
clean the project and re-compile it.
delete all frameworks from Embedded Binaries and re-add it
me too was getting this error , I moved the framework file to the root project folder and added to framework again and problem is solved.
1:- Delete the framework from the Xcode project. Quit the Xcode.
2:- Open your project in XCode and go to file under Menu and select Add files to "YourProjectName".
3:- Select "YourFramwork.framework" in the directory where you keep it.
4:- Click on the Copy items if needed checkbox.
5:- Click Add.
Make sure that you have the framework added in both Embedded Binaries and Linked Frameworks and Libraries under Target settings - General. As shown in the following images:-
Here is the solution :
Turn the "$(PROJECT_DIR)" attribute(might be non-recursive by default) into recursive option in Select Project Click on Targets Click - Build Settings Search for 'Framework Search Path' - Double click the input.
Scratched from https://stackoverflow.com/a/31298214/4493512
Besides from removing the framework from the Podfile and Linked Frameworks and Libraries, I also had to remove the reference to the framework in Other Linker Flags.
I just had the same situation (was having a hard time to address the OP's build error after adding a 3rd party framework) and it seems like a bug in Xcode (mine is 8.3.2 (8E2002)).
The problem was that a folder name in path to the framework contained spaces. In this case, Xcode incorrectly escaped them with backslashes like this in Build Settings -> Framework Search Paths:
$(PROJECT_DIR)/Folder\ with\ spaces/Lib
To fix this, just manually edit the entry to remove those backslashes and enclose the whole string in quotes like this:
"$(PROJECT_DIR)/Folder with spaces/Lib"
Delete the framework that is causing the issue (by removing the reference).
Then add it again, following these steps for adding FBSDK frameworks and libraries:
click project
general settings
linked framework and libraries
click the plus button and add all that you want
None of the above worked for me until I found that I had a blank "Any Architecture | Any SDK" line underneath Framework Search Paths / Debug under Build Settings.
Deleted the line and it works!
Error: Framework not found
If you use CocoaPods try to run these commands from terminal:
Intel chip:
pod deintegrate
pod update
Apple Silicon M1 chip:
pod deintegrate
arch -x86_64 pod update
Also use .xcworkspace instead of .xcodeproj
When this error occurred to me was because Pods folder was in iCloud and had no local copy on my computer. Go to your project's folder in Finder and check if there is iCloud's symbol in any of the folders inside it!
I realised that I hadn't run/built my framework with the Generic Device, which strangely lead to these issues. I just put the framework back in and it worked.
If you are using CocoaPods. Similar thing has happened to me. Although this question is old someone like me might still be struggling. So for to help:
after pod install it warns you about project files. I didn't notice till now. it says:
[!] Please close any current Xcode sessions and use
ProjectFile.xcworkspace for this project from now on.
So basically, do not continue working on .xcodeproj after installing Pods. If you do linker won't find files.
My framework has long name like FrameworkSDK_Light-1.0.6.framework so I renamed it to FrameworkSDK_Light.framework and it solved my problem.
I got the error 'AdBrixRM framework not found'. I checked the AdBrixRM.framework. I noticed that 'AdBrixRM' excution file is missed. I copied this file into the framework folder and the issue was gone.
I used to encounter this same exact issue in the past with Google Admob SDK. Most recently, this happened when trying to add Validic libraries. I tried the same old good trick this time around as well and it worked in a jiffy.
1) Remove the frameworks, if already added.
2) Locate the framework in Finder and Drag & Drop them directly into the Project Navigator pane under your project tree.
3) Build the project and Whooo!
Not sure what makes the difference, but adding the frameworks by the official way of going to the section "Linked Framework & Libraries" under project settings page (TARGET) and linking from there does not work for me. Hope this helps.
I found that the file.framework was referencing a file outside my project. So I dragged the file into my frameworks folder under my project and then got rid of the earlier file.framework file and it worked.
add github "BoltsFramework/Bolts-iOS" on your cartfile.
then carthage update.
after copy Bolts.framework from ../carthage/Build/iOS
Switching from iOS simulator to real device solved the problem for me.
Was facing the same error and solved it ---> Build Settings > Build Active Architecture Only = Yes
Please after adding both framework also open each Bolts and Parse framework and add Parse and Bolts to the project then problem will be solve
Running pod update in the root directory of the app fixed the issue for me.
If you are developing one module using cocoapods, try to comment the line
s.vendored_frameworks = "YOURMODULE.framework"
on YOURMODULE.podspec
The error will disappear after you generate and copy your YOURMODULE.framework to your project folder.
I had this issue on one of the project i worked, before you delete and readd the framework do a:
git status
on your project and check to see if the framework is not listed as deleted. In the event that it is either do a
git stash
or
git checkout *framework/file/path*

Cannot add embedded binaries (other projects) to project dependencies in XCode

I have an XCode workspace created with XCode 6.0.1. It constains 2 (Swift) libraries and one iOS app (Swift) that depends on those 2 libraries. I had stable setup that allowed me to run the iOS app on both iPhone and simulators: The 2 library projects were added as Embedded Binaries (see picture) of the app.
Now, I have XCode 6.1. Recently, I deleted DerivedData folder in ~/Library/Developer/Xcode folder while XCode was running. After that my workspace did not work - the iOS app would fail to compile and I got linker error saying it cannot find the library projects.
I tried to solve it by removing my the 2 libraries from Embedded Binaries of the app project - and I cannot add them back. Clicking + button under Embedded Binaries in project settings displays workspace projects correctly but selecting and adding my library project does not add them to the list of Embedded Binaries. I have solved the linker error by creating new workspace. The app compiles but how it links the libraries is a mystery to me: They are not in listed Embedded Binaries or Linked Frameworks and Libraries not in the Frameworks search path. There appears to be no link between the app and the libraries it needs (and obviously have as it compiles) except that libraries projects are in the same workspace.
Why I cannot add library projects to Embedded Binaries? Is it normal in XCode 6.1 that dependency projects just compile and gets embedded into an app without being listed or linked anywhere?
This is a summary of my answer to the question Xcode won't add “Embedded binary” after deleting “DerivedData”, see the original question and answer for more context and information:
Remove all framework projects from the workspace
Perform a "clean build" and/or remove the "DerivedData"
Add project back into the workspace
Build the project (possibly optional)
In the General tab of the app target click the + under "Linked Frameworks and Libraries", select the framework.
Build and run in the Simulator (there should be no issues building or running)
Build and run for device (this might cause a crash due to the framework not being correctly linked, ignore this crash)
Click the + under "Embedded Binaries", select the framework. This should add it to the project (possible duplicate under "Linked Frameworks and Libraries")
Repeat for all required frameworks
Once building and running (on device) is confirmed you can remove any duplicate (and/or red) frameworks in the Project Navigator or target General tab
Ok, I ran into the same problem as you. After deleting the derived data, I could not re-link my binaries again. I think the reason is because the derived data is where the binaries are written to and linked against in your project.
What I did to solve was to select my Framework as my build target. After building it, the Framework target turned from red to black. I can see in your screenshot it is red, meaning it has not been compiled into a binary and written on disk.
Once I did this, I was able to re-link the Framework to my Project because there was a reference to it on disk. Hope this helps!
Clean your projects & build your framework first. Thereafter you can embed it.
Here is how I solved the problem:
Build the framwork.
Open the build folder and drag built framework into the app project (so it uses the path to DerivedData).
Add the framework to the list of embedded frameworks.
In the Finder, do a Show Contents on the app's xcodeproj file, then open project.pbxproj in your favorite text editor.
Find the line with the long DerivedData path. Change it so there is no name, the path is the framework name, and source tree is BUILT_PRODUCTS_DIR
Xcode should notice the change and the library in the app project will be black instead of red and will now build and run properly.
I have a very similar issue and fixed it just last night. Decided to come back to this thread and offer my workaround, as rjstelling's solution above did not help my case.
I have a workspace that contains two frameworks and one application. The App was making use of both frameworks happily for a while until I got hit by a mysterious compile eror where it decided that adding a property access to an instance variable called "cube" of a class type found in one of the framework, made access to "_cube" impossible (complaining it was not declared, while it had actually worked previously in a setter method).
Long story short, after a clean, somehow the workspace/app project lost track of the embedded framework of my iOS 8+ project. Removing the embedded framework was the last straw in that line of failure, causing my project to no longer allow be to select any frameworks for embedding.
Reverting the project & workspace to an earlier version did not get rid of the voodoo.
I ended up adding the to-be-embeded framework projects in the main app project (as files) and introduced target dependencies on the frameworks.
I was then able to re-embed the frameworks and link.
As for the _cube thing, I had to specify a getter for the property and #synthesize the property to a different name. I dont have an explanation for this one.
It's probably because your framework is a separate project and not a separate target. Try watching carefully Session 416: Building a Modern Framework at around minutes 34-36. It will show you how to set it up correctly.
This makes it a bit confusing if you wanted to share a framework across multiple projects by the way

Resources