Search code examples
iosswift3xcode8xcodebuild

xcodebuild: error: Failed to build workspace. Reason: A build only device cannot be used to run this target


I'm trying to build and test on device (iPhone) using command line:

xcodebuild  \
    -workspace MyApp.xcworkspace \
    -scheme MyApp \
    -destination 'generic/platform=iOS,id=iPhoneUUID' \
    clean test

But I'm getting this error:

xcodebuild: error: Failed to build workspace MyApp with scheme MyApp.
    Reason: A build only device cannot be used to run this target.

Any of you knows why I'm getting this error?

I'll really appreciate any help.


Solution

  • Cut off the generic part in your -destination value. Else Xcode won't try to build for your device, but for the generic build only device:

    xcodebuild  \
        -workspace MyApp.xcworkspace \
        -scheme MyApp \
        -destination 'platform=iOS,id=iPhoneUUID' \
        clean test