34

I've tried reading the Xcode Tools documentation Apple provides, so that I can use the Terminal to build a .app file and run the resulting app on the Simulator. Essentially what I want to do is do the same thing as Cmd + R does on Xcode.

So far I've attempted to build my .xcodeproj like this:

xcodebuild -configuration Debug build

However, when I install & run it on the Simulator I get an app w/ a black screen:

// Boot device
xcrun simctl boot "iPhone 7" 
// Install app
xcrun simctl install "iPhone 7" "/Users/.../MyApp/build/Debug-iphoneos/MyApp.app"
// Open simulator
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
// Launch app using its bundle id
xcrun simctl launch booted "com.example.apps.MyApp"

Not to mention the xcrun simctl launch booted "com.example.apps.MyApp" line never terminates and on the Simulator it keeps trying to open and reopen the app, but the app only ever shows a black screen.

If anyone could tell me what I'm doing wrong with the building of the.xcodeproj that would be great!

14wml
  • 4,048
  • 11
  • 49
  • 97

2 Answers2

48

After having a working configuration in Xcode, open a shell and navigate to the directory, where your <NAME>.xcodeproj resides.

After running:

xcodebuild -list -project <NAME>.xcodeproj/

you see a list of Schemes.

Copy the desired scheme name and run:

xcodebuild -workspace <WORKSPACE NAME> -scheme <SCHEME NAME> build

You can install [ios-deploy][1] i.e. via:

npm install -g ios-deploy

Copy the app path from the end of the xcodebuild output and run:

ios-deploy --debug --bundle <APP PATH>

Now the app should be launched on i.e. a connected device. [1]: https://github.com/phonegap/ios-deploy

mr5
  • 3,438
  • 3
  • 40
  • 57
Tsunamis
  • 5,870
  • 1
  • 20
  • 22
0

@Tsunamis' answer is wonderful.

Also, if your project has a package, that uses some specific iOS libraries like UIKit, and you are having errors about UI controls not found, you can compile the package using this command line:

xcodebuild -scheme <package -sdk "`xcrun --sdk iphonesimulator --show-sdk-path`" -target x86_64-apple-ios14.0-simulator

LightMan
  • 3,517
  • 31
  • 31