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:
- 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).
- Set configs:
flutter config --android-sdk="/home/myuser/Android/Sdk"
flutter config --android-studio-dir="/opt/android-studio-2021.1.1/android-studio"
- Set paths in .bashrc:
export ANDROID_HOME=$HOME/Android/Sdk/
export PATH=$PATH:$ANDROID_HOME/tools/
export PATH=$PATH:$ANDROID_HOME/platform-tools/
- 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
- 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.
4
Answers
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:
if it doesn’t work try installing Flutter manually:
https://docs.flutter.dev/get-started/install/linux#install-flutter-manually
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:
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.
Go to SDK tools and install all Support Repositories. Also check if there are any empty folders inside your SDK folder, if there are any empty folders, please delete them.Then follow the usual steps you mentioned,
Setting the config,
flutter config --android-sdk "/home/myuser/Android/Sdk"
Then finally run the flutter doctor again.
Not sure but maybe the problem is caused by snap, since it was sandboxing the applications you install. I remember having a problem like this on something different. You can try installing flutter manually (downloading the zip and so on…) rather than using snap.