How to build Xcode project from the command line?

旧城冷巷雨未停 提交于 2019-12-04 11:04:15

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/45681264/how-to-build-xcode-project-from-the-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!