結論
% sudo xcode-select -switch /Library/Developer/CommandLineTools
を実行したあと、~/.zshrc
のSDKROOT
の行を以下のように修正した。
export SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk"
ファイル名のMacOSX13.1.sdk
はバージョン番号が人によって違うとおもう。
経緯
MacOSをVenturaに上げたところ、Gitを認識しなくなった。
% git --version
2023-01-03 18:36:20.234 xcodebuild[19006:5027592] Writing error result bundle to /var/folders/rq/6yk7prw57gxfc_jmg4jj69_00000gn/T/ResultBundle_2023-03-01_18-36-0020.xcresult
xcodebuild: error: SDK "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" cannot be located.
git: error: Failed to determine realpath of '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk' (errno=No such file or directory)
git: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -find git 2> /dev/null' failed with exit code 16384: (null) (errno=No such file or directory)
xcode-select: Failed to locate 'git', requesting installation of command line developer tools.
インストールを促すポップアップが出るので言われるがままインストールするが、解決しなかった。
この問題、OSのアップデートするたび毎回直面している気がするけど毎回対応方法を忘れているので、
ググって出てきた以下のコマンドを実行。
% xcode-select -p
/Applications/Xcode.app/Contents/Developer
↑/Applications~~
のパスが返る場合は以下を実行するとよいとのことなので実行
% sudo xcode-select -switch /Library/Developer/CommandLineTools
これでGitは動くようになったが、こんどはflutter doctor
したときにXcodeのエラーが出るようになった
✗ Xcode installation is incomplete; a full installation is necessary for iOS
development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
メッセージはsudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
を実行するように求めているが、これをすると最初の
% xcode-select -p
/Applications/Xcode.app/Contents/Developer
の状態に戻ってしまうので戻せない。さてどうしたものかと悩んだ。
解決方法
最初のログをよく見ると
xcodebuild: error: SDK "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" cannot be located.
とある。MacOSX12.3.sdk
を参照している様子。
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
を見に行くと
MacOSX.sdk MacOSX13.1.sdk MacOSX13.sdk
しかなかった。12.3
は無い。
OSバージョンアップのときに同時に消えちゃったのか、よくわからないまま消してしまったのかはわからないが、いずれにせよ参照先のバージョンとして正しくないので修正する。
このパスは~/.zshrc
に記載されていたので、以下のように修正した。
export SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk"
ターミナルを再起動(あるいは再読み込み)して、git --version
とflutter doctor
が両方正しく動くことを確認。
% git --version
git version 2.37.1 (Apple Git-137.1)
% flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.3, on macOS 13.1 22C65 darwin-x64, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.74.2)
[✓] Connected device (1 available)
[✓] HTTP Host Availability
参考