The Android Toolchain: SDK, Build-Tools & AGP
An Android build is Gradle orchestrating a handful of separate tools. Knowing which piece comes from where saves hours when a CI machine says "Failed to find Build Tools revision" or "SDK location not found".
The pieces
| Piece | Where it comes from | What it gives you |
|---|---|---|
| JDK | your machine / CI image (AGP 9 needs JDK 17 or newer to run) | javac, keytool, the JVM that runs Gradle |
| Gradle | the wrapper (gradle/wrapper/gradle-wrapper.properties) |
the build engine |
| Android Gradle Plugin (AGP) | Google's Maven repository (google()), declared in plugins {} |
the android {} DSL, variants, all Android tasks; R8 and the manifest merger are inside it |
SDK platform platforms;android-36 |
sdkmanager |
android.jar, the API you compile against (compileSdk = 36) |
Build-tools build-tools;36.0.0 |
sdkmanager |
command-line apksigner, zipalign, aapt2, d8 |
| Command-line tools | sdkmanager / a zip from developer.android.com |
sdkmanager, apkanalyzer, retrace, avdmanager |
| platform-tools | sdkmanager |
adb |
AGP finds the SDK through the ANDROID_HOME environment variable or a sdk.dir= line in local.properties (which is machine-specific: never commit it).
echo "ANDROID_HOME=$ANDROID_HOME"
ls $ANDROID_HOME
ls $ANDROID_HOME/platforms $ANDROID_HOME/build-tools
ls $ANDROID_HOME/cmdline-tools/latest/binANDROID_HOME=/opt/android-sdk
build-tools
cmdline-tools
licenses
platform-tools
platforms
/opt/android-sdk/build-tools:
36.0.0
/opt/android-sdk/platforms:
android-36
android
apkanalyzer
avdmanager
d8
lint
profgen
r8
resourceshrinker
retrace
screenshot2
sdkmanager
The licenses folder matters on CI: sdkmanager refuses to install packages until the licences are accepted (yes | sdkmanager --licenses), and AGP refuses to auto-install missing SDK packages without them.
Versions of the command-line tools
aapt2 version
apksigner --version
zipalign 2>&1 | head -1
d8 --version | head -1
bundletool version
java -version 2>&1 | head -1
gradle --version | grep -E '^Gradle|^Launcher'Android Asset Packaging Tool (aapt) 2.20-13193326
0.9
Zip alignment utility
D8 9.4.14 (build b1e20dd52788b7a226f83e24d49d0a53108bc84a from go/r8bot (luci-r8-custom-ci-archive-us-east1-b-0-qvuy))
1.18.3
openjdk version "21.0.13" 2026-10-20 LTS
Gradle 9.8.2
Launcher JVM: 21.0.13 (Eclipse Adoptium 21.0.13+9-LTS)
Note: the build-tools binaries are what you run by hand to inspect or re-sign outputs. AGP itself uses its own copies: aapt2 is downloaded from Google's Maven repository as
com.android.tools.build:aapt2, and R8/D8 ship inside AGP. That's why the R8 in a build (you'll seecompiler_version: 9.4.24in a mapping file) can differ from the standaloned8above.
What AGP pulls in
buildEnvironment lists the build script classpath, i.e. the plugins and everything they depend on. For AGP that includes bundletool, apksig (the signing library) and the aapt2 protocol buffers, all resolved from Maven like any other dependency:
mkdir -p hello/app && cd hello
cat > settings.gradle.kts <<'KTS'
pluginManagement { repositories { google(); mavenCentral(); gradlePluginPortal() } }
dependencyResolutionManagement { repositories { google(); mavenCentral() } }
rootProject.name = "hello"
include(":app")
KTS
echo 'plugins { id("com.android.application") version "9.4.1" apply false }' > build.gradle.kts
gradle -q buildEnvironment | grep -oE 'com.android.tools.build:(gradle|bundletool|apksig|aapt2-proto|manifest-merger):[^ ]+' | sort -ucom.android.tools.build:aapt2-proto:7.3.0-alpha07-8248216
com.android.tools.build:aapt2-proto:9.4.1-15978811
com.android.tools.build:apksig:9.4.1
com.android.tools.build:bundletool:1.18.3
com.android.tools.build:gradle:9.4.1
com.android.tools.build:manifest-merger:32.4.1
(The two aapt2-proto lines are one dependency: bundletool asks for an old version, and Gradle's conflict resolution upgrades it to AGP's.)
Pinning the toolchain
Each of these moves independently, so a reproducible mobile build pins all of them:
| What | Pin it in |
|---|---|
| Gradle | gradle/wrapper/gradle-wrapper.properties (distributionUrl + distributionSha256Sum) |
| AGP | plugins { id("com.android.application") version "9.4.1" } or gradle/libs.versions.toml |
| compileSdk / build-tools | compileSdk = 36 in android {}; buildToolsVersion only if you need a specific one (AGP has a default per release) |
| JDK | the CI image, or a Gradle toolchain / org.gradle.java.home |
| SDK packages on CI | an image with them pre-installed, or sdkmanager "platforms;android-36" "build-tools;36.0.0" in a cached step |
AGP and Gradle versions come in compatible pairs (AGP 9.x needs Gradle 9.x); the AGP release notes list the minimum Gradle and JDK. Upgrade them together, in their own commit.
Test yourself
Where does AGP look for the Android SDK?
- Only in ~/Android
- The ANDROID_HOME environment variable or sdk.dir in local.properties
- Inside the Gradle wrapper
- In gradle/libs.versions.toml
Which statement about R8 and AGP is true?
- R8 must be installed with sdkmanager
- R8 ships inside the Android Gradle Plugin, so its version follows AGP's
- R8 is part of the JDK
- R8 only exists in Android Studio
Why does a CI job fail with a licence error before building anything?
- The keystore is missing
- SDK licences weren't accepted, so sdkmanager/AGP won't install SDK packages
- Gradle needs a licence key
- R8 requires a commercial licence