How to Set Up Android Sdk for Command Line Development on Linux

How to install Android SDK on Ubuntu?

Option 1:

sudo apt update && sudo apt install android-sdk

The location of Android SDK on Linux can be any of the following:

  • /home/AccountName/Android/Sdk

  • /usr/lib/android-sdk

  • /Library/Android/sdk/

  • /Users/[USER]/Library/Android/sdk

Option 2:

  • Download the Android Studio.

  • Extract downloaded .zip file.

    The extracted folder name will read somewhat like android-studio

To keep navigation easy, move this folder to Home directory.

  • After moving, copy the moved folder by right clicking it. This action will place folder's location to clipboard.

  • Use Ctrl Alt T to open a terminal

  • Go to this folder's directory using cd /home/(USER NAME)/android-studio/bin/

  • Type this command to make studio.sh executable: chmod +x studio.sh

  • Type ./studio.sh

A pop up will be shown asking for installation settings. In my particular case, it is a fresh install so I'll go with selecting I do not have a previous version of Studio or I do not want to import my settings.

If you choose to import settings anyway, you may need to close any old project which is opened in order to get a working Android SDK.

./studio.sh popup

From now onwards, setup wizard will guide you.

Android studio setup wizard

Android Studio can work with both Open JDK and Oracle's JDK (recommended). Incase, Open JDK is installed the wizard will recommend installing Oracle Java JDK because some UI and performance issues are reported while using OpenJDK.

The downside with Oracle's JDK is that it won't update with the rest of your system like OpenJDK will.

The wizard may also prompt about the input problems with IDEA .

Select install type

Select Android studio install type

Verify installation settings

Verify Android studio installation settings

An emulator can also be configured as needed.

Android studio emulator configuration prompt

The wizard will start downloading the necessary SDK tools

The wizard may also show an error about Linux 32 Bit Libraries, which can be solved by using the below command:

sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1

After this, all the required components will be downloaded and installed automatically.

After everything is upto the mark, just click finish

Completed installation of Android studio

To make a Desktop icon, go to 'Configure' and then click 'Create Desktop Entry'

Creating Android studio desktop icon

Creating Android studio desktop icon for one or multiple users

source

install android sdk using command line linux

It works fine for me. Try it without the --no-ui flag and see if that works. If not, what is the error message you get?


Edit:

You probably have your PATH configured incorrectly. You need to execute the "current folder executable" as follows:

$ ./android update sdk --no-ui

How do I update Android SDK in Linux via command line

From the documentation:

Starting with Tools R12, the SDK Manager offers a slightly better way
to update the SDK from command-line.

Previously the "android update sdk --no-ui" command already allowed
one to update from the command-line, but it had the annoying tendency
of installing every single platform or add-on. There are now 30 or
more packages available on the SDK repository, including 12 platforms;
that's a lot to download when most people only need the most recent
platform. Starting with R12, you can use combine new things:

  • "android list sdk" will connect to the remote repository and list all the
    packages available with an index number.

  • "android update sdk --no-ui"
    accepts a "--filter" argument that can take a package index, or a
    category name.


Here's an example in action:

Sample Image

There's still room for improvement, notably in a future release we'll work on the first install case and making the update smarter at figuring out what to get.

How to install Android SDK on Linux using CLI only?

If you use tools/android -h update sdk (I discovered that by trying tools/android update sdk --help), you will get a list of options for the update sdk command, the most interesting one being:

  -u --no-ui    Updates from command-line (does not display the GUI)

Android Command line tools sdkmanager always shows: Warning: Could not create settings

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 inside cmdline-tools/tools/bin, you'd better set in PATH environment variable
  • cmdline-tools should not be set as ANDROID_SDK_ROOT. Because later, when updating Android SDK, or installing more packages, the other packages will be placed under ANDROID_SDK_ROOT, but not under cmdline-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 that build-tools and cmdline-tools are siblings, all sit inside the parent ANDROID_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 inside ANDROID_SDK_ROOT
  • Append the directory $ANDROID_SDK_ROOT/cmdline-tools/tools/bin to environment variable PATH, so that the system knows where to find sdkmanager

!!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 to tools, 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 be android_sdk/cmdline-tools/version/bin/, but I've checked, using version or tools 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 latest sdkmanager placed under $ANDROID_SDK_ROOT/cmdline-tools/latest/bin, put it in front will make it higher priority.


Related Topics



Leave a reply



Submit