5

I would like to build a simulator build using Terminal and xcodebuild. Up until now passing something similar like "-sdk iphonesimulator9.0" worked. Now that the watch extension is running on the watch I receive this error :

=== BUILD TARGET appName WatchKit Extension OF PROJECT appName WITH     CONFIGURATION Debug ===

Check dependencies
target specifies product type 'com.apple.product-type.watchkit2-extension',     but there's no such product type for the 'iphonesimulator' platform

Do you know how can someone build simulator version of their app which has watchOS2 support?

Thanks!

thorax
  • 574
  • 1
  • 5
  • 16
  • This post should answer your question: http://stackoverflow.com/questions/31478959/how-to-use-xcodebuild-in-xcode-7-with-a-watch-extension – Yong Li Sep 18 '15 at 18:35

2 Answers2

2

I just found the solution : To build a fat simulator build from Terminal, I have to execute the following steps : Basically the solution is about using the -destination option of xcodebuild.

I have to find a simulator target to configure that as destination :

    SIMULATOR_TARGET_DESTINATION=$("/xcode_7/Xcode.app/Contents/Developer/usr/bin/xcodebuild" -workspace MyApp.xcworkspace -scheme MyApp -configuration MyConfiguration -derivedDataPath My/DerivedData/Path clean build -destination 'platform=iOS Simulator' 2>&1 >/dev/null | grep id: | head -n 1 | awk '{print $4}' | tr ":" "=" | tr -d ",")

About the " 2>&1 >/dev/null" part :

the first part of the previous command :

"/xcode_7/Xcode.app/Contents/Developer/usr/bin/xcodebuild" -workspace MyApp.xcworkspace -scheme MyApp -configuration MyConfiguration -derivedDataPath My/DerivedData/Path clean build -destination 'platform=iOS Simulator'

prints out something like this to the stderr :

xcodebuild: error: Unable to find a destination matching the provided destination specifier:
    { platform:iOS Simulator }

Missing required device specifier option.
The device type “iOS Simulator” requires that either “name” or “id” be specified.
Please supply either “name” or “id”.

Available destinations for the "MyApp" scheme:
    { platform:iOS Simulator, id:3B706D94-89BE-46A3-81C7-34CA2F91B823, OS:9.1, name:iPad 2 }
    { platform:iOS Simulator, id:BE272A9F-4653-4633-9C51-2524AE6AE7D1, OS:9.1, name:iPad 2 }
    { platform:iOS Simulator, id:830CDD58-FF1C-4436-BDF8-0F05452317C7, OS:9.1, name:iPad Air }
    { platform:iOS Simulator, id:B36B366A-A993-4C92-BADC-8C0772320067, OS:9.1, name:iPad Air }
    { platform:iOS Simulator, id:71A801F9-E5CD-4E3A-B46B-882F6ECC7209, OS:9.1, name:iPad Air 2 }
    { platform:iOS Simulator, id:A314088B-2CA5-4F73-B528-9F82C2689156, OS:9.1, name:iPad Air 2 }
    { platform:iOS Simulator, id:0BD94515-1DBE-4A79-B618-FC077539A581, OS:9.1, name:iPad Pro }
    { platform:iOS Simulator, id:471B94A3-67EE-4A4C-BB41-86DB2EE2F11A, OS:9.1, name:iPad Pro }
    { platform:iOS Simulator, id:D39DDDC0-0A1E-4A7E-B9A0-449FD1FE129C, OS:9.1, name:iPad Retina }
    { platform:iOS Simulator, id:F716E5A4-93F7-43B1-94EE-9BE358E4670C, OS:9.1, name:iPad Retina }
    { platform:iOS Simulator, id:5458CA06-BBAE-46E8-9A3E-90E4AE5FEA87, OS:9.1, name:iPhone 4s }
    { platform:iOS Simulator, id:92C98913-F79D-420F-B79B-5387C12B017D, OS:9.1, name:iPhone 4s }
    { platform:iOS Simulator, id:576A754E-3421-4254-A9E9-692844FDFD02, OS:9.1, name:iPhone 5 }
    { platform:iOS Simulator, id:EE446826-3BB6-4081-B28F-8DF115C33776, OS:9.1, name:iPhone 5 }
    { platform:iOS Simulator, id:D4CF7855-9C77-481B-A6CF-68BE8C736695, OS:9.1, name:iPhone 5s }
    { platform:iOS Simulator, id:E332A751-0F8E-4F2A-B27B-35C904300029, OS:9.1, name:iPhone 5s }
    { platform:iOS Simulator, id:0B30A782-0D6F-4398-8F73-F2FCB72F0F31, OS:9.1, name:iPhone 6 }
    { platform:iOS Simulator, id:FD042A1E-2A44-4803-8D01-093E63AECBF9, OS:9.1, name:iPhone 6 }
    { platform:iOS Simulator, id:D0530464-F20E-4BA4-BA49-681B057362E2, OS:9.1, name:iPhone 6 Plus }
    { platform:iOS Simulator, id:F7D70F71-BA90-4F14-9935-BE5447997D8E, OS:9.1, name:iPhone 6 Plus }
    { platform:iOS Simulator, id:B157D201-9673-49A6-9D8A-F6CC43F9350F, OS:9.1, name:iPhone 6s }
    { platform:iOS Simulator, id:B9600BC7-EFE5-4A83-9916-9042B8609A14, OS:9.1, name:iPhone 6s }
    { platform:iOS Simulator, id:69254BE7-1F54-4AA7-8484-B270FF059A57, OS:9.1, name:iPhone 6s Plus }
    { platform:iOS Simulator, id:7F39C8DC-1582-4273-AA3E-5FEE19D4B3B0, OS:9.1, name:iPhone 6s Plus }"

