Installing Android SDK Without Android Studio
Prerequisites
You will need a Java 8 executable in your PATH as the sdkmanager
tool is still not compatible with higher Java versions.
More info can be found here.
Download Android SDK Command line tools
Near to the end of the Studio page, a section exists under the name of “Command line tools only”, download the Linux tools.
Setting up the environment
Add the following environment variables to your ~/.profile
More info about these variables can be found here.
export ANDROID_SDK_ROOT=$HOME/.local/opt/android_sdk
export ANDROID_HOME=$ANDROID_SDK_ROOT
export ANDROID_AVD_HOME=$HOME/.local/opt/android_avd
Activate changes by running source ~/.profile
Extracting the command line utilities
Extract the downloaded zip file to your ANDROID_SDK_ROOT
unzip ~/Downloads/sdk-tools-linux-4333796.zip \
-d $ANDROID_SDK_ROOT
Installing the SDK
$ANDROID_SDK_ROOT/tools/bin/sdkmanager \
'platforms;android-28' \
'build-tools;28.0.3' \
'system-images;android-28;google_apis;x86_64' \
'platform-tools' \
'ndk-bundle'
platforms;android-28
: The Android SDK for API 28 (Android 9).build-tools;28.0.3
: Android SDK Build Tools.system-images;android-28;google_apis;x86_64
: An Android 9 system image for Android Virtual Device.platform-tools
: Tools such asadb
andfastboot
(Optional)ndk-bundle
: Android Native Development Kit (Optional). If this is installed, an additional environment variableANDROID_NDK_ROOT
, which is typically on$ANDROID_SDK_ROOT/ndk-bundle
Searching Additional Utilities
To search a newer version of a package or installing a different package, you may search with the following command:
$ANDROID_SDK_ROOT/tools/bin/sdkmanager --list | grep YOUR_QUERY
Creating an Android Virtual Device
An AVD can be created with the following command;
$ANDROID_SDK_ROOT/tools/bin/avdmanager create avd \
-n MyAvd \
-d 'Nexus 5X' \
-k 'system-images;android-28;google_apis;x86_64'
-n
: Specifies the name of the AVD-d
: Specifies the device definition. Find more definitions by running$ANDROID_SDK_ROOT/tools/bin/avdmanager list device
-k
: Specifies the system image of the AVD. The system image must be installed to be used.
Starting the AVD
An AVD can be started with the emulator
utility.
$ANDROID_SDK_ROOT/tools/emulator @MyAvd
or
$ANDROID_SDK_ROOT/tools/emulator -avd MyAvd
Troubleshooting
“This User Doesn’t Have Permissions to Use KVM” on Debian based systems when trying to run the AVD, there are two solutions
- Installing
qemu-kvm
Though, since the Android Emulator already packs its own qemu, we can avoid installing qemu
_just* for the permission to use /dev/kvm
- Manually taking ownership of
/dev/kvm
sudo groupadd kvm
sudo usermod -aG kvm USER_NAME
# The following must be run each boot,
# create a service or something similar.
sudo chgrp kvm /dev/kvm