xcode 使用 xcodebuild 在模拟器上构建和运行应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34003723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:16:15  来源:igfitidea点击:

Build and run an app on simulator using xcodebuild

iosxcodeshellios-simulatorxcodebuild

提问by Lorenzo B

I have the following goal to achieve: build and run an .appapplication using xcodebuildand ios-sim.

我有以下目标要实现:.app使用xcodebuildand构建和运行应用程序ios-sim

I'm using the following script to build the application.

我正在使用以下脚本来构建应用程序。

xcrun xcodebuild \
  -scheme $XCODE_SCHEME \
  -project $XCODE_PROJECT \
  -configuration Debug \
  -destination generic/platform=iOS \
  -derivedDataPath \
  build

Then for running it, I'm using

然后为了运行它,我正在使用

ios-sim launch MyApp.app/ --devicetypeid "iPhone-6-Plus, 9.1"

Each time I receive the following message:

每次我收到以下消息:

Program specified by service does not contain one of the requested architectures: ?

服务指定的程序不包含所请求的体系结构之一: ?

What is happening, that the app doesn't run?

发生了什么,应用程序没有运行?

Note:if I run the second command (ios-sim...) against the .appbuilt from Xcode (the one contained in derived data) the procedure works fine.

注意:如果我ios-sim...针对.app从 Xcode 构建的命令(包含在派生数据中的命令)运行第二个命令 ( ),则该过程运行良好。

回答by Lorenzo B

Ok. Figured out the issue.

好的。想通了这个问题。

You need to specify the correct destination. For example.

您需要指定正确的destination. 例如。

xcrun xcodebuild \
  -scheme $XCODE_SCHEME \
  -project $XCODE_PROJECT \
  -configuration Debug \
  -destination 'platform=iOS Simulator,name=iPhone 6 Plus,OS=9.1' \
  -derivedDataPath \
  build

In this way Xcode will create the folder (called build) containing your products (in particular look at Debug-iphonesimulator). The builddir is created within the dir you are running the xcodebuildcommand.

通过这种方式,Xcode 将创建build包含您的产品的文件夹(称为)(特别是查看Debug-iphonesimulator)。该build目录是在您运行xcodebuild命令的目录中创建的。

Now you can point that folder in order to run the ios-simcommand (see ios-simfor more references) or simctl(see iOS 8: Building custom simulatorsand Build And Run iOS Apps In Commmand Linefor more info).

现在您可以指向该文件夹以运行ios-sim命令(请参阅ios-sim以获取更多参考)或simctl(请参阅iOS 8:构建自定义模拟器在命令行中构建并运行 iOS 应用程序以获取更多信息)。