linux ubuntu Unable to locate a development device; please run 'flutter doctor' for information

0. 序言

配置环境这种小事,看似小,有时候还是很浪费时间的,我这里是Ubuntu操作系统,Mac Os和Windows相似,参考下也能很快配置好。

1. 问题

首先下载好了Flutter的SDK,然后在AndroidStudio上安装好了Flutter和Dart的插件,JDK也配置好了,重启,创建Flutter项目,运行报以下错误:

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

2. 解决

① 进入Flutter SDK的bin目录下,运行flutter doctor

$flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Linux, locale en_US.UTF-8)
[✗] 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.
      You may also want to add it to your PATH environment variable.

[✓] Android Studio (version 3.1)
[!] IntelliJ IDEA Ultimate Edition (version 2018.2)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (1 available)

! Doctor found issues in 2 categories.

IntelliJ IDEA的错误我们不用管,只是我的另外一个IDE,重点看

Unable to locate Android SDK

② 配置Android SDK

$cd ~
$sudo gedit ~/.bashrc

在文件中加入

export PATH=/home/ruzhi/Desktop/flutter/bin:$PATH

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

export ANDROID_HOME=/home/ruzhi/fukq/Android/Sdk
export PATH=$PATH:$ANDROID_HOME:$ANDROID_HOME/build-tools:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

分别配置了Flutter、Java JDK、Android SDK的环境变量

$source ~/.bashrc

让配置文件生效

$echo $ANDROID_HOME
/home/ruzhi/fukq/Android/Sdk

如果出现以上信息,说明配置正确

$flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Linux, locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses
[✓] Android Studio (version 3.1)
[!] IntelliJ IDEA Ultimate Edition (version 2018.2)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.

按照提示,执行以下代码:

$flutter doctor --android-licenses
...
All SDK package licenses accepted

出现很多信息,并且以这句话结尾,表示证书安装正确。

$flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Android Studio (version 3.1)
[!] IntelliJ IDEA Ultimate Edition (version 2018.2)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (1 available)

! Doctor found issues in 1 category.

这个时候,表示Android toolchain可以使用了,到此Flutter环境变量配置完毕,但是你运行下AndroidStudio依然没有解决问题:

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

这次一定要在AS终端中输入,记好是AS的终端,flutter doctor:

$flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Android Studio (version 3.1)
[!] IntelliJ IDEA Ultimate Edition (version 2018.2)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

命名我的手机设备没有问题啊,AndroidStudio也显示OK啊,但是Flutter比较特殊,你需要在AS下的终端下输入以下命令

$flutter devices
1 connected device:

OE106 • b237447 • android-arm64 • Android 8.1.0 (API 27)

3. 后续

如果大家喜欢这篇文章,欢迎点赞!
如果想看更多 解决BUG 方面的文章,欢迎关注!

    原文作者:FuKaiqiang_2016
    原文地址: https://blog.csdn.net/fkq_2016/article/details/88579187
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