flutter 找不到 android sdk?

flutter can not find android sdk?

我已经在 ubuntu 18.04 上安装了 flutter,我还安装了 android studio,它工作正常但是当我运行 flutter doctor 时。 flutter 无法找到 android 工具链。并且在 dart 插件和 flutter 插件之前也有红叉。我不知道为什么会这样。我也安装了flutter plugin和dart plugin。但是红叉还在。

flutter doctor出来了

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.dev/docs/get-started/install/linux#android-setup
      for detailed instructions).
      If the Android SDK has been installed to a custom location, set
      ANDROID_SDK_ROOT to that location.
      You may also want to add it to your PATH environment variable.

如错误消息所述,ANDROID_SDK_ROOT 或以前称为 ANDROID_HOME 未在您的环境变量中设置。

要解决这个问题,您需要:

export ANDROID_SDK_ROOT=/path/to/android/studio/installation
export ANDROID_HOME=/path/to/android/studio/installation
export PATH=$PATH:/path/to/android/studio/installation

由于一些遗留原因,有几个变量指向同一事物。为确保您的 Flutter SDK 能够获取它,您可以设置所有这些。

注意:如果您不想在每次笔记本电脑重新启动时都设置它们,请随时将它们添加到 ~/.bashrc

理论上,在安装 Android Studio 期间,应该为您设置上面的变量,但实际上,它并不总是发生,这就是您看到错误消息的原因。