How to use xcodebuild in Xcode 7 with a watch extension
Asked Answered
F

2

8

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?

Ferneferneau answered 17/7, 2015 at 15:7 Comment(0)
B
25

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.

Brookebrooker answered 11/8, 2015 at 23:59 Comment(4)
Removing the -sdk argument does the trick for me as well. Great hint. +1Crashland
that way I'm still having problem if I want to run tests, specifically I receive: There was a problem starting the test bundle: Testing with the 'iphoneos' SDK is not yet supported. Instead, test with the simulator SDK by setting '-sdk iphonesimulator'.Ludovika
@dev_mush, you need to provide -destination in order to run tests.Brookebrooker
@Ludovika As the time of writing (Xcode 7), running unit tests on a physical device isn't supported. This means that you cannot use iphoneos for sdk. That's what the error is telling you.Galenic
G
1

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.

enter image description here

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.

Galenic answered 11/12, 2015 at 8:26 Comment(1)
-destination 'generic/platform=iphonesimulator' or -destination 'generic/platform=iOS' allows to use the command on any machine.Gogol

© 2022 - 2024 — McMap. All rights reserved.