99

C:\Android\sdk\bin>sdkmanager Error: Could not determine SDK root. Error: Either specify it explicitly with --sdk_root= or move this package into its expected location: \cmdline-tools\latest\

it shows like this, even after specifying the root in env variables. ANDROID_SDK_ROOT C:\Android\sdk

I am using windows 10 64 bit machine, I want to run flutter without android studio so followed instruction on this page https://medium.com/@quicky316/install-flutter-sdk-on-windows-without-android-studio-102fdf567ce4

alakmar Shafin
  • 3,177
  • 2
  • 7
  • 17

15 Answers15

207

Since new updates, there are some changes that are not mentioned in the documentation. After unzipping the command line tools package, the top-most directory you'll get is cmdline-tools. Rename the unpacked directory from cmdline-tools to tools, and place it under $C:/Android/cmdline-tools

now it will look like $C:/Android/cmdline-tools/tools

and it will work perfectly.

alakmar Shafin
  • 3,177
  • 2
  • 7
  • 17
  • 9
    brilliant!! how did you found that solution? – Mirjalal Aug 10 '21 at 09:37
  • Android being Android. They included some warnings in the command line results, like this one: `Error: Either specify it explicitly with --sdk_root= or move this package into its expected location: /cmdline-tools/latest/` – Paulo Cheque Mar 31 '22 at 20:23
  • worked for me on mac as well. – Ahsan Tarique Jul 06 '22 at 21:13
  • As I tried, just make sure you add a "tools" directory and move everything else in "cmdline-tools" to "tools", that's good enough. I don't have to put it to C:/Android directory. – Jcyrss Apr 15 '23 at 03:11
  • I had the folder structure C:/Android/android-sdk/cmdline-tools. When the folder structure changed as mentioned above (C:/Android/cmdline-tools/tools), it worked! – DiluzFerz Apr 29 '23 at 12:41
89

Downloading the Android SDK 29+ (command line tools for Android) from https://developer.android.com/studio#downloads.

For "commandlinetools-linux-7302050_latest.zip" the process was different from earlier approaches. Earlier after unpacking, the top folder was called tools, but now the top folder is called cmdline-tools.

The problem seems to be that the sdkmanager expects to reside in an environment called. /YOURPATH/cmdline-tools/SOMETHING/bin but unpacks to /YOURPATH/cmdline-tools/bin for Linux anyway.

if you get

Error: Could not determine SDK root.

Error: Either specify it explicitly with --sdk_root= or move this package into its expected location: <sdk>/cmdline-tools/latest/

Unpack and make sure you have this path to the sdkmanager. /YOURPATH/cmdline-tools/latest/bin/sdkmanager

How To

To get this to work, first create the path to your intended Android SDK /opt/android-sdk/cmdline-tools/ then unpack the SDK zip file to that location, and you will have

/opt/android-sdk/cmdline-tools/cmdline-tools/bin/sdkmanager

Now rename the second "cmdline-tools" to "latest"

/opt/android-sdk/cmdline-tools/latest/bin/sdkmanager

And now it should work.

Bo Kristensen
  • 1,460
  • 11
  • 8
  • yep this did the trick. Basically, for anyone struggling, create a folder called "cmdline-tools" where ever you like, you extract the cmdline tools in that folder, rename what you extracted to "latest". Now you go into the bin folder in latest, open a cmd there and run commands like: sdkmanager --license – Liban Jul 11 '23 at 05:23
28

You can create a folder latest inside your cmdline-tools and move all it's contents inside this folder. So, your full path will be C:\Android\cmdline-tools\latest\bin. Using this config there is no need to define a ANDROID_SDK_ROOT environment variable or a --sdk_root= option. It'll assume that your SDK folder is C:\Android, and it'll put all your files (system-images, licenses, ...) inside it.

