Android SDK will be installed in $HOME/.local/share/android/sdk
.
On page https://developer.android.com/studio/index.html#downloads,
got to section "Get just the command line tools" at page end and download Linux package.
With last edition of this document, this is commandlinetools-linux-8092744_latest.zip
.
export ANDROID_SDK_ROOT=$HOME/.local/share/android/sdk
export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk-bundle
mkdir -p $ANDROID_SDK_ROOT
wget -P "$HOME/Downloads" https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip
unzip "$HOME/Downloads/commandlinetools-linux-8092744_latest.zip" -d $ANDROID_SDK_ROOT
Now install minimal packages in order to further build a project.
# Avoid annoying warning from sdkmanager
mkdir $HOME/.android
touch $HOME/.android/repositories.cfg
# Install OpenJDK 8 if not already done
sudo apt install openjdk-8-jre-headless
# Verify that OpenJDK 8 is default for system
update-alternatives --display java
# If OpenJDK 11 is installed and set as default,
# you have to change system default to OpenJDK 8 with command:
sudo update-alternatives --config java
# Or, without prompt, listing choices
update-alternatives --list java
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
# To restore java binary to auto default, use
sudo update-alternatives --auto java
# Accept all licences
yes | $ANDROID_SDK_ROOT/tools/bin/sdkmanager --licenses
# Update to lastest tools version
$ANDROID_SDK_ROOT/tools/bin/sdkmanager --update --verbose
# Install NDK because gradle will never install by itself for project
$ANDROID_SDK_ROOT/tools/bin/sdkmanager --verbose ndk-bundle
Inside a Android Project, ANDROID_SDK_ROOT
and ANDROID_NDK_HOME
have to defined each time to build with gradle.
export ANDROID_SDK_ROOT=$HOME/.local/share/android/sdk
export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk-bundle
gradlew :app:build
# gradle binaries and packages are saved in $HOME/.gradle
There is no way to put proxy configuration in a file. Proxy settings must always be given on command line.
Defines a variable SDKMAN_OPTS
and always run sdkmanager [...] $SDKMAN_OPTS
.
SDKMAN_OPTS="--proxy=http --proxy_host=127.0.0.1 --proxy_port=8123"
export SDKMAN_OPTS
yes | $ANDROID_SDK_ROOT/tools/bin/sdkmanager --licenses $SDKMAN_OPTS
$ANDROID_SDK_ROOT/tools/bin/sdkmanager --update --verbose $SDKMAN_OPTS
$ANDROID_SDK_ROOT/tools/bin/sdkmanager --verbose ndk-bundle $SDKMAN_OPTS
Fo zsh shell:
export SDKMAN_OPTS="--proxy=http --proxy_host=127.0.0.1 --proxy_port=8123"
yes | $ANDROID_SDK_ROOT/tools/bin/sdkmanager --licenses ${=SDKMAN_OPTS}
$ANDROID_SDK_ROOT/tools/bin/sdkmanager --update --verbose ${=SDKMAN_OPTS}
$ANDROID_SDK_ROOT/tools/bin/sdkmanager --verbose ndk-bundle ${=SDKMAN_OPTS}