I am trying to launch my iOS app on the simulator using command-line tools, likely for automated testing for Maestro. I can successfully build the app using xcodebuild
and install it onto the target simulator using xcrun simctl install. The installation appears successful (the app icon shows up on the simulator) and if I click it it opens app successfully.
However, when I try to launch the app using xcrun simctl launch "$SIMULATOR_TARGET" "$BUNDLE_ID"
it fails immediately with the following error
Underlying error (domain=FBSOpenApplicationServiceErrorDomain, code=4):
If I build and run the exact same scheme and configuration (Debug) directly from Xcode, into the exact same simulator instance, the app launches and runs perfectly without any issues.
This is my full build and run bash script.
Which fails on the last command.
xcodebuild -project MyProject.xcodeproj \
-configuration Debug \
-scheme "MyAppScheme (Debug)" \
-destination 'platform=iOS Simulator,name=iPhone 16 Pro' \
-derivedDataPath build
APP_PATH="build/Build/Products/Debug-iphonesimulator/MyAppName.app" SIMULATOR_TARGET="..."
BUNDLE_ID="com.mycompany.myapp.debug"
xcrun simctl install "$SIMULATOR_TARGET" "$APP_PATH"
xcrun simctl launch "$SIMULATOR_TARGET" "$BUNDLE_ID"
What I’ve Tried (and didn’t resolve the issue):
-
Verified Bundle ID: Confirmed the $BUNDLE_ID used in simctl launch exactly matches the CFBundleIdentifier in the built Info.plist.
-
Verified .app Path: Confirmed the $APP_PATH exists and points to the correct .app bundle after the build.
-
Manual Launch: Tapping the icon on the simulator after simctl install also fails to launch the app properly (appears to crash or simply doesn’t open).
-
Simulator Logs: Checked logs via Console.app on the Mac, filtering for the simulator and the app’s bundle ID/name around the time of the failed launch. Found no obvious crash reports or specific errors explaining the launch failure. Also tried xcrun simctl spawn booted log stream –level debug without pinpointing the cause.
-
Erase Simulator: Used “Device -> Erase All Content and Settings…” on the simulator and tried the install/launch process again.
-
Clean Build: Used xcodebuild clean before rebuilding.
-
Checked Scheme Settings: Verified in Xcode (Edit Scheme -> Run -> Arguments) that “Environment Variables” and “Arguments Passed On Launch” are both completely empty for the Debug configuration.
-
Checked Build Settings: Confirmed SKIP_INSTALL = NO for the Debug configuration.
-
Checked Build Phases: Confirmed the scheme is correctly configured to build the main application target.
-
Checked Info.plist Validity: Confirmed CFBundleVersion is a valid integer string (e.g. 1 or 123).
What could explain this discrepancy where the app runs perfectly from Xcode, but consistently fails to launch via xcrun simctl launch with FBSOpenApplicationServiceErrorDomain, given all the troubleshooting steps already performed?
Are there any other potential causes related to the simctl launch environment, specific system service interactions, or subtle build differences that I might be missing? What further diagnostic steps could help the root cause of this command-line launch failure?