Build and run an app on simulator using xcodebuild

Lorenzo B picture Lorenzo B · Nov 30, 2015 · Viewed 21.1k times · Source

I have the following goal to achieve: build and run an .app application using xcodebuild and ios-sim.

I'm using the following script to build the application.

xcrun xcodebuild \
  -scheme $XCODE_SCHEME \
  -project $XCODE_PROJECT \
  -configuration Debug \
  -destination generic/platform=iOS \
  -derivedDataPath \
  build

Then for running it, I'm using

ios-sim launch MyApp.app/ --devicetypeid "iPhone-6-Plus, 9.1"

Each time I receive the following message:

Program specified by service does not contain one of the requested architectures: ?

What is happening, that the app doesn't run?

Note: if I run the second command (ios-sim...) against the .app built from Xcode (the one contained in derived data) the procedure works fine.

Answer

Lorenzo B picture Lorenzo B · Nov 30, 2015

Ok. Figured out the issue.

You need to specify the correct destination. For example.

xcrun xcodebuild \
  -scheme $XCODE_SCHEME \
  -project $XCODE_PROJECT \
  -configuration Debug \
  -destination 'platform=iOS Simulator,name=iPhone 6 Plus,OS=9.1' \
  -derivedDataPath \
  build

In this way Xcode will create the folder (called build) containing your products (in particular look at Debug-iphonesimulator). The build dir is created within the dir you are running the xcodebuild command.

Now you can point that folder in order to run the ios-sim command (see ios-sim for more references) or simctl (see iOS 8: Building custom simulators and Build And Run iOS Apps In Commmand Line for more info).