Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build Xcode project from the command line?

Tags:

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!

like image 1000
14wml Avatar asked Aug 14 '17 18:08

14wml


People also ask

How do I run Xcode from command line app?

Open Xcode and go to File/New/Project. Find the macOS group, select Application/Command Line Tool and click Next: For Product Name, enter Panagram. Make sure that Language is set to Swift, then click Next.

How do I build in Xcode?

Launch Xcode, then click “Create a new Xcode project” in the Welcome to Xcode window or choose File > New > Project. In the sheet that appears, select the target operating system or platform and a template under Application. In the following sheets, fill out the forms and choose options to configure your project.

What is Apple Xcode command line tools?

The Command Line Tools Package is a small self-contained package available for download separately from Xcode and that allows you to do command line development in OS X. It consists of two components: OS X SDK and command-line tools such as Clang, which are installed in /usr/bin.


1 Answers

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 -scheme <SCHEME NAME> build 

You can install ios-deploy 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.

like image 103
Tsunamis Avatar answered Sep 21 '22 19:09

Tsunamis