The sdkmanager is a CLI tool that allows users to view, install, update, and uninstall available packages for the Android SDK.
This article is going to teach you how to install Android SDK Manager on Ubuntu 18.04 using terminal. Earlier we have seen how to Install Android SDK Manager on Ubuntu 16.04.
If you're already using Android Studio, you don't need to use sdkmanager as you can manage your SDK packages from the IDE instead. The sdkmanager tool is provided in the Android SDK Tools package, so we are going to install the latter to be able to use sdkmanager.
Install Android SDK Tools Package
Before installing the preferred tool, we need to update all packages and install JAVA, as the Android SDK requires it to run. To do so you can run the following commands in the order mentioned below:
sudo apt update
sudo apt install default-jdk
Once JAVA is installed on the machine we can run the following command to check the java version and to be sure it has been installed correctly:
The output must look like this
openjdk version "10.0.1" 2018-04-17 OpenJDK Runtime Environment (build 10.0.1+10-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 10.0.1+10-Ubuntu-3ubuntu1, mixed mode)
After successful JAVA installation, we can proceed to the installation of Android SDK. We need to download the binaries from Android Developers Website. If you open the link above in the browser you can find available zip files under the "Command Line Tools only" part. To download binaries from terminal run the command below:
Once it's installed unzip with the following command
A new directory will be created named tools. To complete the installation we need to add the following paths to our PATH environment variable. To do so, you can run the command below:
If you've downloaded or unzipped the SDK-tools package into other directory, please don't forget to use appropriate paths. To add the directories permanently, just add the line above to the
Android SDK Manager usage from terminal
Once Android SDK has been installed we can use
sdkmanager tool to view, install, update and uninstall packages for the Android SDK from terminal.
List installed, available packages and updates
To list all installed, available packages and ones that have update we can run:
The output will look like the one below:
Installed packages: Path | Version | Description | Location ------- | ------- | ------- | ------- platform-tools | 27.0.1 | Android SDK Platform-Tools | platform-tools/ tools | 26.0.1 | Android SDK Tools 26.0.1 | tools/ Available Packages: Path | Version | Description ------- | ------- | ------- add-ons;addon-g..._apis-google-15 | 3 | Google APIs add-ons;addon-g..._apis-google-16 | 4 | Google APIs add-ons;addon-g..._apis-google-17 | 4 | Google APIs add-ons;addon-g..._apis-google-18 | 4 | Google APIs add-ons;addon-g..._apis-google-19 | 20 | Google APIs add-ons;addon-g..._apis-google-21 | 1 | Google APIs add-ons;addon-g..._apis-google-22 | 1 | Google APIs add-ons;addon-g..._apis-google-23 | 1 | Google APIs add-ons;addon-g..._apis-google-24 | 1 | Google APIs add-ons;addon-g...e_gdk-google-19 | 11 | Glass Development Kit Preview ... system-images;a...s_playstore;x86 | 2 | Google Play Intel x86 Atom Sys... system-images;a...laystore;x86_64 | 2 | Google Play Intel x86 Atom_64 ... tools | 26.1.1 | Android SDK Tools Available Updates: ID | Installed | Available ------- | ------- | ------- tools | 26.0.1 | 26.1.1 done
You can have issues when running this command. E.g. the output of the command can be an error like the one below:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156) at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75) at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81) at com.android.sdklib.tool.SdkManagerCli.main(SdkManagerCli.java:117) at com.android.sdklib.tool.SdkManagerCli.main(SdkManagerCli.java:93) Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ... 5 more
To resolve this issue edit the sdkamanger script which is located in bin folder of the installation folder (in our case the full path to the file was
/home/ubuntu/tools/bin/sdkamanager) and add the following line in the 31st line:
-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
After the editing, that line must look like below:
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
Once you've edited the file and saved you can run the
sdkmanager --list command again. Only installed packages will be shown and another error message will appear which will be like the one below:
Warning: javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty Warning: Failed to download any source lists! Warning: File /home/ubuntu/.android/repositories.cfg could not be loaded.
Actually there are two separate errors in the message above. One is related to secure connection due to which it cannot view available packages and check the packages for updates. The second one says that sdkmanager cannot load
To fix the errors we create the repositories.cfg file (as it hasn't been created by default) and run the
sdkmanager --list command with
--no_https flag. Run the following commands in the order below:
sdkmanager --no_https --list
After running these commands you will be able to see the output shown above in this article.
Install, update and uninstall packages using sdkmanager
To install package, run the following command:
sdkmanager --no_https [package_name]
If you want to uninstall several packages you can add them to a file and use --package_file flag. For example
sdkmanager --no_https --package_file=/path/to/package_file
Note that package_name must be from available packages list and if you don't use
no_https flag it will throw the same error when we ran the
sdkmanager --list command.
To update all packages, you can run:
sdkmanager --no_https --update
Note that if you update SDK tools you need to edit
/home/ubuntu/tools/bin/sdkamanager file again and add
-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee in the 31st line, as the mentioned above file will be fetched from the server and will become the default one.
To uninstall package, run the command below:
sdkmanager --uninstall [package_name]
sdkmanager --uninstall --package_file=/path/to/package_file
Read also :
The installation of Android SDK Manager itself is very simple, but during the process you may face different issues which are related to JAVA. However, there are workarounds described for types of issues you can face. So using this tutorial you can be sure that you'll make it work.