After I used migration assistant to migrate data from my old mac to a new one I can no longer use Xcode command line tools. Whenever I run any xcodebuild
command in terminal (even xcodebuild
with no parameters) I get the following error:
dyld: Library not loaded: @rpath/DVTFoundation.framework/Versions/A/DVTFoundation
Referenced from: /usr/bin/xcodebuild
Reason: image not found
Abort trap: 6
When I run which xcodebuild
I get /usr/bin/xcodebuild
.
When I run xcode-select -p
I get /Applications/Xcode.app/Contents/Developer
.
Strangely, if I go to /Applications/Xcode.app/Contents/Developer/usr/bin
and call ./xcodebuild
I do not get the error above.
Here is what I tried:
- Installing command line tools using
xcode-select --install
. - Uninstalling command line tools located in
/Library/Developer/CommandLineTools/
. - Performing
sudo xcode-select --switch /Library/Developer/CommandLineTools/
. - Performing
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
.
None of these resolves my problem.
I am running Xcode 9.4.1 and macOS High Sierra 10.13.5.
UPDATE 1
I tried following this guide to uninstall Xcode and all command line build tools completely. The strange thing is, once I followed all the steps, running xcodebuild
command produced the same result as before. And xcodebuild
was still located in /usr/bin
.
UPDATE 2
If I install command line tools using xcode-select --install
and go to /Library/Developer/CommandLineTools/usr/bin
running xcodebuild
from that location does produce the same error. So, running xcodebuild
which comes pre-installed with Xcode produces no error, but the one from the command line tools does produce the error. It is puzzling and also suggests that when I try to remove all command line tools, the ones left in my /usr/bin
are the ones which do not come with Xcode.
I tried deleting them, but I am unsuccessful even with the sudo
command.
UPDATE 3
I've found a workaround. To ensure that xcodebuild
command uses the tool located in /Applications/Xcode.app/Contents/Developer/usr/bin
rather than the one located in /usr/bin
, I added the following line to my .bash_profile
:
export PATH="/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH"
This approach works, but my question remains. I do not understand why I had this problem in the first place. I have double checked - my PATH
does not contain /Applications/Xcode.app/Contents/Developer/usr/bin
on my old Mac and everything works just fine there.
Looks like for some reason, xcodebuild
located in /usr/bin
got corrupted and couldn't get updated in any way.