当我们用“Flutter run“命令运行我们的flutter项目时,会报出以下错误:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Resolving dependencies...
Note: leak_tracker_flutter_testing is pinned to version 3.0.3 by flutter_test from the flutter SDK.
See https://dart.dev/go/sdk-version-pinning for details.
The current Flutter SDK version is 0.0.0-unknown.
.Because every version of flutter_test from sdk depends on leak_tracker_flutter_testing >=2.0.3 which requires Flutter SDK version >=3.18.0-18.0.pre.54, flutter_test from sdk is forbidden.
So, because flutterdemomobile depends on flutter_test from sdk, version solving failed.
You can try the following suggestion to make the pubspec resolve:
* Try using the Flutter SDK version: 3.22.1.
上面的错误显示我们的flutter test版本有问题,而且flutter的版本位unknown,这样就导致我们无法运行flutter项目了。
为什么会发生错误?
这是因为安装了Xcode软件的原因,它受到xcode的影响,所以你会得到一个错误,例如:当前的Flutter SDK版本是0.0.0-unknown,因为它无法在你的计算机中检测到Flutter SDK版本。
如何解决此问题呢?
我们可以运行下方这个命令:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
如果还不行,报错的话,可以将上方命令替换为:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
我们再使用运行“flutter doctor”命令时,flutter 的版本就会显示出来。100%有效解决!