`xcodebuild`无法在终端上工作

And*_*huk 5 macos xcode xcodebuild xcode-command-line-tools macos-high-sierra

在使用迁移助手将数据从旧Mac迁移到新Mac之后,我不再可以使用Xcode命令行工具。每当我xcodebuild在终端中运行任何命令(即使xcodebuild没有参数)时,都会出现以下错误:

dyld: Library not loaded: @rpath/DVTFoundation.framework/Versions/A/DVTFoundation
  Referenced from: /usr/bin/xcodebuild
  Reason: image not found
Abort trap: 6
Run Code Online (Sandbox Code Playgroud)

当我跑步时which xcodebuild我得到/usr/bin/xcodebuild

当我跑步时xcode-select -p我得到/Applications/Xcode.app/Contents/Developer

奇怪的是,如果我去/Applications/Xcode.app/Contents/Developer/usr/bin打电话给./xcodebuild我,我没有得到上面的错误。

这是我尝试过的:

  1. 使用来安装命令行工具xcode-select --install
  2. 卸载位于中的命令行工具/Library/Developer/CommandLineTools/
  3. 表演sudo xcode-select --switch /Library/Developer/CommandLineTools/
  4. 表演sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/

这些都不能解决我的问题。

我正在运行Xcode 9.4.1和macOS High Sierra 10.13.5。

更新1

我尝试按照本指南完全卸载Xcode和所有命令行构建工具。奇怪的是,一旦执行了所有步骤,运行xcodebuild命令就会产生与以前相同的结果。并且xcodebuild仍然位于/usr/bin

更新2

如果我使用安装命令行工具xcode-select --install并从该位置开始/Library/Developer/CommandLineTools/usr/bin运行xcodebuild则会产生相同的错误。因此,运行xcodebuildXcode预先安装的程序不会产生任何错误,但是命令行工具中的程序确实会产生错误。令人费解的是,还建议当我尝试删除所有命令行工具时,剩下/usr/bin的就是Xcode不附带的工具。

我尝试删除它们,但是即使使用该sudo命令也无法成功。

更新3

我找到了一种解决方法。为了确保xcodebuild命令使用的工具位于/Applications/Xcode.app/Contents/Developer/usr/bin而不是中的工具/usr/bin,我在我的代码行中添加了以下代码.bash_profile

export PATH="/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH"

这种方法有效,但我的问题仍然存在。我不明白为什么我首先遇到这个问题。我已经仔细检查过-我的旧Mac上PATH不包含它/Applications/Xcode.app/Contents/Developer/usr/bin,并且一切正常。

看起来由于某种原因,它xcodebuild位于/usr/bin损坏,无法以任何方式更新。