sasayakki

新卒iOSエンジニアがささやくブログ

Travis CIで "The requested device could not be found because multiple devices matched the request." が出るときの解消法

要約

  • Travis CIでテストを走らせる際に “The requested device could not be found because multiple devices matched the request.” と出て失敗するときの解消法
  • Simulatorの指定が一意でなく、対象に複数端末が見つかっていることが原因なので、 実行前に新しいシミュレータを作成し、そのIDで指定する

前提

CIとしてTravis CIを利用しており、以下の設定でテストを実行しています。

language: objective-c
xcode_project: Sample.xcodeproj
xcode_scheme: SampleTests
osx_image: xcode8.2
xcode_sdk: iphonesimulator

script:
  - xcodebuild build-for-testing test-without-building -scheme SampleTests -configuration Debug -sdk iphonesimulator -destination "name=iPhone 7" ENABLE_TESTABILITY=YES | xcpretty

問題

しかし、上記のスクリプトを実行すると、以下のエラーで失敗するケースが少なくありません。

xcodebuild: error: Unable to find a destination matching the provided destination specifier:
    { name:iPhone 7 }
The requested device could not be found because multiple devices matched the request.

原因

Travis CIで割り当てられるイメージの中で destination の条件に当てはまるシミュレータが複数見つかった場合に失敗します。

解消法

destinationid name,OS で指定できますが、 今回のように name だけあるいは nameOSで指定すると、 一致するシミュレータが複数存在する可能性があります。(割り当てられるイメージによるため、確実に失敗するとは限りません。) 解消するためにはシミュレータを一意に指定する必要があります。 そこで、 実行前に新しいシミュレータを作成し、そのIDを指定する 方法をとります。

language: objective-c
xcode_project: Sample.xcodeproj
xcode_scheme: SampleTests
osx_image: xcode8.2
xcode_sdk: iphonesimulator

before_script:
  - SIMULATOR_UUID=`xcrun simctl create "iPhone 7" "iPhone 7" 10.2`
script:
  - xcodebuild build-for-testing test-without-building -scheme SampleTests -configuration Debug -sdk iphonesimulator -destination "id=$SIMULATOR_UUID" ENABLE_TESTABILITY=YES | xcpretty

新規作成したUUIDを指定することで、シミュレータが一意に指定でき、失敗しなくなります。