Flutter报错:Android toolchain “but Android SDK not found at this location”
Flutter报错:Android toolchain “but Android SDK not found at this location”
当前环境
- macOS 10.13.6
- Android Studio 3.5
- Android Studio 3.5
- Flutter 1.9.1+hotfix.2
Dart 2.5.0
$ flutter —version
Flutter 1.9.1+hotfix.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 2d2a1ffec9 (3 weeks ago) • 2019-09-06 18:39:49 -0700
Engine • revision b863200c37
Tools • Dart 2.5.0
报错“Android SDK not found at this location”
使用 flutter doctor 命令可以诊断当前的 flutter 环境的一些配置和工具的情况。
在本机环境中执行,报错 Android SDK 不再指定的路径中。
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)
[✗] Android toolchain - develop for Android devices
✗ ANDROID_HOME = /usr/local/opt/android-sdk
but Android SDK not found at this location.
[✓] Xcode - develop for iOS and macOS (Xcode 10.1)
[✓] Android Studio (version 3.5)
[!] IntelliJ IDEA Ultimate Edition (version 2019.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Community Edition (version 2019.1.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.35.1)
[✓] Connected device (1 available)
解决办法
可以看到提示信息里有ANDROID_HOME的路径:
ANDROID_HOME = /usr/local/opt/android-sdk
打开 Android Studio 查看配置 【Preferences】:
查看SDK的路径: 【Apperance & Behavior】 > 【System Settings】 > 【Android SDK】
可以看到当前的 SDK 路径是:
/Users/wangtom/Library/Android/sdk
而 flutter doctor 诊断提示的路径 /usr/local/opt/android-sdk ,明细不一致。
现在我们将环境变量 ANDROID_HOME 的路径改成和 Android Studio 的SDK路径一样:
$ export ANDROID_HOME="/Users/wangtom/Library/Android/sdk"
注意: 该配置修改仅在本次开机生效,如果重启了电脑需要再次执行。
如果想长期生效请在 ~/.bash_profile
文件中添加该环境变量。
查看一下配置变量:
$ echo $ANDROID_HOME
/Users/wangtom/Library/Android/sdk
再重新执行 flutter doctor 继续诊断。这次不提示SDK路径对了,提示 一些证书没有同意。
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 10.1)
[✓] Android Studio (version 3.5)
[!] IntelliJ IDEA Ultimate Edition (version 2019.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Community Edition (version 2019.1.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.35.1)
[✓] Connected device (1 available)
安装提示执行 flutter doctor --android-licenses
命令,同意每个正式即可。
// 每个证书选择 y 都同意即可
$ flutter doctor --android-licenses
...
Accept? (y/N): y
2/5: License android-sdk-preview-license:
Accept? (y/N): y
3/5: License google-gdk-license:
...
再次执行flutter doctor验证
最后再次执行 flutter doctor 验证一下,Android toolchain 也验证正常了。
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 10.1)
[✓] Android Studio (version 3.5)
[!] IntelliJ IDEA Ultimate Edition (version 2019.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Community Edition (version 2019.1.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.35.1)
[✓] Connected device (1 available)
! Doctor found issues in 2 categories.
还有提示 IntelliJ IDEA Ultimate Edition
和 IntelliJ IDEA Community Edition
两个软件的警告,因为也没打算用这2个软件来开发 Flutter, 忽略即可。
Reference
[EDN]
还没有评论,来说两句吧...