Flutter报错:Android toolchain “but Android SDK not found at this location”

「爱情、让人受尽委屈。」 2023-08-17 16:42 250阅读 0赞

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 不再指定的路径中。

  1. $ flutter doctor
  2. Doctor summary (to see all details, run flutter doctor -v):
  3. [✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)
  4. [✗] Android toolchain - develop for Android devices
  5. ANDROID_HOME = /usr/local/opt/android-sdk
  6. but Android SDK not found at this location.
  7. [✓] Xcode - develop for iOS and macOS (Xcode 10.1)
  8. [✓] Android Studio (version 3.5)
  9. [!] IntelliJ IDEA Ultimate Edition (version 2019.2)
  10. Flutter plugin not installed; this adds Flutter specific functionality.
  11. Dart plugin not installed; this adds Dart specific functionality.
  12. [!] IntelliJ IDEA Community Edition (version 2019.1.3)
  13. Flutter plugin not installed; this adds Flutter specific functionality.
  14. Dart plugin not installed; this adds Dart specific functionality.
  15. [✓] VS Code (version 1.35.1)
  16. [✓] Connected device (1 available)

解决办法

可以看到提示信息里有ANDROID_HOME的路径:

  1. ANDROID_HOME = /usr/local/opt/android-sdk

打开 Android Studio 查看配置 【Preferences】:

查看SDK的路径: 【Apperance & Behavior】 > 【System Settings】 > 【Android SDK】

可以看到当前的 SDK 路径是:

  1. /Users/wangtom/Library/Android/sdk

而 flutter doctor 诊断提示的路径 /usr/local/opt/android-sdk ,明细不一致。

现在我们将环境变量 ANDROID_HOME 的路径改成和 Android Studio 的SDK路径一样:

  1. $ export ANDROID_HOME="/Users/wangtom/Library/Android/sdk"

注意: 该配置修改仅在本次开机生效,如果重启了电脑需要再次执行。
如果想长期生效请在 ~/.bash_profile 文件中添加该环境变量。

查看一下配置变量:

  1. $ echo $ANDROID_HOME
  2. /Users/wangtom/Library/Android/sdk

再重新执行 flutter doctor 继续诊断。这次不提示SDK路径对了,提示 一些证书没有同意。

  1. $ flutter doctor
  2. Doctor summary (to see all details, run flutter doctor -v):
  3. [✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)
  4. [!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
  5. ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
  6. [✓] Xcode - develop for iOS and macOS (Xcode 10.1)
  7. [✓] Android Studio (version 3.5)
  8. [!] IntelliJ IDEA Ultimate Edition (version 2019.2)
  9. Flutter plugin not installed; this adds Flutter specific functionality.
  10. Dart plugin not installed; this adds Dart specific functionality.
  11. [!] IntelliJ IDEA Community Edition (version 2019.1.3)
  12. Flutter plugin not installed; this adds Flutter specific functionality.
  13. Dart plugin not installed; this adds Dart specific functionality.
  14. [✓] VS Code (version 1.35.1)
  15. [✓] Connected device (1 available)

安装提示执行 flutter doctor --android-licenses 命令,同意每个正式即可。

  1. // 每个证书选择 y 都同意即可
  2. $ flutter doctor --android-licenses
  3. ...
  4. Accept? (y/N): y
  5. 2/5: License android-sdk-preview-license:
  6. Accept? (y/N): y
  7. 3/5: License google-gdk-license:
  8. ...

再次执行flutter doctor验证

最后再次执行 flutter doctor 验证一下,Android toolchain 也验证正常了。

  1. $ flutter doctor
  2. Doctor summary (to see all details, run flutter doctor -v):
  3. [✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)
  4. [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
  5. [✓] Xcode - develop for iOS and macOS (Xcode 10.1)
  6. [✓] Android Studio (version 3.5)
  7. [!] IntelliJ IDEA Ultimate Edition (version 2019.2)
  8. Flutter plugin not installed; this adds Flutter specific functionality.
  9. Dart plugin not installed; this adds Dart specific functionality.
  10. [!] IntelliJ IDEA Community Edition (version 2019.1.3)
  11. Flutter plugin not installed; this adds Flutter specific functionality.
  12. Dart plugin not installed; this adds Dart specific functionality.
  13. [✓] VS Code (version 1.35.1)
  14. [✓] Connected device (1 available)
  15. ! Doctor found issues in 2 categories.

还有提示 IntelliJ IDEA Ultimate EditionIntelliJ IDEA Community Edition 两个软件的警告,因为也没打算用这2个软件来开发 Flutter, 忽略即可。

Reference

[EDN]

发表评论

表情:
评论列表 (有 0 条评论,250人围观)

还没有评论,来说两句吧...

相关阅读