There are several reasons that you're seeing this error, but it boils down to dependencies. If you select a scheme that builds an iOS target, then you don't have a problem using the following command. Note that I used iphoneos
to automatically select the latest SDK.
xcodebuild -configuration Release -target "ios" -sdk iphoneos -scheme "ios" build
The problem you're running into is triggered because of a dependency on the watchOS extension. I've created a sample project and added a watchOS application. In the build phases tab, you see in the Dependencies section that the iOS target has a dependency on the WatchOS target.
This isn't a problem if you specify a destination
in your build command. But it does give a problem if you tell xcodebuild
to build with a specific SDK. Why? Because the WatchOS target cannot be built with the iOS SDK. If you specify iphoneos
as the SDK, the build will fail.
Specifying a destination solves the problem, but know that you are using a specific simulator. If you use the same command on a different machine and that simulator isn't available, then the build will fail.
To be honest, I don't know if there's a middle road that lets you select the latest SDK and still use the correct SDK for each target, regardless of dependencies. If you remove the dependency of the iOS target, then the above build command shouldn't fail. You may also need to update the scheme you're using.