Cannot build any Swift project at all due to strange error about MacOSX10.11.sdk - swift

I'm running macOS 10.12.3 with Xcode 8.3.
I cannot build any macOS Swift projects with it.
If I create a new Cocoa application Xcode project and set it to use Swift, when I try to compile it, I immediately get the following error in the "check dependencies" phase:
error: There is no SDK with the name or path '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk'
I have no idea what's going wrong!
The only clue I have is that earlier I created a symlink with the path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk that pointed to MacOSX.sdk in order to fix an issue where an older build of Qt that required an SDK with that path. However, deleting the symlink has no effect.
I can build Swift projects that targeting other platforms like iOS. Just not macOS.
Help!

try running this command then reopening the project
(Xcode uses xtools in the command line to build its projects)
sudo xcode-select -switch /path/to/file/
(by default the path is)/Applications/Xcode.app/
look at this pic
saw it here yesterday

Related

Flutter Will not run on IOS Simulator - Pods_Runner.framework' is missing one or more architectures

I upgraded to Flutter 2.5.0 and now I cannot run on an IOS simulator, from either Android Studio or the command line.
It fails with the error
Runner.xcodeproj: error: The linked framework 'Pods_Runner.framework' is missing one or more architectures
required by this target: arm64. (in target 'Runner' from project 'Runner')
I can manage to run on the Simulator from XCode without an issue
I can run on a device from Android Studio or command line
I have tried
restarting the simulator.
cleaning the build folder
upgrading Cocoapods to 1.11.1
Flutter Doctor says that everything is fine.
----------------- Edit ------------------
The situation Eventually Resolved Itself.
This is a problem because of ARM64 for me. This helped for me.
Be sure to open .xcworkspace.
Adding "arm64" to Project -> Build Settings -> Excluded Architecture
The reason why this might have been happened is because Xcode has been updated to a newer version. You gotta love Xcode..

Swift 3.1.1 compile error: unknown key 'SwiftImportAsNonGeneric'

Some time after upgrading to Xcode 9, I discovered that I was no longer able to build a Kitura-based project with the Swift 3.1.1 snapshot (which I have installed via swiftenv).
When I ran swift build, some time into the build I would get:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes:8:28: error: unknown key 'SwiftImportAsNonGeneric'
SwiftImportAsNonGeneric: true
^
<unknown>:0: error: could not build Objective-C module 'Foundation'
It seems that there is a dependency between Swift and Xcode, and Xcode 9 is no longer fully compatible with Swift 3.1.1 (or earlier) snapshots. I believe it may be because my project uses Foundation, and Foundation on Mac is provided as part of Xcode, whereas on Linux it is part of the Swift snapshot (via swift-corelibs-foundation).
I did find a solution to this problem: If I keep a copy of Xcode 8.3.3 around (eg. in /Applications/Xcode8.3.3.app) then I can use sudo xcode-select -s /Applications/Xcode<version>.app/Contents/Developer to select the appropriate one prior to building with SPM, and I can then build both Swift 3.1.1 and 4.0 projects on the same system.
However, this feels a bit clunky. Each time I build a project with the 'other' Swift version, I have to make sure I run xcode-select, or the build will fail. Is having multiple versions of Xcode the right solution in this case, or am I missing a trick with Xcode 9?
note that if, like me, you upgraded Xcode via the App Store, previous versions of Xcode are still available from https://developer.apple.com/download/more/

vapor build command not working with Swift 3.0

I am currently following the small and brief introduction to Swift Vapor by following their "Hello World" tutorial on their website. However I keep getting an error from swift-package when I try to build the project where it shows the following.
$ vapor build
No .build folder, fetch may take a while...
Fetching Dependencies [Failed]
Error: swift-package: error: unknown command: --enable-prefetching
I cannot seem to find out how to resolve this online. Anybody have any idea?
you have not mentioned your environment, so i'm giving solution for macOS.
I had the same issue, my swift version is 3.0.2 and vapor toolbox version is 1.0.9,
I tried the following thing to make it work
get into your project directory
create xcode project with command
swift package generate-xcodeproj
open xcode project
Select your scheme as App like this
and then build and run app
hope this helps!!
Make sure that you're using the correct command line tools for the Swift Version that you're using.
You can check from Xcode > Preferences > Locations > Command Line Tools
For me, using swift 3.0.2, vapor build command doesn't work neither.
However using swift 3.1.0, vapor build command works well.
My Vapor toolbox version is v1.1.0
I had the same problem, and I had Swift 3.1 installed. I deleted old version completely and installed new one and now it's building fine.
Try
rm -rf /usr/local/bin/vapor
brew tap vapor/homebrew-tap

