问题
Our command used to be like this
xcodebuild -configuration Release -target "xxx" -sdk iphoneos9.0 -scheme "xxx" archive
Now in Xcode 7, we get this error:
Build settings from command line:
SDKROOT = iphoneos9.0
=== BUILD TARGET xxx WatchKit Extension OF PROJECT Mobile WITH CONFIGURATION Release ===
Check dependencies
target specifies product type 'com.apple.product-type.watchkit2-extension', but there's no such product type for the 'iphoneos' platform
How do we specify to use iOS 9.0 SDK and the watchos 2.0 SDK?
回答1:
If you need a simulator build run this:
xcodebuild -workspace WorkspaceName.xcworkspace -scheme SchemeWithWatchOS2Target -destination 'name=iPhone 6' build
And if you need a device build run this:
xcodebuild -workspace WorkspaceName.xcworkspace -scheme SchemeWithWatchOS2Target build
The trick is that for any build you need to remove -sdk
option. For simulator build you need to specify -destination
which should be iPhone 6
or iPhone 6 Plus
. And for devices builds you skip -destination
.
回答2:
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.
来源:https://stackoverflow.com/questions/31478959/how-to-use-xcodebuild-in-xcode-7-with-a-watch-extension