Prepare the Android build tools
Android SDK and project configuration
To develop apps for Android, you need to use the Android SDK. Use a terminal on your development machine to install JDK 17 and the
Android SDK command-line tools
.
If you used WSL for model preparation, use WSL for the asset-sync command at
the start of the next page. Run the SDK commands below and the later Gradle and
adb commands in Windows PowerShell because USB-connected Android devices are
not exposed to WSL by default.
brew install openjdk@17
brew install --cask android-commandlinetools
export JAVA_HOME="$(brew --prefix openjdk@17)/libexec/openjdk.jdk/Contents/Home"
export ANDROID_HOME="$(brew --prefix)/share/android-commandlinetools"
export PATH="$JAVA_HOME/bin:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
sudo apt update
sudo apt install -y openjdk-17-jdk unzip
export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-$(dpkg --print-architecture)"
export ANDROID_HOME="$HOME/Android/Sdk"
export PATH="$JAVA_HOME/bin:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
winget install --exact --id Microsoft.OpenJDK.17
$env:JAVA_HOME = (Get-ChildItem "C:\Program Files\Microsoft" -Directory -Filter "jdk-17*" | Sort-Object Name -Descending | Select-Object -First 1).FullName
$env:ANDROID_HOME = "$env:LOCALAPPDATA\Android\Sdk"
$env:Path = "$env:JAVA_HOME\bin;$env:ANDROID_HOME\cmdline-tools\latest\bin;$env:ANDROID_HOME\platform-tools;$env:Path"
If Homebrew reports a conflict with android-cli, remove that cask before
installing android-commandlinetools. Both casks install an android
executable and cannot be installed together.
The environment variables ensure that the Gradle wrapper does not select a newer, incompatible JDK.
On Ubuntu or Windows, also download the appropriate command-line tools archive from the
Android Studio download page
and extract it. Place the contents of its cmdline-tools directory under
$ANDROID_HOME/cmdline-tools/latest on Ubuntu or
$env:ANDROID_HOME\cmdline-tools\latest on Windows. The resulting bin
directory should contain the sdkmanager command.
Install the SDK packages used by the project. Accept the license terms if prompted:
sdkmanager --licenses
sdkmanager "platform-tools" "platforms;android-35" "build-tools;34.0.0"
Check the installed Java and Android tools:
java -version
sdkmanager --version
adb version
java -version must report Java 17.
The project configuration is:
| Setting | Value |
|---|---|
| Application ID | org.arm.education.executorch.objectcutout |
| Minimum SDK | 28 |
| Compile and target SDK | 35 |
| SDK Build Tools | 34.0.0 |
| Android Gradle Plugin | 8.7.3 |
| Gradle wrapper | 8.9 |
| JDK and Java target | 17 |
| ExecuTorch Android | 1.3.1 |
| Packaged ABIs | arm64-v8a, x86_64 |
The minimum SDK is the oldest Android API level the app supports. The compile SDK supplies APIs used while building, and the target SDK tells Android which platform behavior the app has been tested against. The Android Gradle Plugin connects Gradle to the Android SDK, while the Gradle wrapper pins the build tool version used by the project.
These versions are tested together. If Android Studio offers to upgrade Gradle or the Android Gradle Plugin, keep the versions supplied by the project.
The x86_64 ABI lets the app run in a compatible emulator. Use a physical
Arm-based phone for meaningful mobile timing measurements.
The project obtains the ExecuTorch AAR from Maven Central through Gradle:
dependencies {
implementation("org.pytorch:executorch-android:1.3.1")
}
The application source is Java, but model execution is native. Calls such as
Module.load() and Module.forward() use the ExecuTorch Java API and JNI
bridge to enter the C++ ExecuTorch runtime packaged in the AAR. ExecuTorch dispatches delegated regions to XNNPACK and runs any remaining operators with its portable kernels, while the Java code handles Android assets, preprocessing, postprocessing, threading, and the user interface.
The ExecuTorch Android guide describes two alternatives to downloading the prebuilt AAR from Maven Central:
- store a downloaded AAR in the project for offline or restricted build environments
- build a custom AAR from ExecuTorch source when changing native code, operators, or backends
For applications that use the supported operators and backends without custom native code, the Maven Central approach used here is usually the simplest choice.
Course complete
Nice work
You completed Optimize and deploy AI inference with ExecuTorch on Arm.