不能通过 flutter 找到 Android SDK

我已经安装了 flutter到 AUR。我也已经安装了 aur/android-sdk 26.0.2-1。当我运行 flutter run我得到:

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.

首先,我运行 flutter --version,收到:

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

不知道“看看你的道路上有什么风吹草动”到底是什么意思。接下来我运行 flutter doctor并得到:

[✓] 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

然而,如果我 cd 到 /opt/android-sdk我得到:

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

所以它看起来就在那里。我能找到的最接近的问题是这个: 反应原生机器人构建失败。找不到 SDK 位置,但它似乎是使用 Mac 而不是 arch,以及其他一些差异。我如何解决 flutter doctor和让我的应用程序运行?

204508 次浏览

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.

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

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.

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 !!

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

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.

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.

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.

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!

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

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

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

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

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.

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.

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.

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"

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\Леон>

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!

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

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

enter image description here

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\

In my case, I have to accept the android licenses

run this command in the terminal or android studio terminal

flutter doctor --android-licenses