[Solved] Unable to locate the Android SDK – Android

Photo of author
Written By M Ibrahim
android android-sdk-tools flutter flutter-layout flutter-test

Quick Fix: Utilize flutter config --android-sdk /path/to/android/sdk to configure the Android SDK for your project. Additionally, ensure that the PATH variable includes the SDK. Modify /usr/local/opt/android-sdk and 26.0.1 to match your system.

The Problem:

While using Flutter, the ‘flutter doctor’ command is indicating that the Android SDK is not installed, despite the fact that both Android Studio and the Android SDK were already installed before adding Flutter and the Flutter SDK.

The Solutions:

Solution 1: Reconfigure Android SDK Path

To resolve the issue of "Unable to locate the Android SDK", you can configure the Android SDK path for your Flutter project using the following steps:

  1. Open your terminal or command prompt and navigate to the directory where you want to configure the Android SDK.

  2. Run the following command to set the Android SDK path:

flutter config --android-sdk /path/to/android/sdk

Make sure to replace /path/to/android/sdk with the actual path to your Android SDK directory. You can find the Android SDK directory by navigating to the folder where Android Studio is installed and then locating the sdk folder.

  1. Additionally, you need to ensure that the PATH environment variable contains the path to the Android SDK tools. You can do this by running the following command:
export PATH=$PATH:/path/to/android/sdk/tools

Again, replace /path/to/android/sdk/tools with the actual path to the tools directory within the Android SDK directory.

  1. You may need to adjust the specific paths in the commands above to match your system configuration. For example, the path to the Android SDK and the tools directory may vary depending on your operating system and installation location.

  2. Once you have updated the Android SDK path and added it to the PATH variable, run the flutter doctor command again. This should now show that the Android SDK is properly configured for your Flutter project.

Solution 2: Configure Environment Variables

Step 1: Locate Android SDK Folders

  • Ensure you have the Android SDK Platform and Platform Tools folders.

Step 2: Set System Environment Variables

  • Search for "Env" in Windows.
  • Click on "System Variable Environment."
  • Choose "Advanced and Environment Variable."
  • Under "System Variable," select "Path" and click "Edit."
  • Add the paths to both Platform and Platform Tools folders.

Step 3: Restart PowerShell

  • Close and reopen PowerShell.

Step 4: Accept Android Licenses

  • Run the command "flutter doctor –android-licenses."
  • Accept all licenses by typing "Y."

Step 5: Verify Successful Setup

  • Run "flutter doctor" again to check if the Android SDK is detected correctly.

Solution 3: Set Android SDK path in Flutter Configuration

Configure Flutter to use the Android SDK path manually using the command:


flutter config --android-sdk /your path

Replace "/your path" with the actual path to your Android SDK directory, for example:

flutter config --android-sdk /root/Android/Sdk

Additionally, you can set the path in the Flutter SDK Manager:

  1. Open Flutter SDK Manager.
  2. Click Tools > SDK Manager.
  3. In the Android SDK Location field, specify the path to the Android SDK.

Enter image description here

Solution 4: Locating Android SDK and Setting PATH Variable

  1. Locate Android SDK Folder:
    Locate the folder where the Android SDK is installed. The default installation directory is usually C:\Users\[your_username]\AppData\Local\Android\Sdk on Windows, /usr/local/share/android-sdk on macOS, and ~/Library/Android/sdk on Linux.

  2. Add Platforms and Platform-Tools to PATH Variable:

    • Open the System Settings or Control Panel on your computer.
    • Search for "Environment Variables" and open it.
    • Under User variables, select the PATH variable and click "Edit".
    • Add the following two paths, separated by a semicolon (;):
    <path_to_android_sdk>\platforms
    <path_to_android_sdk>\platform-tools
    

    For example, if your Android SDK is installed at C:\Users\[username]\AppData\Local\Android\Sdk, you would add the following paths:

    C:\Users\[username]\AppData\Local\Android\Sdk\platforms
    C:\Users\[username]\AppData\Local\Android\Sdk\platform-tools
    
  3. Run flutter doctor:
    Open your terminal or command prompt and run the following command:

    flutter doctor
    

This command will check your system for any missing or outdated components required for Flutter development. If the Android SDK is now correctly detected, you should no longer see any errors or warnings related to the Android SDK.