简介信息
1. 问题背景
随着苹果iPhone 14的发布,Xcode也推送了更新。
更新以后,和同事一样都遇到了相同的bug——git用不了:使用git命令会报下面这个错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| $ git 2022-09-19 15:21:51.777 xcodebuild[14474:4015692] [MT] DVTPlugInLoading: Failed to load code for plug-in com.apple.dt.IDESimulatorAvailability (/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin), error = Error Domain=NSCocoaErrorDomain Code=3588 "dlopen(/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, 0x0109): Symbol not found: (_OBJC_CLASS_$_SimDiskImage) Referenced from: '/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability' Expected in: '/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator'" UserInfo={NSLocalizedFailureReason=The bundle couldn’t be loaded., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, NSDebugDescription=dlopen(/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, 0x0109): Symbol not found: (_OBJC_CLASS_$_SimDiskImage) Referenced from: '/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability' Expected in: '/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator', NSBundlePath=/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin, NSLocalizedDescription=The bundle “IDESimulatorAvailability” couldn’t be loaded.}, dyldError = dlopen(/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, 0x0000): Symbol not found: (_OBJC_CLASS_$_SimDiskImage) Referenced from: '/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability' Expected in: '/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator' 2022-09-19 15:21:51.877 xcodebuild[14474:4015692] [MT] DVTAssertions: ASSERTION FAILURE in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot2/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/DVTFrameworks/DVTFrameworks-21303/DVTFoundation/PlugInArchitecture/DataModel/DVTPlugIn.m:374 Details: Failed to load code for plug-in com.apple.dt.IDESimulatorAvailability (/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin) Please ensure Xcode packages are up-to-date — try running 'xcodebuild -runFirstLaunch'.
NSBundle error: Error Domain=NSCocoaErrorDomain Code=3588 "dlopen(/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, 0x0109): Symbol not found: (_OBJC_CLASS_$_SimDiskImage) Referenced from: '/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability' Expected in: '/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator'" UserInfo={NSLocalizedFailureReason=The bundle couldn’t be loaded., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, NSDebugDescription=dlopen(/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability, 0x0109): Symbol not found: (_OBJC_CLASS_$_SimDiskImage) Referenced from: '/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin/Contents/MacOS/IDESimulatorAvailability' Expected in: '/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator', NSBundlePath=/Applications/Xcode.app/Contents/PlugIns/IDESimulatorAvailability.ideplugin, NSLocalizedDescription=The bundle “IDESimulatorAvailability” couldn’t be loaded.} Object: <DVTPlugIn: 0x6000032adcc0> Method: -loadAssertingOnError:error: Thread: <_NSMainThread: 0x6000016fc480>{number = 1, name = main} Hints:
Backtrace: 0 0x000000010243ff81 1 0x000000010243f4b5 2 0x000000010243f6c1 3 0x00000001022b63ba 4 0x0000000102271c73 5 0x000000010226fa1f 6 0x00007ff81590b317 7 0x00007ff8159187ee 8 0x000000010248e5a1 9 0x00000001024640d8 10 0x000000010226f8a3 11 0x000000010226faf5 12 0x0000000103354f66 13 0x0000000103354526 14 0x0000000103353919 15 0x0000000100cdc9a4 16 0x0000000100a5f20a sh: line 1: 14476 Abort trap: 6 /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find git 2> /dev/null git: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find git 2> /dev/null' failed with exit code 34304: (null) (errno=Invalid argument) xcode-select: Failed to locate 'git', requesting installation of command line developer tools.
|
尽管按照苹果的这个提示,下载、安装完了,但也依然不好使。
尝试了其它几种方法安装git,好多方法是依赖brew的,而brew本身,又是依赖git的。
2. 解决方法
有两种方法可以解决这个问题:
- 打开Xcode,会让你选择安装哪个组件、然后还会再安装一次依赖;
- 把git切换到CommandLineTools:
具体就是这个命令:
$ sudo xcode-select --switch /Library/Developer/CommandLineTools
3. 2/3个一样的git
CommandLineTools的git位于这个位置:
/Library/Developer/CommandLineTools/usr/bin/git
Xcode的git位于这个位置:
/Applications/Xcode.app/Contents/Developer/usr/bin/git
而具体执行的git命令,位于这个位置:
/usr/bin/git
三个文件都是可执行文件,但略有差异:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| $ ls -l /Applications/Xcode.app/Contents/Developer/usr/bin/git /Library/Developer/CommandLineTools/usr/bin/git /usr/bin/git -rwxr-xr-x 1 root wheel 6480800 Aug 28 05:46 /Applications/Xcode.app/Contents/Developer/usr/bin/git -rwxr-xr-x 1 root wheel 6480800 Aug 28 05:46 /Library/Developer/CommandLineTools/usr/bin/git -rwxr-xr-x 76 root wheel 167120 Aug 24 16:59 /usr/bin/git $ md5 /Applications/Xcode.app/Contents/Developer/usr/bin/git /Library/Developer/CommandLineTools/usr/bin/git /usr/bin/git MD5 (/Applications/Xcode.app/Contents/Developer/usr/bin/git) = 2d28c1a09e1981a6df9d5c46a7605371 MD5 (/Library/Developer/CommandLineTools/usr/bin/git) = 2d28c1a09e1981a6df9d5c46a7605371 MD5 (/usr/bin/git) = b804370957619edc6510439fed2b35b0 $ file /Applications/Xcode.app/Contents/Developer/usr/bin/git /Library/Developer/CommandLineTools/usr/bin/git /usr/bin/git /Applications/Xcode.app/Contents/Developer/usr/bin/git: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64 - Mach-O 64-bit executable x86_64] [arm64] /Applications/Xcode.app/Contents/Developer/usr/bin/git (for architecture x86_64): Mach-O 64-bit executable x86_64 /Applications/Xcode.app/Contents/Developer/usr/bin/git (for architecture arm64): Mach-O 64-bit executable arm64 /Library/Developer/CommandLineTools/usr/bin/git: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64 - Mach-O 64-bit executable x86_64] [arm64] /Library/Developer/CommandLineTools/usr/bin/git (for architecture x86_64): Mach-O 64-bit executable x86_64 /Library/Developer/CommandLineTools/usr/bin/git (for architecture arm64): Mach-O 64-bit executable arm64 /usr/bin/git: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64 - Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e - Mach-O 64-bit executable arm64e] /usr/bin/git (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/git (for architecture arm64e): Mach-O 64-bit executable arm64e
|
可以看出:
- /usr/bin/git下的文件是一个单独的副本,不是软链接,但体积明显小于其它两个;
- 从md5值可以看出,CommandLineTools下面的和Xcode下面的是同一个文件的两个副本;
- 而/usr/bin/git这个文件,经过实验,在使用
xcode-select --switch xxx
切换时,其md5值是固定的,也就是切换的时候不会引起/usr/bin/git文件的变化。
推测:感觉/usr/bin/git
这个文件是通过类库的方式调用的其它依赖代码,而依赖代码影响到了Xcode的运行。