To be able to grep out a device id from it, I have to redirect this stderr output to stdin for this command

So now that I have something like this : id=3B706D94-89BE-46A3-81C7-34CA2F91B823

in my SIMULATOR_TARGET_DESTINATION variable, I can use that to actually create the build : "/xcode_7/Xcode.app/Contents/Developer/usr/bin/xcodebuild" -workspace MyApp.xcworkspace -scheme MyApp -configuration MyConfiguration -derivedDataPath My/DerivedData/Path clean build -destination "$SIMULATOR_TARGET_DESTINATION" ONLY_ACTIVE_ARCH=NO

About "ONLY_ACTIVE_ARCH=NO" :

This way I can generate a fat build instead of just a build for one architecture (i386 or x86_64) .

thorax
  • 574
  • 1
  • 5
  • 16
  • I believe you can simplify this with `-destination 'platform=iOS Simulator,name=iPhone 6'` and skip extracting the `id`. – Joe Nov 01 '15 at 20:36
0

Nice approach.

Sometimes my Jenkins builds were failing due to duplicated simulators (mainly after using snapshot reset_simulators).

Long story short, I needed to get the first available simulator UUID and pass it in as a parameter to xcodebuild. Based on your answer, I ended up like this:

# Finds the UUID of the first "iPhone" simulator available
# (sometimes the simulators get duplicated, which can break the build)
#
# instruments -s devices    // Shows list of known devices
# grep "iPhone"             // Self explanatory. May return more than one currence.
# head -1                   // Displays only the first line of the previous grep
# awk '{print $4}'          // Displays the fourth argument of the previous line, which represent the UUID
# tr -d '[]'                // Removes the following characters of the returned UUID "[" and "]"
#
SIM_ID=$(instruments -s devices | grep "iPhone" | head -1 | awk '{print $4}' | tr -d '[]')

# Builds and runs tests
xcodebuild -workspace MyWorkspace.xcworkspace -sdk iphonesimulator -destination id=$SIM_ID -scheme MyScheme test

Works great. Thanks for sharing.

backslash-f
  • 7,923
  • 7
  • 52
  • 80