Command Line "Android Update Sdk" on Headless Linux

Command line Android update sdk on headless Linux

Updating Android SDK headless and automatically is described in Stack Overflow question Is there a way to automate the Android SDK installation?.

Is there a way to automate the Android SDK installation?

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]

User Defined Sites in Android SDK Manager via Command Line

There is a workaround for this

after testing on a machine with the ui i have found that it created a file called "repositories.cfg"

so all you need to do is to create a file HOME_DIR/.android/repositories.cfg
with the content fitting to your needs in my case it was:

count=1
src00=https\://s3.amazonaws.com/android-sdk-manager/redist/addon.xml

The count here is the number of add-on sites you have on the machine.

How to install old version of Android build tools from command line?

Assuming you have downloaded the Android SDK for linux, you have two options to update from command line.

Download using android tool from the sdk

Instead of running the android sdk manager with a GUI, you also have an option to run in headless mode. You just need to specify -u (or --no-ui) flag.

To list packages available for installation or upgrade:

$ cd android-sdk-linux
$ ./tools/android list sdk --all
Refresh Sources:
(...)
Fetching URL: https://dl.google.com/android/repository/repository-11.xml
(...)
Packages available for installation or update: 166
1- Android SDK Tools, revision 24.4.1
2- Android SDK Tools, revision 25.0.9 rc10
3- Android SDK Platform-tools, revision 23.1
4- Android SDK Platform-tools, revision 24 rc1
5- Android SDK Build-tools, revision 24 rc1
6- Android SDK Build-tools, revision 23.0.2
7- Android SDK Build-tools, revision 23.0.1
8- Android SDK Build-tools, revision 23 (Obsolete)
(...)
162- Google Play Billing Library, revision 5
163- Google Play Licensing Library, revision 2
164- Android Auto API Simulators, revision 1
165- Google Web Driver, revision 2
166- Intel x86 Emulator Accelerator (HAXM installer), revision 6.0.1

To download specific packages you need to specify the number of the item you want to install from the list in the following command:

$ ./tools/android update sdk -u -a -t [NO_OF_ITEM_TO_BE_INSTALLED]

Example: if I wanted to install Android SDK build tools revision 23.0.1, I would type in:

$ ./tools/android update sdk -u -a -t 7

Manual download

As not every package (especially the old ones) is listed when you do android sdk list, you can also download things manually. You can manually open the XML file that is shown when during android sdk list - https://dl.google.com/android/repository/repository-11.xml

You can find there links to various types of things to download, e.g:

  • ADK
  • http://dl.google.com/android/ADT-XX.0.0.zip
  • SDK Tools
  • http://dl.google.com/android/repository/tools_rXX-linux.zip
  • http://dl.google.com/android/repository/tools_rXX-windows.zip
  • http://dl.google.com/android/repository/tools_rXX-macosx.zip
  • Platform Tools
  • http://dl.google.com/android/repository/platform-tools_rXX-linux.zip
  • http://dl.google.com/android/repository/platform-tools_rXX-windows.zip
  • http://dl.google.com/android/repository/platform-tools_rXX-macosx.zip
  • Build Tools
  • http://dl.google.com/android/repository/build-tools_rXX-linux.zip
  • http://dl.google.com/android/repository/build-tools_rXX-windows.zip
  • http://dl.google.com/android/repository/build-tools_rXX-macosx.zip
  • Platforms
  • http://dl.google.com/android/repository/android-XX.zip

To manually download e.g. version 19.0.1 of build tools

$ cd android-sdk-linux/build-tools
$ wget http://dl.google.com/android/repository/build-tools_r19.0.1-linux.zip
$ unzip build-tools_r19.0.1-linux.zip
$ mv android-4.4.2 19.0.1
$ rm build-tools_r19.0.1-linux.zip

Side note (ubuntu):

If you're running debian/ubuntu 64-bit, to run aapt you will need to install additional packages:

sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1

If you're running CentOs (RedHat), to run aapt you will need to install additional packages:

sudo yum install zlib.i686 libstd++.i686

While running aapt, if you get an error with GLIBC 2.14 and you dont wont to upgrade your locale GLIBC. Then u need to download the following packages for sdk (build-tool, platform-tool) :

build-tool : http://dl.google.com/android/repository/build-tools_r23.0.2-linux.zip

platform-tool : https://dl.google.com/android/repository/platform-tools_r23.0.1-linux.zip

How can I install Android NDK Cmake tools on headless server

I've found a workaround!!

I've install cmake using this script: https://github.com/Commit451/android-cmake-installer

It's done the job until Google publish a fix so we can install it using the Sdk Manager (here link of the issue

Valid Android package names when performing SDK update at command line

The command below should list all valid package names.

android list sdk --extended


Related Topics



Leave a reply



Submit