SDK Tools 26.1.1 (GNU/Linux, Windows)

Principle of operation

The Android SDK contains the SDK Tools, which are built from a different source tree than the SDK.

Recreate matching build environment

The current reference build environment for this version is Ubuntu 14.04.

Build dependencies

# OpenJDK 8 N/A
#apt-get -y install openjdk-8-jdk
apt-get -y install wget
cat <<'EOF' > $checksumfile
0f5aba8db39088283b51e00054813063173a4d8809f70033976f83e214ab56c0  openjdk-8-jre-headless_8u45-b14-1_amd64.deb
SHA256 9ef76c4562d39432b69baf6c18f199707c5c56a5b4566847df908b7d74e15849  openjdk-8-jre_8u45-b14-1_amd64.deb
SHA256 6e47215cf6205aa829e6a0a64985075bd29d1f428a4006a80c9db371c2fc3c4c  openjdk-8-jdk_8u45-b14-1_amd64.deb
sha256sum $checksumfile || exit "Incorrect checksums"
dpkg -i openjdk-8-jdk_8u45-b14-1_amd64.deb \
  openjdk-8-jre-headless_8u45-b14-1_amd64.deb \
  openjdk-8-jre_8u45-b14-1_amd64.deb || true
apt-get -y -f install

# Compiles 32-bit C++ programs
# 'emugen' compiled and run as 32-bit
apt-get -y install make binutils patch
apt-get -y install g++-multilib
apt-get -y install zip unzip libxml2-utils  # zip/unzip/zip + xmllint

Locating the source

According to the, studio-3.2.1 is the current stable version.

Preparing the source tree

Install repo:

sudo apt-get install curl ca-certificates git python
mkdir ~/bin/
curl > ~/bin/repo
chmod a+x ~/bin/repo

# avoid prompts
git config --global ""
git config --global "Your Name"
git config --global color.ui true

Shallow checkout of the source:

~/bin/repo init -u -b studio-3.2.1
# version == 26.1.1 according to 'tools/base/files/'
~/bin/repo sync -c -j4 -q
# 30mn with good connectivity
# ??GB (inc. 13GB .repo)

Building SDK Tools

mkdir -p out/dist
# Fix silly mistake
sed -i -e 's/${GRADLEW} $1/${GRADLEW} $*/' tools/buildSrc/servers/
time bash -x tools/buildSrc/servers/ `pwd`/out `pwd`/out/dist 0  # doesn't accept 26.1.1 as last argument :/
# Note: if needed for speed-up: remove target 'makeWinSdk' in that script

# Android Studio
#tools/base/bazel/bazel version
    cd tools/idea/
    bash -x ./

# Gradle plugin
    cd tools/
    ./gradlew assemble
    # TODO: this asks for a SDK, plus with more recent buildtools than we just compiled
    ./gradlew publishLocal || true

# 30mn, 42GB (inc. 13GB .repo)

This results in:

out/dist/  # SDK tools
tools/idea/out/studio/dist/  # Android Studio
out/repo/  # Android Gradle plugin

We just compiled Tools > Android SDK Tools 26.1.1!



We should be able to compile without (untrusted) prebuilts

Android Gradle Plugin

We're supposed to use the Android Gradle Plugin like this in your build.gradle:

buildscript {
   repositories {
       maven { url '.../out/repo' }
   dependencies {
       classpath ''

but the resulting repo lacks packages which are present in the prebuilts.