使用 xcodebuild 创建 watchOS2 模拟器构建

creating watchOS2 simulator build using xcodebuild

我想使用终端和 xcodebuild 构建模拟器。到目前为止,传递类似于“-sdk iphonesimulator9.0”的东西是有效的。现在手表扩展是 运行 在手表上我收到这个错误:

=== 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

您知道如何构建支持 watchOS2 的应用的模拟器版本吗?

谢谢!

我刚刚找到了解决方案: 要从终端构建胖模拟器,我必须执行以下步骤: 基本上解决方案是使用 xcodebuild 的 -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 }' | tr ":" "=" | tr -d ",")

关于“2>&1 >/dev/null”部分:

上一条命令的第一部分:

"/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'

向 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 }"

为了能够从中找出设备 ID,我必须将此 stderr 输出重定向到此命令的标准输入

所以现在我有这样的东西: id=3B706D94-89BE-46A3-81C7-34CA2F91B823

在我的 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 "$SIMULATOR_TARGET_DESTINATION" ONLY_ACTIVE_ARCH=NO

关于 "ONLY_ACTIVE_ARCH=NO" :

这样我就可以生成一个胖构建,而不仅仅是一个架构(i386 或 x86_64)的构建。

不错的方法。

有时我的 Jenkins 构建会因为重复的模拟器而失败(主要是在使用 snapshot reset_simulators 之后)。

长话短说,我需要获取第一个可用的模拟器 UUID 并将其作为参数传递给 xcodebuild。根据你的回答,我最终是这样的:

# 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 }'          // 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 }' | tr -d '[]')

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

效果很好。感谢分享。