List installed sdk package via command line - android

I want to list the installed sdk packages by command lines.(For some reasons I cannot use the GUI)
I have done some research and found out several commands to list the available packages on the remote server, but I fail to find any command to list the installed sdk packages yet.
Thanks

With Android SDK Tools 25.2.3 (and higher):
$ANDROID_HOME/tools/bin/sdkmanager --list
See: https://developer.android.com/studio/command-line/sdkmanager.html#usage

If you have your path set up, run
sdkmanager --list_installed
This will print out all the packages installed using sdkmanager.

For those want to use awk getting the inner paragraph between "Installed packages" and "Aavaliable Packages", but not include "Installed packages" and "Aavaliable Packages" lines.
sdkmanager --list | awk '/Installed/{flag=1; next} /Available/{flag=0} flag'

As described in $ANDROID_HOME/tools/android list --help
list : Lists existing targets or virtual devices.
list avd : Lists existing Android Virtual Devices.
list target : Lists existing targets.
list device : Lists existing devices.
list sdk : Lists remote SDK repository.
I guess you are looking for this:
$ANDROID_HOME/tools/android list target
You can learn more on the android tool in the Command Line Reference.
Good luck!

On my mac just sdkmanager --list was not working, path needed to be specified.
Using android studio default SDK location the path is ~/Library/Android/sdk/tools/bin/sdkmanager --list
As mentioned by #tnissi this is for Android SDK Tools 25.2.3 (and higher).
Or add the path by: export PATH=$PATH:~/Library/Android/sdk/tools/bin

in case you need only the installed packages with full names
sdkmanager --verbose --list | sed -n '/^Installed packages:$/,/^Available Packages:$/p'

It's not quite a listing, but the source.properties files give details of the provenance. I'm using this to compare SDKs on different machines:
for i in $(find -name source.properties); do
if [ -e ../other.sdk/$i ] ; then
echo ========================= $i
diff -wu $i ../other.sdk/$i | grep -v Pkg.License
fi
done
I strip Pkg.License because it's hyoooj.

A bit old topic but I had similar problem, And noticed that avdmanager lists installed platforms as targets
"%ANDROID_SDK_ROOT%\tools\bin\avdmanager" list target
Available Android targets:==============] 100% Fetch remote repository...
----------
id: 1 or "android-25"
Name: Android API 25
Type: Platform
API level: 25
Revision: 3
----------
id: 2 or "android-28"
Name: Android API 28
Type: Platform
API level: 28
Revision: 6

Related

How to get latest build tool installed (locally) in android sdk using command line

Actually I am trying to get latest build tool installed in my machine.
But here I don't want to go through my file system, I am looking for Android SDK commands to figure out latest build tool installed in my system.
Not the prettiest or more stable trick but you can get the latest installed build tools by doing:
$ANDROID_HOME/tools/bin/sdkmanager --list | grep "build-tools/" | awk '{ print $3 }' | tail -1

How do I download the Android SDK without downloading Android Studio?

