Android

Debian has some packages for Android. During installation some components are downloaded from third party servers. The scripts installs the sdkmanager from google.

sdkmanager
#!/bin/bash
# install android sdk in debian
# https://anonscm.debian.org/cgit/android-tools/google-android-installers.git

set -o errexit
set -o nounset
# set -o verbose
set -o xtrace

cat > /etc/apt/sources.list.d/android.list <<-'APT'
        deb http://deb.debian.org/debian sid contrib
APT
apt-get --quiet update

debconf-set-selections <<-'APT'
        # Choices: https://dl.google.com, http://mirrors.neusoft.edu.cn, http://android-mirror.bugly.qq.com:8080
        google-android-ndk-installer    google-android-installers/mirror        select  https://dl.google.com
APT

# set -o physical
cd -P "$(mktemp -d)" || exit 1

mkdir /var/cache/google-android-ndk-installer && (
        cd ..
        xargs --verbose --max-lines \
                wget \
                        --quiet \
                        --continue \
                        --no-check-certificate \
                <<-'FILES' || exit 2
                        https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
                        https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip
                FILES

        unzip \
                -quod \
                /var/cache/google-android-ndk-installer \
                android-ndk-r13b-linux-x86_64.zip

        wget \
                --quiet \
                --continue \
                --no-cookies \
                --no-check-certificate \
                --header "Cookie: gpw_e24=http%3a%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
                https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz

        apt-get --yes --quiet install java-package java-common
        usermod nobody --shell=/bin/sh
        yes | head | su nobody -P -c \
                fakeroot\ make-jpkg\ jdk-8u201-linux-x64.tar.gz
        dpkg --install oracle-java8-jdk_8u201_amd64.deb
        update-alternatives --set java \
                /usr/lib/jvm/oracle-java8-jdk-amd64/jre/bin/java
)

apt-get install --yes --quiet \
        anbox \
        android-sdk \
        android-sdk-platform-23 \
        google-android-ndk-installer \
        libjmock-java \
        unzip \
        stow

# https://developer.android.com/studio/command-line/variables.html
export GRADLE_USER_HOME=$PWD/.gradle
export ANDROID_SDK_HOME=$PWD
export ANDROID_NDK_HOME=$ANDROID_SDK_HOME/android-ndk
export ANDROID_SDK_ROOT=$ANDROID_SDK_HOME/android-sdk
export ANDROID_HOME=$ANDROID_SDK_ROOT
unzip -q -d $ANDROID_SDK_HOME ../sdk-tools-linux-4333796.zip

: sh <<-'STOW'
        mkdir android-sdk android-ndk
        stow --verbose --target=$ANDROID_SDK_ROOT --dir=/usr/lib --stow android-sdk \
          --ignore=^tools --ignore=licenses
        stow --verbose --target=$ANDROID_NDK_HOME --dir=/usr/lib --stow android-ndk
STOW

mkdir $ANDROID_SDK_HOME/.android &&
cat > $ANDROID_SDK_HOME/.android/repositories.cfg <<-'CFG'
        ### User Sources for Android SDK Manager
        count=0
        src00=https\://dl.google.com/android/repository/addon.xml
CFG

JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 \
gradle --no-daemon --quiet --console=plain

yes | $ANDROID_SDK_HOME/tools/bin/sdkmanager \
        --sdk_root=$ANDROID_SDK_ROOT \
        --licenses \
> /dev/null \

xargs --verbose --max-lines \
        $ANDROID_SDK_HOME/tools/bin/sdkmanager \
                --sdk_root=$ANDROID_SDK_ROOT \
<<-'PACKAGE' > /dev/null || exit 3
        cmake;3.6.4111459
        extras;android;m2repository
        extras;m2repository;com;android;support;constraint;constraint-layout;1.0.1
PACKAGE
exit
Makefile
# https://developer.android.com/studio/intro/update
# ~/.AndroidStudio3.3/config/options/updates.xml
IDE_FILES=android-studio-ide-182.5314842-linux.zip
SDK_FILES=\
        3534162-studio.sdk-patcher.zip \
        android_m2repository_r47.zip \
        build-tools_r25.0.3-linux.zip \
        google_m2repository_gms_v9_1_rc07_wear_2_0_1_rc3.zip \
        platform-25_r03.zip platform-tools_r25.0.5-linux.zip \
        sdk-tools-linux-3859397.zip \
        sources-25_r01.zip
GRADLE_FILES=gradle-3.3-all.zip

ifndef DESTDIR
DESTDIR=.
endif

Android: $(SDK_FILES) $(IDE_FILES) $(GRADLE_FILES)
        mkdir -p $(DESTDIR)/$@/Sdk/extras \
            $(DESTDIR)/$@/Sdk/build-tools \
            $(DESTDIR)/$@/Sdk/platforms/android-25
        cp package.xml $(DESTDIR)/$@/Sdk/platforms/android-25
        ln -s ../../extras/android/android-7.1.1/android.jar $(DESTDIR)/$@/Sdk/platforms/android-25
        ln -s ../../extras/android/android-7.1.1/build.prop $(DESTDIR)/$@/Sdk/platforms/android-25
        cp package.xml $(DESTDIR)/$@/Sdk/platforms/android-25
        unzip -d $(DESTDIR)/$@/Sdk sdk-tools-linux-3859397.zip
        unzip -d $(DESTDIR)/$@/Sdk platform-tools_r25.0.5-linux.zip
        unzip -d $(DESTDIR)/$@/Sdk/patcher 3534162-studio.sdk-patcher.zip && \
            mv $(DESTDIR)/$@/Sdk/patcher/sdk-patcher $(DESTDIR)/$@/Sdk/patcher/v4
        unzip -d $(DESTDIR)/$@/Sdk build-tools_r25.0.3-linux.zip && \
            mv $(DESTDIR)/$@/Sdk/android-7.1.1 $(DESTDIR)/$@/Sdk/build-tools/25.0.3
        unzip -d $(DESTDIR)/$@/Sdk/extras/google google_m2repository_gms_v9_1_rc07_wear_2_0_1_rc3.zip
        unzip -d $(DESTDIR)/$@/Sdk/extras/android android_m2repository_r47.zip
        unzip -d $(DESTDIR)/$@/Sdk/extras/android platform-25_r03.zip
        unzip -d $(DESTDIR)/$@/Sdk/sources sources-25_r01.zip && \
            mv $(DESTDIR)/$@/Sdk/sources/src $(DESTDIR)/$@/Sdk/sources/android-25
        unzip -d $(DESTDIR)/$@ android-studio-ide-182.5314842-linux.zip
        unzip -d $(DESTDIR)/$@/android-studio/gradle gradle-3.3-all.zip
        rm -rf $(DESTDIR)/$@/android-studio/gradle/gradle-3.2

$(GRADLE_FILES):
        wget https://downloads.gradle.org/distributions/$@

$(IDE_FILES):
        wget https://dl.google.com/dl/android/studio/ide-zips/3.3.2.0/$@

$(SDK_FILES):
        wget https://dl.google.com/android/repository/$@