Now I have to download and install the Android SDK and AVD Manager, and then install the APIs, tools through the UI. Is there a way to automate this process?

- 30,738
- 21
- 105
- 131

- 6,434
- 7
- 35
- 44
-
1Possible duplicate of [How to install Android SDK Build Tools on the command line?](http://stackoverflow.com/questions/17963508/how-to-install-android-sdk-build-tools-on-the-command-line) – Ciro Santilli OurBigBook.com Jun 25 '16 at 14:19
-
1Possible duplicate of ["android update sdk" on headless linux](http://stackoverflow.com/questions/2157089/android-update-sdk-on-headless-linux) – phunehehe Aug 16 '16 at 13:01
11 Answers
UPDATE
The latest versions introduce sdkmanager
, a command line tool that allows you to view, install, update, and uninstall packages for the Android SDK.
The sdkmanager
tool is provided in the Android SDK Tools package (25.2.3 and higher) and is located in android_sdk/tools/bin/
.
sdkmanager [--uninstall] [<common args>] [--package_file <file>] [<packages>...]
sdkmanager --update [<common args>]
sdkmanager --list [<common args>]
sdkmanager --licenses [<common args>]
In its first form, installs, or uninstalls, or updates packages.
By default, the listed packages are installed or (if already installed)
updated to the latest version.
--uninstall: uninstalled listed packages.
<package> is a sdk-style path (e.g. "build-tools;23.0.0" or
"platforms;android-23").
<package-file> is a text file where each line is a sdk-style path
of a package to install or uninstall.
Multiple --package_file arguments may be specified in combination
with explicit paths.
In its second form (with --update), all installed packages are
updated to the latest version.
In its third form, all installed and available packages are printed
out.
In its fourth form (with --licenses), show and offer the option to
accept licenses for all available packages that have not already been
accepted.
Common Arguments:
--sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK
containing this tool
--channel=<channelId>: Include packages in channels up to <channelId>.
Common channels are:
0 (Stable), 1 (Beta), 2 (Dev), and 3 (Canary).
--include_obsolete: With --list, show obsolete packages in the
package listing. With --update, update obsolete
packages as well as non-obsolete.
--no_https: Force all connections to use http rather than https.
--proxy=<http | socks>: Connect via a proxy of the given type.
--proxy_host=<IP or DNS address>: IP or DNS address of the proxy to use.
--proxy_port=<port #>: Proxy port to connect to.
* If the env var REPO_OS_OVERRIDE is set to "windows",
"macosx", or "linux", packages will be downloaded for that OS.
So, to update the packages run
sdkmanager --update
To accept the licenses,
yes | sdkmanager --licenses
OLD ANSWER
(Please note: The android
command is deprecated!)
The closer you can get to automation probably is:
android update sdk --no-ui
android
provides these options for automatic updates:
Action "update sdk":
Updates the SDK by suggesting new platforms to install if available.
Options:
-f --force Forces replacement of a package or its parts, even if something has been modified
-u --no-ui Updates from command-line (does not display the GUI)
-o --obsolete Installs obsolete packages
-t --filter A filter that limits the update to the specified types of packages in the form of
a comma-separated list of [platform, tool, platform-tool, doc, sample, extra]
-s --no-https Uses HTTP instead of HTTPS (the default) for downloads
-n --dry-mode Simulates the update but does not download or install anything
If you want to list which packages are available for installation you can use
android list sdk
And you'll obtain an ordered list of packages, for example
Packages available for installation or update: 9
1- ARM EABI v7a System Image, Android API 15, revision 2
2- Intel x86 Atom System Image, Android API 15, revision 1
3- Android Support, revision 8
4- Google AdMob Ads SDK, revision 6
5- Google Analytics SDK, revision 2
6- Google Play APK Expansion Library, revision 1
7- Google Play Billing Library, revision 2
8- Google Play Licensing Library, revision 2
9- Google Web Driver, revision 2
Also you can limit the update only to a desired component if you use the --filter
option
android update sdk --filter <component> --no-ui
where component is one or more of
- the numbers returned by
android list sdk
(i.e. 1, also know as package index) - add-on
- doc
- extra
- platform
- platform-tool
- sample
- source
- system-image
- tool
Or can be one or more specific identifiers. For instance, if you just want to download a small set of specific packages, you could do this:
android update sdk -u --filter platform-tools,android-16,extra-android-support
And you'll just get the platform tools, API level 16 and support package JAR files. This is really handy if you're building a build machine only and would have to pay for downloading all the extra stuff that you'll never use.
To see the available options you can use --help, for example
android --help list sdk
Usage:
android [global options] list sdk [action options]
Global options:
-h --help : Help on a specific command.
-v --verbose : Verbose mode, shows errors, warnings and all messages.
--clear-cache: Clear the SDK Manager repository manifest cache.
-s --silent : Silent mode, shows errors only.
Action "list sdk":
Lists remote SDK repository.
Options:
-o --obsolete : Deprecated. Please use --all instead.
-a --all : Lists all available packages (including obsolete and
installed ones)
--proxy-host: HTTP/HTTPS proxy host (overrides settings if defined)
--proxy-port: HTTP/HTTPS proxy port (overrides settings if defined)
-s --no-https : Uses HTTP instead of HTTPS (the default) for downloads.
-e --extended : Displays extended details on each package
-u --no-ui : Displays list result on console (no GUI) [Default: true]

- 30,738
- 21
- 105
- 131

- 65,697
- 9
- 111
- 134
-
1I'm getting all these third-party "Site authentication" prompts where I have to press enter to continue/skip, is there a way to get rid of those? – Somatik Apr 05 '12 at 14:19
-
2I don't see an "android.exe" for the Windows SDK -- how would you automate SDK installation and configuration on Windows? – Jul 02 '12 at 16:41
-
1Note that in case a package is already installed, you get the nonsensical error such as `Error: Ignoring unknown package filter 'tools'` or `Error: Ignoring unknown package filter 'android-17'`. – Ivan Vučica Mar 08 '13 at 19:55
-
Is there a way to avoid downloading all versions? When I just select one version (14,platform-tools,platform,tool) it does not report an error. But I do not get an 'aapt' tool which I need for android-maven-plugin:3.5.3 – Karussell May 17 '13 at 22:16
-
Ok, this is an issue of the maven-android-plugin: http://stackoverflow.com/q/16619143/194609 which was fixed 2 days ago :) – Karussell May 19 '13 at 07:47
-
Is there any way to accept licenses automatically from command line ? – Snicolas May 28 '13 at 06:59
-
32To accept the license automatically, next version will add a `--accept-license` flag. Meanwhile you can `echo "y" | android update sdk --no--ui` – Snicolas May 28 '13 at 07:15
-
After installing everything, everything looks fine if I check using the GUI but, for some reason, I always have 2 items that remain uninstalled as far as `android list sdk` can see. The weird thing is that they also change as new packages are added to the repository (Looks like last 2 things to be installed). – dzeikei Aug 05 '13 at 05:44
-
2@Snicolas I've written a makefile that uses "expect" to automatically accept the license agreements for now. It's on github (https://github.com/ken-noland/android-autoget-makefile) – Kenneth Noland Nov 06 '13 at 15:35
-
To complement this wonderful answer, here's a comprehensive list of some other packages (e.g. extras): https://github.com/makinacorpus/android-archetypes/wiki/Getting-started%3A-Building-Android-apps-with-Jenkins-CI – Christian García Jul 29 '14 at 16:22
-
1Just for further reference, Options for --filter. A filter that limits the update to the specified types of packages in the form of a comma-separated list of [platform, system-image, tool, platform-tool, doc, sample,source]. This also accepts the identifiers returned by 'list sdk --extended'. – Francois Oct 22 '14 at 13:45
-
Example -- filter update: android update sdk -u --filter platform,platform-tool,extra-android-support,extra-google-m2repository,extra-android-m2repository – Francois Oct 22 '14 at 13:52
-
I had to add `--all` flag in order to bypass "Ignoring unknown package filter" error. – eigenein Mar 19 '15 at 14:44
-
-
And the `android` tool now seems deprecated: https://developer.android.com/studio/tools/help/android.html looks like Studio is the way now. – Ciro Santilli OurBigBook.com Jun 25 '16 at 14:36
-
Would recommend to use --extended to get the specific parameter for filtering, the id could be different across machine. – jernkuan Sep 30 '16 at 21:02
This didn't work for me...
echo "y" | android ....
So I ended up here:
expect -c '
set timeout -1 ;
spawn sudo /opt/android-sdk/tools/android update sdk -u;
expect {
"Do you accept the license" { exp_send "y\r" ; exp_continue }
eof
}
'

- 30,738
- 21
- 105
- 131

- 10,239
- 14
- 60
- 76
-
2This looks very similar to the solution provided here: http://stackoverflow.com/a/6674626/3063884 ... is attribution required? – CJBS Aug 15 '14 at 19:24
-
3@CJBS Nope. I came to the same conclusion that guy did. Once you learn "expect" this result is pretty much the only one you can come up with... but thanks for providing the attribution anyway. – danb Aug 18 '14 at 22:57
-
4
-
This only worked after removing sudo and then fixing the android tool path. – Pellet Jan 14 '16 at 06:48
I use this to install and update the SDK on Travis CI:
curl --location http://dl.google.com/android/android-sdk_r22.3-linux.tgz | tar -x -z -C $HOME
export ANDROID_HOME=$HOME/android-sdk-linux
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk --no-ui --filter platform-tool,android-19,sysimg-19,build-tools-19.0.1

- 30,738
- 21
- 105
- 131

- 9,147
- 2
- 48
- 38
-
2For me the option -a was also needed in order for all the packages specified in the filter to be found. – alfoks Dec 07 '15 at 10:29
-
The sleep script worked good but the top answer with yes is much more elegant – Dragan Marjanović Aug 25 '20 at 13:49
To answer all licenses with 'y', you can try this in the script:
(while :
do
echo 'y'
sleep 2
done) | android update sdk -u .....

- 128
- 4
- 7
-
12I cannot confirm this working. I get an error sounding like " 'y y y y y y y y' is not a valid answer", that's why I fell back to the solution with a sleep between. – npstr Oct 29 '13 at 17:21
-
What do you mean by *"answer all licenses"*? What do the questions look like? Can you provide some examples? (But ***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today.) – Peter Mortensen Dec 30 '21 at 21:09
For anyone still searching for a method to download all Android packages, I have wrote a script to do that. It will download all non-obsoleted packages.
#!/binbash
# Install all non-obsolete Android SDK packages.
# author: Tai Le Tien (letientai299 at gmail.com)
function install_sdk {
android update sdk -u -s -a -t "$1"
}
function fetch_non_obsoled_package_indices {
# Fetch the SDK list using non-https connections
android list sdk -u -s -a |\
# Filter obsoleted packages
sed '/\(Obsolete\)/d' |\
# Filter to take only the index number of package
sed 's/^[ ]*\([0-9]*\).*/\1/' |\
# Remove the empty lines
sed -n 's/^[^ $]/\0/p'
}
for package_index in $(fetch_non_obsoled_package_indices)
do
echo "====================================================================="
echo "Start to install package: ${package_index}"
echo "====================================================================="
# Auto accept license
echo -e "y" | install_sdk "${package_index}"
echo
echo
done
You can also see it on my GitHub repository
The good:
- Not depend on
expect
. - Headless.
The downsides:
- You still have to install basic SDK manually, and put
android
into your path. - The script only works on Unix.

- 30,738
- 21
- 105
- 131

- 102
- 2
- 10
In newer Android versions (e.g., 25.2.5) we should use sdkmanager
(instead of the android
command).
Example of installing a package:
android-sdk/tools/bin/sdkmanager "extras;android;m2repository"
Command to get a list of all available packages:
android-sdk/tools/bin/sdkmanager --verbose --list
This web-page lists download links for the SDK-tools:
Here is a link to an open-source repository docker-android which can install android in a Docker image.
You may also find the answers in this SO question: Automatically accept all SDK licences useful.

- 30,738
- 21
- 105
- 131

- 17,012
- 10
- 94
- 142
Starting with Android Plugin for Gradle version 2.2.0, missing SDK components get downloaded automatically.

- 28,386
- 6
- 101
- 146
-
2They do, but licenses don't get accepted automatically, which makes it of minimal use for CI. – eAi Nov 07 '16 at 14:49
-
My second link has explicit instructions about how to "export your licenses by copying over the accepted licenses directory". This is something you can easily do for your CI build nodes. – sschuberth Nov 07 '16 at 16:49
A script to download only needed, non-{obsolete, source, emulator-image, doc} packages:
#!/bin/bash
set -e
# cd into where tools/android can be found
if [[ -d "$ANDROID_HOME" ]]; then
cd "$ANDROID_HOME"
elif [[ -x "$(dirname "$0")/tools/android" ]]; then
cd "$(dirname "$0")"
else
echo "FAILED: Cannot find ANDROID_HOME/tools/android"
exit 1
fi
android () {
"$(dirname $0)/tools/android" "$@"
}
needed_packages () {
android list sdk -u -s -e \
| grep '^id:' \
| cut -d'"' -f2 \
| grep -v 'source' \
| grep -v 'sys-img' \
| grep -v 'doc' \
| paste -d, -s -
}
main () {
(while : ; do
echo 'y'
sleep 1
done) | android update sdk -u -s -a -t "$(needed_packages)"
}
main
Some parts are taken from other answers.

- 30,738
- 21
- 105
- 131

- 5,501
- 3
- 31
- 39
To automate the sdkmanager.bat --licenses
prompt away on Windows (say you're installing via automation for build infrastructure)... Don't run it. Don't waste time trying to figure out how to pipe y
into it. I tried; abject fail.
Rather - run it one time, yourself, and take note that it generates files into C:\android\android-sdk\licenses
(where you're running C:\android\android-sdk\tools\bin\sdkmanager.bat
- your install root may vary).
Take those files, and place them somewhere you can grab them from in your automated setup scripts. Personally, Ansible is my poison, so:
# Note to future-us:
# These are magical files generated by running `c:/android/android-sdk/tools/bin/sdkmanager.bat --licenses`
# This, delightfully, is interactive, and wants to _actually_ read the keyboard buffer.
# That's reputedly possible via SendKeys. I elected to not try that.
# So, instead:
# 1) remote to an instance like a cave-dweller
# 2) run `c:/android/android-sdk/tools/bin/sdkmanager.bat --licenses` in a prompt.
# 3) _actually type_ `y` however many godforsaken times you need to.
# 4) meticulously harvest `c:/android/android-sdk/licenses/*` to this task.
# (you don't need the newline that they thoughtfully put before the hash in each file).
- name: set up android licenses by hand
win_lineinfile:
path: c:/android/android-sdk/licenses/{{ item.name }}
line: "{{ item.line }}"
create: true
with_items:
- {name: "android-googletv-license", line: "SOME HASH"}
- {name: "android-sdk-license", line: "SOME OTHER HASH"}
...

- 30,738
- 21
- 105
- 131

- 4,105
- 3
- 34
- 65
I got frustrated with this as well and built a Gradle plugin named com.quittle.setup-android-sdk
that will detect and install what you need. It works on Windows, OS X, and Linux and doesn't require any additional dependencies if you build with Gradle.
If you're interested, you can checkout my documentation on it here: https://github.com/quittle/gradle-setup-android-sdk

- 30,738
- 21
- 105
- 131

- 856
- 2
- 10
- 19
For a newbie Android developer, but an experienced Java developer, it is really bewildering to know which dependencies, even if you get past all of the nightmares in the previous answers.
A colleague of mine advised me to use Android Studio (which is IntelliJ IDEA based :-) specifically because of the above nightmares.
I followed his advice.
But I did not accept the defaults for the installation, and tried to install it in a software drive of mine. It turned out to be a nightmare. The SDK dialogue seemed to hang and was not intuitive at all. Which is why I ended up here.
After reading the above, I gave Studio another try, and this time it accepted all the defaults for the installation.
Hey PRESTO...it took care of all the SDK dependencies (core ones I am guessing) in a couple of dialogues without being prompted i.e., Ctrl + Shift + S and the SDK.
I would therefore recommend it for a newbie. Here the proof of the pudding as it downloads:
The version of Studio I downloaded and installed:
Version of windows:
And here after it did its good stuff:

- 30,738
- 21
- 105
- 131

- 1,084
- 13
- 18
-
So what I subsequently found was that it actually has nothing to do with the folder in which it is installed. Make sure that your internet connection and by inference the proxy are configured properly. Otherwise, you will see nothing available to install. That was the problem. – Beezer Jun 22 '18 at 13:11