Android SDK cannot be found by flutter
Asked Answered
M

26

95

I have installed flutter through AUR. I also have aur/android-sdk 26.0.2-1 installed. When I run flutter run I get:

Warning! This package referenced a Flutter repository via the .packages file that is
no longer available. The repository from which the 'flutter' tool is currently
executing will be used instead.
  running Flutter tool: /home/dair/.flutter-sdk
  previous reference  : /home/dair/flutter
This can happen if you deleted or moved your copy of the Flutter repository, or
if it was on a volume that is no longer mounted or has been mounted at a
different location. Please check your system path to verify that you are running
the expected version (run 'flutter --version' to see which flutter is on your path).

Unable to locate a development device; please run 'flutter doctor' for information about installing additional components.

Firstly, I ran flutter --version, and received:

Flutter • channel alpha • https://github.com/flutter/flutter.git
Framework • revision e2f54df5ab (9 days ago) • 2017-06-02 10:43:54 -0700
Engine • revision 1f2aa07571
Tools • Dart 1.24.0-dev.3.0

Not sure what exactly it means by "to see which flutter is on your path". Next I ran flutter doctor and got:

[✓] Flutter (on Linux, locale en_US.UTF-8, channel alpha)
    • Flutter at /home/christopher/.flutter-sdk
    • Framework revision e2f54df5ab (9 days ago), 2017-06-02 10:43:54 -0700
    • Engine revision 1f2aa07571
    • Tools Dart version 1.24.0-dev.3.0

[✗] Android toolchain - develop for Android devices
    ✗ ANDROID_HOME = /opt/android-sdk
      but Android SDK not found at this location.

[✓] Android Studio (version 2.3)
    • Android Studio at /usr/local/android-studio
    • Gradle version 3.2
    • Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] Connected devices
    • None

However, if I cd into /opt/android-sdk I get:

➜  ~ cd /opt/android-sdk 
➜  android-sdk ls
add-ons  build-tools  emulator  platforms  tools

So it looks like it is there. The closest question I could find is this one: React Native android build failed. SDK location not found but it seems to be using Mac as opposed to arch as well as some other differences. How can I resolve the flutter doctor and have my app run?

Messick answered 11/6, 2017 at 16:0 Comment(0)
D
132

I was running with the same problem when I was trying the flutter doctor command:

enter image description here

The problem is a little clear, it's occurring because the flutter is not founding the path for your Android SDK.

There are two ways to solve it:

  • You can solve this issue setting only for your current terminal instance the SDK path with the following commands:

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

    flutter config --android-studio-dir /path/to/android/studio

  • Or to save it forever, exporting the ANDROID_HOME with your Android sdk path.

I solved it by exporting the ANDROID_HOME on my machine (Arch Linux, but this works for any Unix instance).

This will solve your issue, But you can need the sdk, platform-tools, tools and the ndk-build paths too (of course, everything needs to be installed first) on my profile file (in my case the .zshrc file, the same can be done on your .bashrc and etc.):

#SDK exporting - this will solve your issue
export ANDROID_HOME=/home/{user}/Android/Sdk 

#Tools exporting - it can be need in your case
export PATH=/home/{user}/Android/Sdk/platform-tools:$PATH
export PATH=/home/{user}/Android/Sdk/tools:$PATH
export PATH=/home/{user}/Android/ndk-build:$PATH

#Flutter binary exporting
export PATH=/home/{user}/flutter/bin:$PATH

Then, I reloaded my profile file (that in my is the .zshrc file, use your file in your case .eg .bashrc):

source ~/.zshrc

After that, the flutter doctor will run properly.

enter image description here

Dave answered 2/8, 2018 at 1:53 Comment(5)
flutter config --android-sdk /path/to/android/sdk This worked for me. ThanksStylize
I added the ANDROID_HOME but flutter couldnt locate it. I did alot of searches in github too but none of them resulted.Debidebilitate
@Debidebilitate did you edit the correct file for your shell? Which OS are you using?Dave
Added ANDROID_HOME to path first, didn't work. Then tried flutter config --android-sdk /path/to/android/sdk and it worked. Thanks a million times.Nasalize
flutter config --android-sdk /path/to/android/sdk, when i did this the android studio warn me • Android Studio at /path/to/android/studio/Contents • Flutter plugin can be installed from: 🔨 plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 plugins.jetbrains.com/plugin/6351-dart ✗ Android Studio not found at /path/to/android/studio/Contents • Try updating or re-installing Android Studio.Atmosphere
T
65

