lostAtSeaJoshua lostAtSeaJoshua - 2 months ago 16
iOS Question

How to fix DVTToolchain: Failed to load toolchain using Xcode command line tools?

Anytime I run any command with

xcrun
or
xcodebuild
in the terminal it always outputs:


VTToolchain: Failed to load toolchain: : Error Domain=DVTToolchainErrorDomain Code=4 "alleged toolchain directory doesn't contain ToolchainInfo.plist or Info.plist" UserInfo={NSFilePath=/Library/Developer/Toolchains/swift-latest.xctoolchain, NSLocalizedDescription=alleged toolchain directory doesn't contain ToolchainInfo.plist or Info.plist}


I have opened the /Toolchains/switft-latest.xctoolchain and it contains Toolchain.Info.plist, so I am confused on how to fix this error. I have tried reinstalling Xcode and reinstalling Xcode command tools

These are my SDK paths:

xcode-select -p
/Applications/Xcode.app/Contents/Developer

xcrun --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk

Answer

I fixed the issue by removing the link to the latest toolchain in Library/Developer/Toolchains.

$ cd /Library/Developer/Toolchains/
$ ls -l
$ -rw-r--r--@ 1 user  admin  1268976 Sep  3 04:43 swift-latest.xctoolchain
$ rm swift-latest.xctoolchain

I ran xcodebuild right after and I had no error. The issue was from previously downloading a new toolchain and Xcode didn't remove it correctly when I uninstalled it. I had help from this github issue.