As of the moment, I am running a Windows 8.1 PC that does not have the storage or the RAM for a IDE like Android Studio or Eclipse. I want to download the Android SDK tools, without the IDE. How can this be accomplished?
You can find the command line tools at the downloads page under the "Command line tools only" section.
These are the links provided in that page as of now (version 2022.1.1.20):
Windows no installer: https://dl.google.com/android/repository/commandlinetools-win-9477386_latest.zip
MacOS: https://dl.google.com/android/repository/commandlinetools-mac-9477386_latest.zip
Linux:
https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip
Be sure to have read and agreed with the terms of service before downloading any of the command line tools.
The installer version for windows doesn't seem to be available any longer, this is the link for version 24.4.1:
Windows installer: https://dl.google.com/android/installer_r24.4.1-windows.exe
Navigate to the "Get just the command line tools" section of the android downloads page, and download the tools for your system.
For Windows:
Extract the contents to C:\Android\android-sdk
Navigate to
C:\Android\android-sdk\tools\bin and open a command line window
(shift + right click)
Run the following to download the latest android package:
sdkmanager "platforms;android-25"
Update everything
sdkmanager --update
Other operation systems
Do pretty much the same, but not using windows directories.
The sdkmanager page gives more info in to what commands to use to install your sdk.
Command-line approach
mkdir android-sdk
cd android-sdk
wget https://dl.google.com/android/repository/sdk-tools-linux-*.zip
unzip sdk-tools-linux-*.zip
tools/bin/sdkmanager --update
When executing the above commands, make sure that you replace * with an appropriate version number which you could find in the download page.
Installing packages
You can also use the sdkmanager to list and to install any specific packages needed.
tools/bin/sdkmanager --list
tools/bin/sdkmanager "platform-tools" "platforms;android–27" "build-tools;27.0.3"
FYI
sdk-tools-linux-*.zip only includes the command-line tools. This extracts content to a single directory named tools, like:
+- android-sdk
+- tools
To get the SDK packages we could run:
tools/bin/sdkmanager --update
The sdkmanager accepts the following flag:
--sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK
containing this tool
But if we omit this flag, it assumes parent directory of tools directory as the sdk root, here in our case android-sdk directory.
If you check the android-sdk folder after running tools/bin/sdkmanager --update it will be like:
+- android-sdk
+- tools
+- emulator
+- platforms
+- platform-tool
If needed, also set ANDROID_HOME environment variable like:
export ANDROID_HOME=/path/to/android-sdk
What worked for me on Windows:
Downloaded command line tools from https://developer.android.com/studio/index.html
Put the whole tools folder from the ZIP archive to C:\Program Files (x86)\Android SDK\
Launched tools\android.bat as administrator, which opened the usual SDK Manager window
Installed required components. The files were downloaded to ...\Android SDK\ directory (that is build-tools, platforms, platform-tools, etc. directories appeared alongside tools inside ...\Android SDK\)
Opened the Android project in Intellij IDEA, navigated to File->Project Structure->SDKs, and added Android SDK by directing to ...\Android SDK\ directory
This tutorial is a just step by step for installing Android SDK (Software Development Kit) assuming the user is starting from scratch.
There are just a couple of prerequisites to note:
Java runtime environment (or JDK) at Oracle website (and download the correct version (32- or 64-bit) for your computer).
A good internet connection (needed for downloading system images etc)
I recommed using the offline SDK installer for installing the essential tools namely SDK and AVD manager: The last version of he installer is found here: SDK Installer_r24.4.1 (for windows), SDK Installer_r24.4.1 (for linux) or SDK Installer_r24.4.1 (for macos)
For this guide I was using windows:
Here is the workthrough:
Depending on your choice download the appropriate SDK package from above links (but for this example I will be using the manual method)
After downloading the package, begin installation (and choose the desired installation folder to proceed or just leave the default %USERPROFILE%\android-sdk):
When done leave the option to download system images "checked":
Now we're in business...
The SDK manager window will appear, now you need to update/download other sdk packages (i.e platform-tools, system-images, platforms etc according to API levels)
Note: I recommend downloading x86 images as they're much faster tham arm counterparts, also get intel HAXM (hardware accelerated execution manager) driver to significantly increase your emulator speed
All set, now you just need to create and configure an Android virtual device matching your target Android version and tweak desired settings.
To do this click on the Tools tab in SDK manager and select manage AVDs, then in the following window click Create you'll see a similar screen as below:
After that boot the newly created virtual device.
Install applications and test as you wish ..
Command line only without sdkmanager (for advanced users / CI):
You can find the download links for all individual packages, including various revisions, in the repository XML file:
https://dl.google.com/android/repository/repository-12.xml
(where 12 is the version of the repository index and will increase in the future).
All <sdk:url> values are relative to https://dl.google.com/android/repository, so
<sdk:url>platform-27_r03.zip</sdk:url>
can be downloaded at https://dl.google.com/android/repository/platform-27_r03.zip
Similar summary XML files exist for system images as well:
(default) https://dl.google.com/android/repository/sys-img/android/sys-img.xml
(google_apis) https://dl.google.com/android/repository/sys-img/google_apis/sys-img.xml
For those using the latest distribution on windows, the following should be enough:
Download the command line tools from here
Extract it somewhere (e.g. C:\androidsdk)
Add ANDROID_SDK_TOOLS as environment variable pointing to where you extracted it (C:\androidsdk)
Create a folder named latest inside the cmdlime-tools you extracted. And move what's inside(bin,lib...) to the folder latest.
cd cmdline-tools/latest/bin and execute the following:
sdkmanager.bat system-images;android-29;default;x86_64 platforms;android-29 build-tools;29.0.3 extras;google;m2repository extras;android;m2repository
Agree to the terms and conditions and continue. voilà
Well the folks who are trying to download either on *ix or Ec2 machine would suggest to clean approach in below steps:
$ mkdir android-sdk
$ cd android-sdk
$ mkdir cmdline-tools
$ cd cmdline-tools
$ wget https://dl.google.com/android/repository/commandlinetools-linux-*.zip
$ unzip commandlinetools-linux-*.zip
The king - sdkmanager lives inside
cmdline-tools/tools/bin
, you'd better set in PATH environment variable.
but cmdline-tools should not be set as ANDROID_HOME. Because later, when updating Android SDK, or installing more packages, the other packages will be placed under ANDROID_HOME, but not under cmdline-tools.
The final, complete ANDROID_HOME directory structure should look like below, consist of quite a few sub-directories:
build-tools, cmdline-tools, emulator, licenses, patcher, platform-tools, platforms, tools.
You can easily point out that build-tools and cmdline-tools are siblings, all resides inside the parent ANDROID_HOME.
Add SDK tools directory in PATH environment variable to make executable available globally. Add below line either in ~/.bashrc or ~/.profile file to make it permanent.
In order to edit the ~/.bashrc simply can be editable in vim mode
$ vim .bashrc
Now set your preferred ANDROID_HOME in .bashrc file :
export ANDROID_HOME=/home/<user>/android-sdk
export PATH=${PATH}:$ANDROID_HOME/cmdline-tools/tools/bin:$ANDROID_HOME/platform-tools
here strange thing that we haven't download the platform-tools directory as of now but mentoning it under path but let it be as it will help you avoid remodification on the same file later.
Now go inside the same directory:
$ cd android-sdk
NOTE: well in first attempt sdkmanager command didnt found for me so I close the terminal and again created the connection or you can also refresh the same if it works for you.
after that use the sdkmanager to list and install the packages needed:
$ sdkmanager "platform-tools" "platforms;android-27" "build-tools;27.0.3"
Hence Sdkmanager path is already set it will be accessible from anywhere:
$ sdkmanager --update
$ sdkmanager --list
Installed packages:=====================] 100% Computing updates...
Path | Version | Description | Location
------- | ------- | ------- | -------
build-tools;27.0.3 | 27.0.3 | Android SDK Build-Tools 27.0.3 | build-tools/27.0.3/
emulator | 30.0.12 | Android Emulator | emulator/
patcher;v4 | 1 | SDK Patch Applier v4 | patcher/v4/
platform-tools | 30.0.1 | Android SDK Platform-Tools | platform-tools/
platforms;android-27 | 3 | Android SDK Platform 27 | platforms/android-27/
Install latest version from CLI without specifying version
Here is an approach to downloading the last version of the Android SDK from CLI.
First of all, create and move to the following dir:
mkdir -p ~/android-sdk/cmdline-tools
cd ~/android-sdk/cmdline-tools
Then download the SDK (it basically finds the download URL from the HTML and downloads it, if you go to the web page, you'll see that it only shows the last one, so it works):
curl -s https://developer.android.com/studio\#command-tools | grep -Eo 'https://dl.google.com/android/repository/commandlinetools-mac-[0-9]*_latest.zip' | head -n 1 | xargs wget
Unzip file
ls -A1 | xargs unzip
Sadly, straight from google, which is where you will want to download if your company firewall blocks other sources, Release 1.6 r1 September 2009 is the latest SDK they have.
To download the SDK over command line, the link has changed slightly than previously mentioned:
wget --quiet --output-document=/tmp/sdk-tools-linux.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}.zip
Latest version listed on the downloads page.
I downloaded Android Studio and installed it. The installer said:-
Android Studio => ( 500 MB )
Android SDK => ( 2.3 GB )
Android Studio installer is actually an "Android SDK Installer" along with a sometimes useful tool called "Android Studio".
Most importantly:-
Android Studio Installer will not just install the SDK. It will also:-
Install the latest build-tools.
Install the latest platform-tools.
Install the latest AVD Manager which you cannot do without.
Things which you will have to do manually if you install the SDK from its zip file.
Just take it easy. Install the Android Studio.
****************************** Edit ******************************
So, being inspired by the responses in the comments I would like to update my answer.
The update is that only (and only) if 500MB of hard disk space does not matter much to you than you should go for Android Studio otherwise other answers would be better for you.
Android Studio worked for me as I had a 1TB hard disk which is 2000 times 500MB.
Also, note: that RAM sizse should not a restriction for you as you would not even be running Android Studio.
I came to this solution as I was myself stuck in this problem. I tried other answers but for some reason (maybe my in-competencies) they did not work for me. I decided to go for Android Studio and realized that it was merely 18% of the total installation and SDK was 82% of it. While I used to think otherwise. I am not deleting the answers inspite of negative rating as the answer worked for me. I might work for someone elese with a 1 TB hard disk (which is pretty common these days).