If you're using Android Studio 3, you can configure your platform SDK by going to File -> Project structure and choose your platform SDK.

Hope this works for you.

enter image description here

Talich answered 19/3, 2018 at 3:41 Comment(0)
D
36

I have solved this problem by the following command flutter config --android-sdk <sdk-location> Where is the location for your sdk. If you're on windows make sure to use double quotes.

Doolittle answered 14/4, 2018 at 6:28 Comment(0)
C
25

For Windows: Inside Android Studio, get path from : Apprearance & Behaviour > System Settings > Android SDK > Android SDK path

Make sure your path does not contain any spaces in them, if you have edit path and re-install sdk to a different location.

After that,

flutter config --android-sdk {path}
flutter doctor --android-licenses

You are set!

Contravention answered 21/2, 2021 at 11:13 Comment(1)
For me, the issue is that the path to Android SDK contains spaces. Thank you very much !Depose
N
11

To get the Android SDK path - Open Flutter project in Android Studio - Go to File > Project Structure > SDK Location. Copy the location

To set the Android SDK path - Type in terminal flutter config --android-sdk /path/that/you/just/copied

Nianiabi answered 8/7, 2019 at 13:26 Comment(1)
Am having the same issue for ios, it was working properly, but now whenever I run flutter doctor, I get this result ✗ CocoaPods not installed. CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see flutter.dev/platform-plugins To install: sudo gem install cocoapods and 'sudo gem install cocoapods' never worksAmey
R
10

i have solved! i put my android SDK before in F:/androidsdk so when i run "flutter config" android sdk doesnt linked. To link flutter wiht android sdk just type command below:

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

i just change with this

flutter config --android-sdk F:/androidsdk

i hope this is working.

Regretful answered 30/11, 2018 at 6:25 Comment(1)
Thank you. before I used () in this line and emit error , but I use (/) and issue is fix.Briarroot
B
8

I suffered alot trying to find a solution to it and finally I found the solution by configuring the project SDK
File -> Project structure then choose sdk platform.

Brei answered 14/12, 2018 at 13:1 Comment(0)
H
5

Go to the project structure and make sure the sdk version is selected. Project Structure Image

Hofstetter answered 19/3, 2020 at 7:9 Comment(0)
S
3

Flutter requires the Android SDK platform tools so that it can use the adb command line tool.

It looks like you've installed the Android SDK but you haven't installed the platform tools yet.

Here is the android-sdk-platform-tools Aur package for arch and a guide for how to install it.

Possibly the error message could be improved to indicate that we are actually missing the Android SDK platform tools rather than the Android SDK itself. If you want to, feel free to send a pull request or open an issue.

Spinozism answered 11/6, 2017 at 16:18 Comment(1)
Ok thanks! This seems to get me a bit further. I'm going to do a little more debugging to see if I can resolve it completely before I accept. Android studio had a few problems the past couple of days on arch. Typical rolling release model haha.Messick
I
3
flutter config --android-studio-dir <path where android studio is installed>

In my case it was "C:\Program Files\Android\Android Studio"

try with double quotes in the command( I tried with double quotes, which might be necessary if there is space in the path)

Source: https://flutter.dev/docs/get-started/install/windows#android-setup

Intertidal answered 29/6, 2021 at 15:48 Comment(0)
M
1

It is saying that your project is using two different path of flutter-sdk. There are two place where sdk paths are defined.

  1. Setting (Setting > Language&Frameworks > Flutter > Flutter SDK path)

enter image description here

  1. local.properties in your root folder

enter image description here

These both place should contain same path to sdk.Compile with flutter run !! done !!

Monger answered 20/7, 2018 at 9:34 Comment(0)
A
1

The solution at https://github.com/flutter/flutter/issues/15114#issuecomment-376582281 worked for me, this worked after adding $ANDROID_SDK_PATH\platform-tools to user path variable.