than
brew install vapor
or
brew link vapor
if you have installed a new version previously.

swift build doesn't work

I'm trying to run Kitura project on XCode. I tried to follow instructions on this page ([https://github.com/IBM-Swift/Kitura/wiki/Building-your-Kitura-application-on-XCode]), however I failed with step 3 – run swift build -X. I get this error:
error: unable to invoke subcommand: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build (No such file or directory)
Looks like I have latest toolchain installed (see the screenshot below).
I also have both XCode 7.3.1 and XCode 8 beta. What would you suggest to solve that problem?
As Daniel mentioned above, Kitura right now requires use of the June 6 drop of the Swift Development toolchain. This toolchain can only be used with Xcode v7.3.1. The toolchain format changed between Xcode 7.x and newer Xcode 8 beta. When using the Xcode 8 beta with the new June 20 toolchain, there's another step that you need to do before you can run swift build from the command line.
From the command line, enter the following command:
$ sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer/
This command is necessary to inform Xcode where to find the required binaries and frameworks.
To switch it back, just use the same command but point it at non-beta version of Xcode:
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
Using these commands will eliminate the error <unknown>:0: error: Swift does not support the SDK 'MacOSX10.11.sdk' error: exit(1): that you ran into.
The Xcode 8 beta will be required to be used for all future Swift.org toolchains unless otherwise specified.
As of this writing, Kitura only compiles with the 06-06 Swift Development toolchain so make sure you have that installed.
In addition the wiki was out of date, the generate Xcode project command got renamed to swift package generate-xcodeproj. I updated the wiki to reflect this change.
Try:
export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"

How to install Swift package via package manager?

I am currently following the document from swift.org to play around with the new Swift Package Manager.
I cloned the demo project from Github and run the following command from terminal.
git clone https://github.com/apple/example-package-dealer.git
cd example-package-dealer
swift build
.build/debug/Dealer
While I run swift build, error arise.
<unknown>:0: error: no such file or directory: 'build'
Any idea?
I stuck for an hour. Sadly, it's just an epic fail that downloading the wrong swift package. If you want to use swift build, MAKE SURE you download the development version.
You did not add the newly installed swift to your PATH. The instructions for doing that are here.
On OS X:
export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"
On Linux:
export PATH=/path/to/Swift/usr/bin:"${PATH}"
Then to test it works:
swift build --version
I think it is a problem with the latest snapshot:
Ubuntu 14.04 Swift 2.2 Snapshot of January 11 contains swift-build in usr/bin
Ubuntu 14.04 Swift 2.2 Snapshot of January 25 doesn't contain swift-build in usr/bin
Besides, the January 25 release also seems to miss other files (libFoundation.so and libXCTest.so in usr/lib/swift/linux for instances).
Either there has been a structure change....or, simply, the latest snapshot had a problem ;)
While they fix the snapshot, simply take the older (January 11th) snapshot, and you should be fine.
I was facing the same issue and in my case, I recently updated my Xcode to 8.2.1 and swift 3.0 comes with it.
I was getting this log.
Ranvijay-Mac-mini:PerfectTemplate ranaranvijaysingh$ swift build
error: unable to invoke subcommand: /Library/Developer/CommandLineTools/usr/bin/swift-build (No such file or directory)
The path it was taking was incorrect. It was suppose to be:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
To change the path, run this command.
export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH
And DONE.
Run : swift build again on your project and if you get this error.
xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
error: Invalid platform path
then you need to change the SDK path as well.
In my case, I had two .sdk at path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
MacOSX.sdk MacOSX10.12.sdk
To know what is your SDK path, run this command.
xcrun --sdk macosx --show-sdk-path
My case i got this.
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
To change it run this command.
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
and NOW DONE.
Try running swift build now.