Marcelo Barros
  • 930
  • 9
  • 16
  • 1
    this answer is not just for android itself. it solved my `flutter doctor --android-licenses` problem in one single go: "Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to resolve this." – Yılmaz Durmaz Nov 24 '21 at 15:17
16

I successfully configured the command-line-tools in my mac.

  • Big Sur 11.6.4
  • commandlinetools-mac-8092744_latest.zip (6.0)

Downloaded a zip archive and unzip it.

% unzip commandlinetools-mac-8092744_latest.zip
% mv cmdline-tools latest
% mkdir sdk
% mkdir sdk/cmdline-tools
% mv latest sdk/cmdline-tools

This looks like this.

┌ sdk
│    ├ cmdline-tools
│    │     ├ latest
│    │     │     ├ bin
│    │     │     ├ lib
│    │     │     ├ NOTICE.txt
│    │     │     ├ source.properties

run sdkmanager

% ./sdk/cmdline-tools/latest/bin/sdkmanager
[============================] 100% Computing updates...
Andrew Shepherd
  • 44,254
  • 30
  • 139
  • 205
iroiroys
  • 788
  • 1
  • 10
  • 17
9

If you don't want to move it to another location, you can use --sdk_root to specify the folder where do you want to install and download Android SDK.

For example, if you want to use: X:\Dev\AndroidSDK and you downloaded and unziped your the command line tools package in that folder, you'll have this path: X:\Dev\AndroidSDK\cmdline-tools\bin for sdkmanager.bat.

So, your command will be:

X:\Dev\AndroidSDK\cmdline-tools\bin>.\sdkmanager.bat --sdk_root=X:\Dev\AndroidSDK

PS: Don't use spaces on the path to AndroidSDK or it will not work

Juan Antonio Tubío
  • 1,172
  • 14
  • 28
8

• Go to extracted folder android-sdk\cmdline-tools
• Create a folder named latest in it.
• Cut bin , lib ...etc & paste in latest folder.
• Go to cmd of android-sdk\cmdline-tools\latest folder and run:

sdkmanager “platform-tools” “platforms;android-28”

It solves the problem

exploitr
  • 843
  • 1
  • 14
  • 27
Sharma AK
  • 79
  • 1
  • 3
6

I have been facing this error on Ubuntu server 18.04, and it appears that the problem comes from the path. It should be different than what is given when you the download the zip. This is what I did to solve the problem in my case :

~> wget https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip

~> unzip commandlinetools-linux-8092744_latest.zip

~> mkdir android-sdk

~> mv cmdline-tools android-sdk

~> cd android-sdk/cmdline-tools; mkdir latest 

~> mv ./* latest

# */ So the path will be now :
# android-sdk/cmdline-tools/latest/bin

# instead of android-sdk/cmdline-tools/bin

~> nano ~/.bashrc

# add these two lines :

export ANDROID_HOME=$HOME/android-sdk
export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$PATH

# save the file

source ~/.bashrc

# Try this now, it should work.

sdkmanager --list 

4hbane
  • 139
  • 1
  • 10
4
  1. You need put all the files and folders in this new folder tools

       `C:/Android/cmdline-tools/tools`
    

OR Alternative step

2.1. type cmd C:\Android\cmdline-tools\bin

2.2. type in the promt sdkmanager.bat --sdk_root=C:\Android

3

if you get an error Error: Could not determine SDK root. Error: Either specify it explicitly with --sdk_root= or move this package into its expected location: \cmdline-tools\latest\

then use command with sdk root specified like:

sdkmanager --sdk_root=path-to-where-cmdline-tools-is "platform-tools" "platforms;android-29"

1

Some of the answers below might have worked for others but for my case, they didn't work until I figured this.

  1. Do not change the directory name upon extracting the zip file. (cmdline-tools)
  2. open the source.property file using notepad or any respective editor to check your SDK manager version.
  3. Update your system variable paths i.e $C:/Android/cmdline-tools/4.0/bin in this context 4.0 is my SDK manager version upon writing this and thereafter close the terminal and reopen it again and run sdkmanager --version