Abdulabdulla answered 4/2, 2019 at 3:20 Comment(0)
I
1

For me, the Android SDK command-line tools were missing, i.e. installing Android Studio did not install the command-line tools automatically.

I had to run Android studio and use the included SDK manager to install the Android SDK Command-line Tools

Start Android Studio, select More Actions... > SDK Manager, select the SDK Tools tab, make sure to check Android SDK Command-line Tools (latest), click Apply. This will install the Android SDK command-line tools.

After that, flutter doctor completed successfully. No need to set flutter config --android-sdk ... etc.

$ uname -a
Linux x220 6.1.0-7-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.20-2 (2023-04-08) x86_64 GNU/Linux
Inhaul answered 3/5, 2023 at 10:3 Comment(0)
O
0

I've set up my Android SDK manually on Windows 10 with the command line, I think this not change a lot in Linux, and I was able to solve this kind of errors while I tried to set up my development environment, if you want to solve it as I did, just follow the next steps that I posted in a GitHub Comment in a related issue:

https://github.com/flutter/flutter/issues/19805#issuecomment-478306166

I hope this can help anyone need it! Bye!

Overcheck answered 31/3, 2019 at 19:50 Comment(0)
T
0

in environment variables make Variables: ANDROID_HOME

and add path of SDK get from Andriod stideo --> settings --> SDK Coppy the Path examlpe

:C:\Users\Omar\AppData\Local\Android

Add the SDK path in variables Value: C:\Users\Omar\AppData\Local\Android

Next Step: Add 2 value in path variables :

 %ANDROID_HOME%\tools 

%ANDROID_HOME%\platform-tools
Tears answered 2/3, 2020 at 22:38 Comment(0)
L
0

For macOS Catalina: If you have installed android sdk to a custom location (say /Users/your_username/dev/android/sdk) then follow these steps (NOTE: You must change the location according to your sdk location):

  1. Open zshrc file

    nano ~/.zshrc

  2. Add the following to the zshrc file

    export ANDROID_HOME=Users/your_username/dev/android/sdk
    export ANDROID_SDK_ROOT=$ANDROID_HOME
    export ANDROID_AVD_HOME=$HOME/.android/avd

  3. Save and close nano using Ctrl+x, when prompted type y

  4. Source your zshrc file using

    source $HOME/.zshrc

  5. You can check whether your problem is fixed by typing the following in a terminal window. You should get the sdk path as your output

    echo $ANDROID_SDK_ROOT

Lamond answered 9/9, 2020 at 8:40 Comment(0)
C
0

For Windows 10 Version 2004

I added a user environment variable named ANDROID_HOME and value is {SDK-PATH}\build-tools\{SDK-VERSION}. You have to replace SDK-PATH and SDK-VERSION for your custom values.

And I appended another value named %ANDROID_HOME% to system PATH variable.

Then it worked as expected.

Castor answered 11/9, 2020 at 20:10 Comment(0)
M
0

for me, it was very simple.

this kind of issue usually happens if IDE unable to load SDK.

so to solve this follow below steps:

goto file menu -> project structure -> project settings -> select "project"

now set Android SDK path with existing java version.

then select "modules" and configure Android SDK and click on apply and then click ok.

now we may find both ios and android emulators to run your flutter app on both devices.

Minnesota answered 24/11, 2020 at 13:54 Comment(0)
P
0

You Can follow the first answer above. I would like to add a tip. If you are on windows and installed sdk on a path that requires admin rights to modify, then flutter doctor might fail to recognise the sdk. Copy the sdk folder to another non-admin location and then run flutter config --android-sdk command.

Prae answered 21/1, 2021 at 17:21 Comment(2)
This should be a comment on the 1st answer rather than being another answer.Saar
I need 50 reputations for that. I will definitely move this post to comment once I get there. Thank you.Prae
F
0

Windows command to fix SDK path

As mentioned above by others, using the below command works:

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

Remember to put quotes in the /path/to/android/sdk

Example: flutter config --android-sdk "C:\Users\UserName\AppData\Local\Android\Sdk"

Footpad answered 24/1, 2021 at 15:15 Comment(0)
B
0

