如何从命令行构建Xcode项目? [英] How to build Xcode project from the command line?

查看:464
本文介绍了如何从命令行构建Xcode项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试阅读 Apple提供的Xcode Tools文档,因此我可以使用终端生成.app文件并在Simulator上运行生成的应用程序.本质上,我想做的事情与Cmd + R在Xcode上所做的相同.

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.

到目前为止,我已经尝试过这样构建我的.xcodeproj:

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"

更不用说xcrun simctl launch booted "com.example.apps.MyApp"行永远不会终止,并且在Simulator上它一直尝试打开并重新打开该应用程序,但是该应用程序只会显示黑屏.

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.

如果有人能告诉我我在构建.xcodeproj时做错了什么,那太好了!

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

推荐答案

在Xcode中进行了有效的配置后,打开一个外壳并导航到<NAME>.xcodeproj所在的目录.

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

运行后:

xcodebuild -list -project <NAME>.xcodeproj/

您会看到方案的列表.

复制所需的方案名称并运行:

Copy the desired scheme name and run:

xcodebuild -scheme <SCHEME NAME> build

您可以安装 ios部署,即通过以下方式安装:

You can install ios-deploy i.e. via:

npm install -g ios-deploy

xcodebuild 输出的末尾复制应用程序路径并运行:

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.

这篇关于如何从命令行构建Xcode项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