Home > Net >  Flutter doctor can't find Android SDK, but everything is set
Flutter doctor can't find Android SDK, but everything is set

Time:04-14

I'm on Ubuntu 20.04 LTE

My Android SDK Location (shown in Android studio) is /home/myuser/Android/Sdk

The error goes as follows:

✗] 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, please use
  `flutter config --android-sdk` to update to that location.

What I did to try to fix it:

  1. Fresh installs of both Flutter (via snap) and Android studio (via apt, because when I install it also via snap, Flutter can't find even Android studio then).
  2. Set configs:
    • flutter config --android-sdk="/home/myuser/Android/Sdk"
    • flutter config --android-studio-dir="/opt/android-studio-2021.1.1/android-studio"
  3. Set paths in .bashrc:
    • export ANDROID_HOME=$HOME/Android/Sdk/
    • export PATH=$PATH:$ANDROID_HOME/tools/
    • export PATH=$PATH:$ANDROID_HOME/platform-tools/
  4. In Android studio, I installed:
    • Dart and Flutter plugins.
    • SDK Platforms: 9.0(Pie), 10.0(Q), 11.0(R), 12.0(S), Android API 32
    • SDK Tools:
      • Android SDK Build-Tools 33-rc2
      • Android SDK Command-line Tools (latest)
      • Android Emulator 31.2.9
      • Android SDK PLatform-Tools 33.0.1
  5. Trying to do flutter doctor --android-licenses doesn't do anything as it can't find Android SDK.

And I also can't run flutter doctor without adding sudo, because it stops after the first result and then runs for infinity.

CodePudding user response:

I use ubuntu too and the below is my environment.

Please try something like this in your vim ~./bashrc or vim ~/.zshrc

Change the paths as it is in your environment:

  • JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
  • PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
  • export JAVA_HOME
  • export JRE_HOME
  • export PATH
  • export PATH=$PATH:~/development/flutter/bin

if it doesn't work try installing Flutter manually:

https://docs.flutter.dev/get-started/install/linux#install-flutter-manually

CodePudding user response:

As the error message says, ANDROID_SDK_ROOT or previously known as ANDROID_HOME are not set in your environment variables.

To fix that, you will need to:

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

Due to some legacy reasons, there are a few variables pointing to the same thing. To make sure your Flutter SDK is getting it, you can set all of them.

Note: if you don't want to set them every time your laptop reboots, feel free to add them into ~/.bashrc.

Theoretically, during the installation of Android Studio, the variables above should be set for you, but, in reality, it doesn't always happen which is the reason you are seeing the error message.

  • Related