安卓学习笔记(21)-flutter doctor时显示X Unable to locate Android SDK的解决方案

时间:2024-04-07 09:56:52

安卓学习笔记(21)-flutter doctor时显示X Unable to locate Android SDK的解决方案

​ 在安装flutter之后,打算开启一个demo测试一下,结果出现了这么一句话:

Unable to locate a development device; please run ‘flutter doctor’ for information about installing additional components.

​ 于是运行flutter doctor:出现了如下内容:

[✓] Flutter (on Linux, locale en_US.UTF-8, channel master)

[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.io/setup/#android-setup for detailed instructions).
If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.

[✓] Android Studio (version 3.0.0)
• Android Studio at /home/f/App/android-studio
• Gradle version 3.2
• Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] Connected devices(1 available)

中间的那条 ✗ Unable to locate Android SDK困惑了很久,因为Android的所有的SDK都已经更新过了,不能因为要安装flutter就卸载重新装一个。于是在网上查了一下,但是网上关于这一块的解决方案还是比较少的,最后在https://github.com/flutter/flutter/issues/13078找到了思路。其实就是添加环境变量ANDROID_HOME,把你SDK的位置填上,重启电脑即可。

具体如下:

1.右键此电脑,打开属性,并点击左侧的高级系统设置

安卓学习笔记(21)-flutter doctor时显示X Unable to locate Android SDK的解决方案

2.点击环境变量,在用户变量中添加

ANDROID_HOME
安卓学习笔记(21)-flutter doctor时显示X Unable to locate Android SDK的解决方案
D:\AS\SDK (你SDK的安装路径)

3.重启电脑

4.输入flutter doctor检查一下,出现如下内容基本上就没有问题了

C:\Users\lenovo>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.1.5, on Microsoft Windows [Version 10.0.14393], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.0)
[√] Connected devices (1 available)

! No issues found!