Good luck Enjoy your development process!

13Tracso
  • 479
  • 4
  • 8
1

I'm installing Android Studio for Flutter on my Mac. The following steps solve the problem:

  1. The original unzipped folder is cmdline-tools. Change the folder hierarchy into cmdline-tools > latest. That means creating a new directory latest under cmdline-tools and moving everything to latest. TL;DR If you look at the zip file name carefully, you'll find out that its name indicates that this is the latest one. You can have many versions of cmdline-tools but the latest directory means what is inside it is the latest one. Let's why we have to create a new directory.

  2. Find out where the Android SDK is located. Open Android Studio and navigate to Preference > Appearance & Behavior > System Settings > Android SDK. The Android SDK Location is where your Android SDK is installed. For me, it is /Users/myname/Library/Android/sdk. Open your Finder and navigate to it. enter image description here

  3. Move the cmdline-tools under the sdk directory. Double check that you have sdkmanager under /Users/myname/Library/Android/sdk/cmdline-tools/latest/bin/sdkmanager

  4. Follow what Flutter implies us to do. Run /Users/myname/Library/Android/sdk/cmdline-tools/latest/bin/sdkmanager --install "cmdline-tools;latest" in your terminal. This tells where the latest sdkmanager is. enter image description here

  5. Run flutter doctor -v in your terminal again. The problem should be fixed.

Michael Revlis
  • 1,463
  • 11
  • 14
1

My solution on macOS:

  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
  - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip

  # unzip the zip and name it with 'android-sdk'
  - unzip -d android-sdk android-sdk.zip

  # you can remove useless zip if you want
  - rm android-sdk.zip 

  # create a new directory android-sdk-latest
  - mkdir android-sdk-latest; cd android-sdk-latest
  - mkdir cmdline-tools; cd cmdline-tools
  # create a new directory: android-sdk-latest/cmdline-tools/latest
  - mkdir latest
  - cd ../..

  # then move all files to new created latest directory
  - mv android-sdk/cmdline-tools/* android-sdk-latest/cmdline-tools/latest

  - export ANDROID_HOME=$PWD/android-sdk-latest
  - export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$PATH

  - echo y | android-sdk-latest/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
  - echo y | android-sdk-latest/cmdline-tools/latest/bin/sdkmanager "platform-tools" >/dev/null
  - echo y | android-sdk-latest/cmdline-tools/latest/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null

I have a problem when I want to remove all file into a new created latest directory: cannot remove latest to latest/latest. So I did this to resolve the problem.

You can also remove android-sdk directory after removing all sub files and change the name of android-sdk-latest to android-sdk.

Hope this can help you.

Yuman Yin
  • 71
  • 4
0

I came across this answer while I was trying to accept package license for android package with sdkmanager

Open bin folder ( I have downloaded from android side, https://developer.android.com/studio#downloads) I got the cmdline tools from here.

First I tried this bin> %ANDROID_HOME%\tools\bin\sdkmanager.bat --licenses

Got error - could not determined ask root

Then I tried this one

bin>sdkmanager.bat --licenses --sdk-root\E:\Android

Pravin Ghorle
  • 606
  • 7
  • 7
0

change the path to like this

C:/Android/cmdline-tools/tools/bin 

it worked for me perfectly

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Mohamed Atef
  • 477
  • 4
  • 6
0

Try the below command it will work perfectly:

sdkmanager --sdk_root=path-to-where-cmdline-tools-is "platform-tools" "platforms;android-29"
Ranoiaetep
  • 5,872
  • 1
  • 14
  • 39
Afnan Zia
  • 9
  • 2
  • There is no explanation as to why this answer should work and even when I do try to run the suggested command I get `Failed to create SDK root dir: path-to-where-cmdline-tools-is` – Nikitas IO Mar 05 '23 at 21:15