Build (and optionally install and launch) an Android app
android_buildAssemble an Android APK via Gradle and optionally install and launch it on a connected device, handling JDK compatibility and condensing build errors for quick iteration.
Instructions
Run a Gradle assemble for an Android project and, when asked, install the APK and start it on a device — the full edit-run loop in one call.
Handles the toolchain details that normally break automated builds:
picks a JDK Gradle can actually run on (Android Studio's bundled JBR when present), instead of trusting the ambient JAVA_HOME
refuses to start, with an explanation, when the JDK is newer than the Gradle wrapper supports
condenses a failed build's log down to the compiler errors instead of returning thousands of progress lines
The first build of a project downloads the Gradle distribution and dependencies and can take several minutes.
Args:
project_path (string): absolute path to the Gradle root (contains gradlew)
module (string): module producing the APK (default: 'app')
variant ('debug' | 'release'): build variant (default: 'debug')
clean (boolean): run the 'clean' task first (default: false)
install (boolean): install the APK after a successful build (default: false)
launch (boolean): start the app after installing; implies install (default: false)
serial (string, optional): target device when installing
timeout_ms (number): build timeout (default: 900000)
response_format ('markdown' | 'json')
Returns: { "success": boolean, "task": string, // e.g. "assembleDebug" "durationMs": number, "apkPath": string, // present on success "packageName": string, // resolved from applicationId / namespace / manifest "gradleVersion": string, "javaMajor": number, // JDK major version used "installed": boolean, "launched": boolean, "output": string, // build tail on success, error summary on failure "hint": string // present when the failure is recognised }
Examples:
Use when: "build and run this app on my phone" -> project_path=..., install=true, launch=true
Use when: verifying a code change compiles -> project_path=..., install=false
Don't use when: the APK is already built and you only want it installed (use android_install)
Error Handling:
"Unsupported class file major version" is caught before the build starts and reported as a JDK/Gradle mismatch with the fix
"SDK location not found" means local.properties or ANDROID_HOME is missing
Install failures report the adb failure code (e.g. INSTALL_FAILED_UPDATE_INCOMPATIBLE) with the usual remedy
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clean | No | Run the 'clean' task before assembling. | |
| force | No | Skip the JDK/Gradle compatibility pre-check. Use only when the check is out of date and the combination is known to work. | |
| launch | No | Start the app after installing. Implies install. | |
| module | No | Gradle module that produces the APK. Almost always 'app'. | app |
| serial | No | Device serial from android_list_devices. Optional when exactly one device is connected; required when several are. | |
| install | No | Install the APK after building. | |
| variant | No | Build variant. 'release' requires signing config to be set up in the project. | debug |
| timeout_ms | No | Build timeout in milliseconds. | |
| project_path | Yes | Absolute path to the Gradle project root — the directory containing gradlew and settings.gradle. | |
| response_format | No | Output format: 'markdown' for human-readable, 'json' for machine-readable. | markdown |