使用xcodebuild创建watchOS2模拟器

时间:2015-09-02 14:11:16

标签: ios build simulator xcodebuild watch-os-2

我想使用Terminal和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支持的应用的模拟器版本?

谢谢!

2 个答案:

答案 0 :(得分:1)

我刚刚找到解决方案: 要从Terminal构建胖模拟器,我必须执行以下步骤: 基本上解决方案是使用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 $4}' | 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输出重定向到此命令的stdin

所以现在我有这样的事情: 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 =否" :

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

答案 1 :(得分:0)

很好的方法。

有时我的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 $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

效果很好。谢谢分享。