xcode 为什么在此构建脚本中出现“xcodebuild: command not found”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24445229/
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 05:08:21  来源:igfitidea点击:

Why is "xcodebuild: command not found" in this build script?

xcodebashshxcodebuild

提问by Chris

Hi I have the following in the root of my xcode project:

嗨,我的 xcode 项目的根目录中有以下内容:

#!/bin/bash
xcodebuild -scheme target1 clean;
xcodebuild -scheme target1 archive;
xcodebuild -scheme target2 clean;
xcodebuild -scheme target2 archive;

However, this only executes the first line xcodebuild -scheme target1 clean;and then yields

但是,这只执行第一行xcodebuild -scheme target1 clean;,然后产生

...
** CLEAN SUCCEEDED **

xcodebuild: command not found
xcodebuild: command not found
xcodebuild: command not found

Disclaimer: I'm an absolute Mac OS X / Unix greenhorn.

免责声明:我是绝对的 Mac OS X / Unix 新手。

Edit: Following kranteg's suggestion I added pwd to the script:

编辑:按照 kranteg 的建议,我在脚本中添加了 pwd:

#!/bin/bash
pwd;
xcodebuild -scheme target1 clean;
pwd;
xcodebuild -scheme target1 archive;
pwd;
xcodebuild -scheme target2 clean;
pwd;
xcodebuild -scheme target2 archive;
pwd;

The output:

输出:

/Users/CKU/Programme/uraClient
=== CLEAN TARGET uraClient OF PROJECT uraClient WITH CONFIGURATION Debug ===

Check dependencies

<... lots of compiler messages about the clean ...>

** CLEAN SUCCEEDED **

/Users/CKU/Programme/uraClient
xcodebuild: command not found
/Users/CKU/Programme/uraClient
xcodebuild: command not found
/Users/CKU/Programme/uraClient
xcodebuild: command not found
/Users/CKU/Programme/uraClient

Edit 2: Replacing the pwd with echo $PATH yields a better result, now the script performs the first three xcodebuild commands before failing. However, the PATH variable seems to be unaffected by xcodebuild:

编辑 2:用 echo $PATH 替换 pwd 会产生更好的结果,现在脚本在失败之前执行前三个 xcodebuild 命令。但是,PATH 变量似乎不受 xcodebuild 的影响:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
=== CLEAN TARGET uraClient OF PROJECT uraClient WITH CONFIGURATION Debug ===

<... log messages ...>

** CLEAN SUCCEEDED **

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
=== BUILD TARGET uraClient OF PROJECT uraClient WITH CONFIGURATION Release ===

<... log messages ...>

** ARCHIVE SUCCEEDED **


The following commands produced analyzer issues:
    AnalyzeShallow uraClient/SQLiteLibrary/SQLiteManager.m
    AnalyzeShallow uraClient/URA/NSString+UrlEncoding.m
    AnalyzeShallow uraClient/Services/UraTripPredictionsProvider.m
    AnalyzeShallow uraClient/UtilityAppViewController/ViewController.m
    AnalyzeShallow uraClient/RNCryptor/RNDecryptor.m
    AnalyzeShallow uraClient/RNCryptor/RNEncryptor.m
    AnalyzeShallow uraClient/RNCryptor/RNOpenSSLCryptor.m
    AnalyzeShallow uraClient/RNCryptor/RNOpenSSLDecryptor.m
    AnalyzeShallow uraClient/RNCryptor/RNOpenSSLEncryptor.m
(9 commands with analyzer issues)
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
=== CLEAN TARGET uraAseag OF PROJECT uraClient WITH CONFIGURATION Debug ===

<... log messages ..>

** CLEAN SUCCEEDED **

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
xcodebuild: command not found
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:Desktop/adt-bundle-mac-x86_64-20130522/sdk/platform-tools

回答by Chris

With the help of kranteg & Opal I've come up with a working solution:

在 kranteg & Opal 的帮助下,我想出了一个可行的解决方案:

#!/bin/bash
/usr/bin/xcodebuild -scheme target1 clean archive;
/usr/bin/xcodebuild -scheme target2 clean archive;
/usr/bin/xcodebuild -scheme target3 clean archive;
<...>

Thanks again for the relentless community support, I would have given up otherwise :-)

再次感谢社区的无情支持,否则我会放弃:-)

Note: I've found that each scheme has a post-action step for the "Archive" action, that I had forgotten about:

注意:我发现每个方案都有一个“存档”操作的后操作步骤,我已经忘记了:

xcrun -sdk iphoneos PackageApplication "$ARCHIVE_PRODUCTS_PATH/$INSTALL_PATH/$WRAPPER_NAME" -o "${HOME}/Desktop/${PRODUCT_NAME}.ipa"

This automatically creates .ipa files for Ad-Hoc deployment. Maybe this interfered with the original build script by changing a working directory. However, I don't understand why that would not register with the pwdand echo $PATHlogging.

这会自动为 Ad-Hoc 部署创建 .ipa 文件。也许这会通过更改工作目录来干扰原始构建脚本。但是,我不明白为什么这不会在pwdecho $PATH日志记录中注册。

回答by Saif

xcodebuildcommand will not work when Command Lines Tools is not setup for xcode.

xcodebuild当没有为 xcode 设置命令行工具时,命令将不起作用。

Make sure that latest command line tools are selected (Under Xcode> Preferences> Locations)

确保最新的命令行工具选择(在Xcode> Preferences> Locations

enter image description here

在此处输入图片说明

回答by Caleb

Make sure that you've installed Xcode's command line tools. Go to the Xcode->Preferences... Command and look for the panel that lets you download additional packages and documentation. IIRC, the command line tools can be installed from there.

确保您已经安装了 Xcode 的命令行工具。转到 Xcode->Preferences... 命令并查找可让您下载其他包和文档的面板。IIRC,可以从那里安装命令行工具。