How to check the Android developer tools version from the command line?

I'm trying to retrieve the ADT version to generate some system reports.
How can I check the version of the android developer tools installed on the system using the command line?
Various parts of the tools save their revision number in files
For example
cat /android/sdk/platform-tools/source.properties | grep Pkg.Revision
cat /android/sdk/tools/source.properties | grep Pkg.Revision
The build tools themselves are placed in versioned directories, so you can find them via
ls /android/sdk/build-tools/

How to install Android SDK Build Tools on the command line?

I want to setup the Android dev environment from command line, and encounter the following issue:
wget http://dl.google.com/android/android-sdk_r22.0.5-linux.tgz
after extract the file, run
tools/android update sdk --no-ui
However, it is too slow on running
Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml
The result is that nothing in folder build-tools, and I want is aapt and apkbuilder, since I want to build apk from command line without ant.
By default, the SDK Manager from the command line does not include the build tools in the list. They're in the "obsolete" category. To see all available downloads, use
android list sdk --all
And then to get one of the packages in that list from the command line, use:
android update sdk -u -a -t <package no.>
Where -u stands for --no-ui, -a stands for --all and -t stands for --filter.
If you need to install multiple packages do:
android update sdk -u -a -t 1,2,3,4,..,n
Where 1,2,..,n is the package number listed with the list command above
As mentioned in other answers, you can use the --filter option to limit the installed packages:
android update sdk --filter ...
The other answers don't mention that you can use constant string identifiers instead of indexes (which will change) for the filter options. This is helpful for unattended or scripted installs. Man for --filter option:
... This also accepts the identifiers returned by 'list sdk --extended'.
android list sdk --all --extended :
Packages available for installation or update: 97
----------
id: 1 or "tools"
Type: Tool
Desc: Android SDK Tools, revision 22.6.2
----------
id: 2 or "platform-tools"
Type: PlatformTool
Desc: Android SDK Platform-tools, revision 19.0.1
----------
id: 3 or "build-tools-19.0.3"
Type: BuildTool
Desc: Android SDK Build-tools, revision 19.0.3
Then you can use the string ids as the filter options to precisely specify the versions you want:
android update sdk --filter tools,platform-tools,build-tools-19.0.3 etc
Version 25.2.3 (and higher) of Android SDK Tools package contains new tool - sdkmanager - which simplifies this task of installing build-tools from the command line.
It is located in android_sdk/tools/bin folder.
Usage (from documentation):
List installed and available packages:
sdkmanager --list [options] \
[--channel=channel_id] // Channels: 0 (stable), 1 (beta), 2 (dev), or 3 (canary)
Use the channel option to include a package from a channel up to and including channel_id. For example, specify the canary channel to list packages from all channels.
Install packages:
sdkmanager packages [options]
The packages argument is an SDK-style path, wrapped in quotes (for
example, "build-tools;25.0.0" or "platforms;android-25"). You can
pass multiple package paths, separated with a space, but they must
each be wrapped in their own set of quotes.
Example usage (on my Mac):
alex#mbpro:~/sdk/tools/bin$ ls ../../build-tools/
25.0.0/
alex#mbpro:~/sdk/tools/bin$ ./sdkmanager "build-tools;25.0.2"
done
alex#mbpro:~/sdk/tools/bin$ ls ../../build-tools/
25.0.0/ 25.0.2/
You can also specify various options, for example to force all connections to use HTTP (--no_https), or in order to use proxy server (--proxy_host=address and --proxy_port=port).
To check the available options, use the --help flag. On my machine (Mac), the output is as following:
alex#mbpro:~/sdk/tools/bin$ ./sdkmanager --help
Usage:
sdkmanager [--uninstall] [<common args>] \
[--package_file <package-file>] [<packages>...]
sdkmanager --update [<common args>]
sdkmanager --list [<common args>]
In its first form, installs, or uninstalls, or updates 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), currently installed packages are
updated to the latest version.
In its third form, all installed and available packages are printed out.
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.
ADB Build-Tools Will Not be downloaded automatically, by command android update sdk --no-ui
So for installing Buil-Tool type (in console):
android list sdk --all
Remember the number that is listed before the item and execute the following:
android update sdk -u --all --filter <number>
commands should be typed in /YourFolder/android-sdk-linux/tools
Also for remote folder (server opened by ssh for example) type:
**./android** list sdk --all
**./android** update sdk -u --all --filter <number>
For simple list of ADB packages type in terminal:
android list sdk
for install all packages:
android update sdk --no-ui
Or with filters (comma is separator):
android update sdk --no-ui --filter 3,5,8,14
A great source of information I came across while trying to install everything Android SDK related from the command line, was this Dockerfile. Inside the Dockerfile you can see that the author executes a single command to install platform tools and build tools without any other interaction. In the case the OP has put forth, the command would be adapted to:
echo y | $ANDROID_HOME/tools/android update sdk --all --filter build-tools-21.1.0 --no-ui
If you have sdkmanager installed (I'm using MAC)
run sdkmanager --list to list available packages.
If you want to install build tools, copy the preferred version from the list of packages available.
To install the preferred version run
sdkmanager "build-tools;27.0.3"
The "android" command is deprecated.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
If you do not need Android Studio, you can download the basic Android command line tools from developer.android.com in section Command line tools only.
from CLI it should be somfing like:
curl --output sdk-tools-linux.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
or
wget --output-document sdk-tools-linux.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
After that just unpack the archive to the target folder
unzip sdk-tools-linux.zip
And now we can install everything you need...
./tools/bin/sdkmanager --install 'build-tools;29.0.2' 'platform-tools' 'platforms;android-29' 'tools'
You can get a complete list of packages using the command ./tools/bin/sdkmanager --list
Some packages require acceptance of the license agreement. you can accept it interactively or just pass "y" to the input stream, like this(two agreements in case):
echo -ne "y\ny" | ./tools/bin/sdkmanager --install 'system-images;android-29;default;x86_64'
And of course, for your convenience, you can export variables such as ANDROID_HOME or ANDROID_SDK_ROOT (including doing it in ~/.profile or ~/.bash_profile) or patch the PATH variable - all this is at your discretion.
Script example:
mkdir /opt/android-sdk
cd /opt/android-sdk
curl --output sdk-tools-linux.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
unzip sdk-tools-linux.zip
echo -ne "y" | ./tools/bin/sdkmanager --install 'build-tools;29.0.2' 'platform-tools' 'platforms;android-29' 'tools'
Requirements:
curl(or wget) and unzip
Troubleshooting:
if you see Warning: Could not create settings, you need to have the tools directory inside the cmdline-tools directory inside the ANDROID_HOME (create it if needed with this exact name) see Android Command line tools sdkmanager always shows: Warning: Could not create settings
I just had a heck of a time getting android sdk dependencies installed via command line and since the documentation that comes with the tools and online are woefully lacking, I thought I'd post what I discovered here.
I'm working with android sdk r24.4.1 for linux. There are two commands that you can run to list the available packages:
android list sdk
and the more exhaustive:
android list sdk --all
The package numbers for specific packages differ for each command above! For example, the former lists package API 23.1 revision 3 as package #3 and the latter lists it as #29.
Now, there are two different ways to install using the android command.
tools/android update sdk --no-ui --filter <package number>
and
tools/android update sdk -u -a -t <package number>
Given that the install commands each can take the package # as a parameter, which package number do you use? After much online searching and trial and error, I discovered that
android update sdk --no-ui --filter uses the package numbers from android list sdk
and
android update sdk -u -a -t uses the package numbers from android list sdk --all
In other words - to install API 23.1 revision 3 you can do either:
android update sdk --no-ui --filter 3
or
android update sdk -u -a -t 29
Crazy, but it works.
Most of the answers seem to ignore the fact that you may need to run the update in a headless environment with no super user rights, which means the script has to answer all the y/n license prompts automatically.
Here's the example that does the trick.
FILTER=tool,platform,android-20,build-tools-20.0.0,android-19,android-19.0.1
( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) \
| android update sdk --no-ui --all \
--filter ${FILTER}
No matter how many prompts you get, all of those will be answered. This while/sleep loop looks like simulation of the yes command, and in fact it is, well almost. The problem with yes is that it floods stdout with 'y' and there is virtually no delay between sending those characters and the version I had to deal with had no timeout option of any kind. It will "pollute" stdout and the script will fail complaining about incorrect input. The solution is to put a delay between sending 'y' to stdout, and that's exactly what while/sleep combo does.
expect is not available by default on some linux distros and I had no way to install it as part of my CI scripts, so had to use the most generic solution and nothing can be more generic than simple bash script, right?
As a matter of fact, I blogged about it (NSBogan), check it out for more details here if you are interested.
However, it is too slow on running
Yes, I've had the same problem. Some of the file downloads are extremely slow (or at least they have been in the last couple of days). If you want to download everything there's not a lot you can do about that.
The result is that nothing in folder build-tools, and I want is aapt and apkbuilder, since I want to build apk from command line without ant.
Did you let it run to completion?
One thing you can do is filter the packages that are being downloaded using the -t switch.
For example:
tools/android update sdk --no-ui -t platform-tool
When I tried this the other day I got version 18.0.0 of the build tools installed. For some reason the latest version 18.0.1 is not included by this filter and the only way to get it was to install everything with the --all switch.
I prefer to put a script that install my dependencies
Something like:
#!/usr/bin/env bash
#
# Install JUST the required dependencies for the project.
# May be used for ci or other team members.
#
for I in android-25 \
build-tools-25.0.2 \
tool \
extra-android-m2repository \
extra-android-support \
extra-google-google_play_services \
extra-google-m2repository;
do echo y | android update sdk --no-ui --all --filter $I ; done
https://github.com/caipivara/android-scripts/blob/master/install-android-dependencies.sh
I just had this problem, so I finally wrote a 1 line bash dirty solution by reading and parsing the list of aviable tools :
tools/android update sdk -u -t $(android list sdk | grep 'Android SDK Build-tools' | sed 's/ *\([0-9]\+\)\-.*/\1/')
Inspired from answers by #i4niac & #Aurélien Lambert, this is what i came up with
csv_update_numbers=$(./android list sdk --all | grep 'Android SDK Build-tools' | grep -v 'Obsolete' | sed 's/\(.*\)\- A.*/\1/'|sed '/^$/d'|sed -e 's/^[ \t]*//'| tr '\n' ',')
csv_update_numbers_without_trailing_comma=${csv_update_numbers%?}
( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) \
| ./android update sdk --all -u -t $csv_update_numbers_without_trailing_comma
Explanation
get a comma separated list of numbers which are the indexes of build tools packages in the result of android list sdk --all command (Ignoring obsolete packages).
keep throwing 'y's at the terminal every few miliseconds to accept the licenses.
Download android SDK from developer.android.com (its currently a 149mb file for windows OS). It is worthy of note that android has removed the sdkmanager GUI but has a command line version of the sdkmanager in the bin folder which is located inside the tools folder.
When inside the bin folder, hold down the shift key, right click, then select open command line here.
Shift+right click >> open command line here.
When the command line opens, type sdkmanager click enter.
Then run type sdkmanager (space), double hyphen (--), type list
sdkmanager --list (this lists all the packages in the SDK manager)
Type sdkmanager (space) then package name, press enter.
Eg. sdkmanager platform-tools (press enter)
It will load licence agreement. With options (y/n). Enter y to accept and it will download the package you specified.
For more reference follow official document here
I hope this helps. :)
Build tools could not be downloaded automatically by default as Nate said in https://stackoverflow.com/a/19416222/1104031 post.
But I wrote small tool that make everything for you
I used "expect" tool as danb in https://stackoverflow.com/a/17863931/1104031 post.
You only need android-sdk and python27, expect.
This script will install all build tools, all sdks and everything you need for automated build:
import subprocess,re,sys
w = subprocess.check_output(["android", "list", "sdk", "--all"])
lines = w.split("\n")
tools = filter(lambda x: "Build-tools" in x, lines)
filters = []
for tool in tools:
m = re.search("^\s+([0-9]+)-", tool)
tool_no = m.group(1)
filters.append(tool_no)
if len(filters) == 0:
raise Exception("Not found build tools")
filters.extend(['extra', 'platform', 'platform-tool', 'tool'])
filter = ",".join(filters)
expect= '''set timeout -1;
spawn android update sdk --no-ui --all --filter %s;
expect {
"Do you accept the license" { exp_send "y\\r" ; exp_continue }
eof
}''' % (filter)
print expect
ret = subprocess.call(["expect", "-c", expect])
sys.exit(ret)
As stated in other responses, the build tools requires the --all flag to be installed. You also better use a -t filter flag to avoid installing ALL the packages but there is no way to filter all the build tools.
There are already features requests for these two points in AOSP bug tracker. Feel free to vote for them, this might make them happen some day:
https://code.google.com/p/android/issues/detail?id=78765
https://code.google.com/p/android/issues/detail?id=58337
I tried this for update all, and it worked!
echo y | $ANDROID_HOME/tools/android update sdk --no-ui
Try
1. List all packages
android list sdk --all
2. Install packages using following command
android update sdk -u -a -t package1, package2, package3 //comma seperated packages obtained using list command
android update sdk
This command will update and install all latest release for SDK Tools, Build Tools,SDK platform tools.
It's Work for me.
To setup android environment without installating the whole android studio :
Download JDK (version greater than 8)
Download gradle from https://gradle.org/install/
Download command line tools from https://developer.android.com/studio scroll down and download command line tools only
Setup the necessary environment variables
Download the necessary SDK tools

Is there a way to automate the Android SDK installation?

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?
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]
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
}
'
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
To answer all licenses with 'y', you can try this in the script:
(while :
do
echo 'y'
sleep 2
done) | android update sdk -u .....
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.
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.
Starting with Android Plugin for Gradle version 2.2.0, missing SDK components get downloaded automatically.
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
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"}
...
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.
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:

Categories

Resources