Instead of passing the argument --sdk_root
for each single command execution, let’s deep dive into the real cause.
Starting from Android SDK Command-line Tools 1.0.0 (6200805), in contrast to Android SDK 26.1.1 (4333796), the tools
directory hierarchy has been changed.
Previously it was placed right inside ANDROID_HOME
(which is deprecated, we will use the term ANDROID_SDK_ROOT
for the rest of the paragraph), now it’s still named as tools
(the only thing you’ll get after unpacking the downloaded commandlinetools zip file), but differently, you have to place it inside a directory called cmdline-tools
on your own. The name cmdline-tools
comes from its package name, where you can get from listing packages command sdkmanager --list
, whose outputs include cmdline-tools;1.0 | 1.0 | Android SDK Command-line Tools
.
Wrapping tools
directory inside cmdline-tools
directory would make it work, and help you get rid of the annoying --sdk_root
argument. But what about the other parts?
Well, that’s all you have to change. Let me explain more.
- The king –
sdkmanager
lives insidecmdline-tools/tools/bin
, you’d better set inPATH
environment variable cmdline-tools
should not be set asANDROID_SDK_ROOT
. Because later, when updating Android SDK, or installing more packages, the other packages will be placed underANDROID_SDK_ROOT
, but not undercmdline-tools
.- The final, complete
ANDROID_SDK_ROOT
directory structure should look like below, consist of quite a few sub-directories:build-tools
,cmdline-tools
,emulator
,licenses
,patcher
,platform-tools
,platforms
,system-images
. You can easily point out thatbuild-tools
andcmdline-tools
are siblings, all sit inside the parentANDROID_SDK_ROOT
.
Let me recap in a simple way:
- Set your preferred
ANDROID_SDK_ROOT
(just like before) - Download and unpack the commandlinetools zip file into a directory called
cmdline-tools
, which is insideANDROID_SDK_ROOT
- Append the directory
$ANDROID_SDK_ROOT/cmdline-tools/tools/bin
to environment variablePATH
, so that the system knows where to findsdkmanager
!!UPDATE!!
The behavior has changed again since the build 6858069
(Android SDK Command-line Tools 3.0):
- After unzipping the package, the top-most directory you’ll get is
cmdline-tools
. - Rename the unpacked directory from
cmdline-tools
totools
, and place it under$ANDROID_SDK_ROOT/cmdline-tools
, so now it should look like:$ANDROID_SDK_ROOT/cmdline-tools/tools
. And inside it, you should have:NOTICE.txt bin lib source.properties
. Actually according to the official Command-Line Tools doc, the tree structure should beandroid_sdk/cmdline-tools/version/bin/
, but I’ve checked, usingversion
ortools
makes no difference here. - For your environment variable
PATH
, I would recommend you to set like this:PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/cmdline-tools/tools/bin
, because after update later, you’ll get the latestsdkmanager
placed under$ANDROID_SDK_ROOT/cmdline-tools/latest/bin
, put it in front will make it higher priority.