Under Windows 10 (without Android Studio) I noticed that folder 'sdk/build-tools' is empty. Then I solved this problem by executing:

sdkmanager build-tools;30.0.3

where 'build-tools;30.0.3' was obtained in an output of "sdkmanager --list >list.txt" command.

And, after build-tools's installation the error "Android SDK cannot be found by flutter" was solved too!

PS. It is absolutely essential to read carefully the documentation (there were although another mistakes by me)

PS.PS. The log (for illustration):

[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.17763.1697], locale ru-UA)
[!] Android toolchain - develop for Android devices
    X 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/windows#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
      You may also want to add it to your PATH environment variable.

    X No valid Android SDK platforms found in d:/Android\SDK\platforms. Candidates were:
        - android-13
        - android-19
        - android-23
        - android-29
[!] Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    X android-studio-dir = d:\Android
    X Unable to find bundled Java version.
[√] VS Code (version 1.53.1)
[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.

C:\Users\Леон>sdkmanager build-tools;30.0.3

[=======================================] 100% Unzipping... android-11/renderscr
C:\Users\Леон>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.17763.1697], locale ru-UA)

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[!] Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    X android-studio-dir = d:\Android
    X Unable to find bundled Java version.
[√] VS Code (version 1.53.1)
[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.

C:\Users\Леон>
Bundesrat answered 10/2, 2021 at 9:2 Comment(0)
S
0

I had a similar error. Adding Flutter path of extracted flutter sdk till flutter fixed it

enter image description here

Sudhir answered 15/7, 2021 at 8:30 Comment(0)
G
0

We need to fix this in the tool. You can work around this locally by running flutter config --android-studio-dir='C:\Program Files\Android\Android Studio' , which you can check with explorer. For me this path is C:\Program Files\Android\Android Studio\

Glenoid answered 26/7, 2021 at 4:51 Comment(0)
A
0

In my case, I have to accept the android licenses

run this command in the terminal or android studio terminal

flutter doctor --android-licenses
Apotheosis answered 6/1, 2022 at 18:52 Comment(0)
S
0

I'm going to write my experience here on a mac. The real difference to the other answers is that I was confused as to where the installs were, where they should be found and also how confusion was caused by multiple versions of both Android Studio & the sdk existing on my mac.

You to need find two main directories; the sdk location and the installation directory of Android Studio.

sdk

The sdk seemed to have been installed twice and referenced in different places. One of which was installed by brew so I uninstalled that one. The one I ended up referencing is the following. I think that is the proper location on a mac (don't use brew)

/Users/myusername/Library/Android/sdk/

sdk references

Run this command

flutter config --android-sdk sdk_path_here

and set these environment & path variables

export ANDROID_HOME=sdk_path_here 
export PATH=sdk_path_here/platform-tools:$PATH
export PATH=sdk_path_here/tools:$PATH

Android Studio reference

Again there were multiple installs and multiple locations of Android Studio. You may have installed yours manually and it would be installed in the following location
flutter config --android-studio-dir=/Applications/Android\ Studio.app

but I had updated to the JetBrains Toolbox so mine was installed there (I uninstalled the other version of Studio). The one I referenced was

/Users/yourusername/Applications/JetBrains\ Toolbox/Android\ Studio.app

So I ran the following to set the Android Studio location

flutter config --android-studio-dir=/Users/yourusername/Applications/JetBrains\ Toolbox/Android\ Studio.app

After that I still was presented with an error but I restarted my whole machine, deleted previously created AVDs in Studio's Device Manager and then everything did indeed work as expected.

Stallworth answered 28/3, 2023 at 23:14 Comment(0)
K
0

I experienced the same issue and solved it with these simple steps:

  1. Open Android Studio.
  2. In the top navigation bar, click Tools -> Android SDK.
  3. Copy the Android SDK location path, for example /Users/yourname/Library/Android/sdk
  4. Click 'Edit' next to the Android SDK location.
  5. Check Android SDK option/s (this might already be pre-selected).
  6. Click 'next' then continue installation.
  7. Restart Android Studio.
  8. Open the Android Studio terminal and command flutter config --android-sdk pastetheAndroidSDKlocationpathhere.
  9. Run flutter doctor.
Kenric answered 25/4, 2023 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.