Search code examples
androidflutterubuntudartandroid-sdk-tools

Flutter Doctor not recognizing my ANDROID_SDK environment variables


I have the android-sdk installed from ubuntu's repository but it does not contain the sdkmanager executable and isn't current enough to be compatible with flutter, so I installed the wrapper from snapd that contains it. According to the documentation I have to change my ANDROID_SDK_ROOT env. variable so that it works with it. I have also read that I need to set ANDROID_HOME to the directory (I think it's deprecated but just in case) so I put this in my .profile:

export ANDROID_SDK_ROOT=/snap/androidsdk/current/
export ANDROID_HOME=/snap/androidsdk/current/

I then ran source .profile and restarted my machine, however flutter doctor kept giving me this error:

[!] Android toolchain - develop for Android devices (Android SDK version 27.0.1)
    ✗ Flutter requires Android SDK 29 and the Android BuildTools 28.0.3
      To update the Android SDK visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions.

I know that it's using the wrong path because when I run flutter doctor --android-licenses I receive this error:

Android sdkmanager tool not found (/usr/lib/android-sdk/tools/bin/sdkmanager).

Which points to the path of the the SDK I installed with apt. I have tried flutter config --android-sdk $PATH_TO_SDK but that still has not changed anything. Is there a ppa that contains the sdk manager so that I don't have to try and configure flutter to use the snapd androidsdk or is there something I'm missing/doing wrong?

OS: Ubuntu 20.04

androidsdk (snapd) version: 30 (I would prefer not to use this)

android-sdk (apt) version: 25.0.0 (Which is also below flutter's requirements)


Solution

  • You were using the wrong path for ANDROID_HOME

    Android Studio is not necessary:

    After installing flutter with snap and ensuring "/snap/bin" is in your path:

    1. sudo snap install androidsdk
    2. As regular user: androidsdk "platform-tools" "platforms;android-29" "build-tools;30.0.2"

    This will install the android sdk tools you need into "$HOME/AndroidSDK"

    1. export ANDROID_HOME="$HOME/AndroidSDK"

    2. flutter doctor