Gradle Commands
Key Rules
- •The Android project lives in
android/. Alwayscdthere before running Gradle. - •Always use
run_in_background: truefor any./gradlewcommand. Gradle builds are slow (minutes, not seconds) and will timeout or hang if run synchronously. - •Use
--no-daemon --console=plainflags for predictable, non-interactive output. - •Set
timeout: 120000(2 minutes). Do NOT use longer timeouts. - •Never block with
TaskOutputon a Gradle command. Instead, periodically check the output file withReadto monitor progress. - •Do other work while Gradle runs in background. Don't poll the output file in a tight loop.
Pattern
code
# Launch in background Bash(command="cd .../android && ./gradlew <task> --no-daemon --console=plain 2>&1", run_in_background=true, timeout=120000) # Check progress by reading the output file (returned in the tool result) Read(file_path="/private/tmp/.../tasks/<task_id>.output")
Common Tasks
bash
./gradlew assembleDebug # Build debug APK ./gradlew assembleRelease # Build release APK ./gradlew test # Unit tests ./gradlew connectedAndroidTest # Instrumented tests (needs device/emulator) ./gradlew test --tests "com.highliuk.manai.SomeTest.someMethod" # Single test ./gradlew lint # Android lint ./gradlew ktlintCheck # Check Kotlin style ./gradlew ktlintFormat # Auto-fix Kotlin style
Generating the Wrapper
bash
# Requires system `gradle` CLI (e.g. via Homebrew) cd android && gradle wrapper --gradle-version <version> --no-daemon
This also takes minutes on first run (downloads the distribution). Run in background.
Gotchas
- •First build downloads the Gradle distribution + all dependencies. Can take 5-10 minutes.
- •
gradle wrapperuses the systemgradle, not./gradlew. - •The
--no-daemonflag prevents orphan daemon processes that consume RAM.