Automate Your Android Workflow — Command-Line Tools and Tips for App Development

Mastering Android App Development with Command-Line Tools

Overview

A focused guide to using command-line tools to build, test, debug, and distribute Android apps without relying on an IDE.

Essential tools

  • ADB (android debug bridge): install/uninstall APKs, access device shell, forward ports, capture logs.
  • sdkmanager / avdmanager: install SDK packages, create/manage emulators.
  • Gradle wrapper (./gradlew): build, assemble APK/AAB, run tests, manage flavors and build types.
  • bundletool: inspect and generate APKs from AABs.
  • apksigner / zipalign: sign and optimize APKs for release.
  • fastboot: flash images, unlock/lock bootloader (device-level tasks).
  • aapt / aapt2: inspect/manipulate resources and APK contents.
  • lint, androidx test CLI, emulator: static checks, instrumentation tests, headless emulator runs.

Typical CLI workflow (compact)

  1. Install SDK tools and platform-tools with sdkmanager; accept licenses.
  2. Start or create emulator via avdmanager / emulator.
  3. Build debug APK: ./gradlew assembleDebug
  4. Install to device: adb install -r app/build/outputs/apk/debug/app-debug.apk
  5. Run instrumentation tests: ./gradlew connectedAndroidTest
  6. Produce release AAB: ./gradlew bundleRelease
  7. Sign & verify release APK/AAB: apksigner sign/verify; zipalign if needed
  8. Convert AAB to device APKs for local testing: bundletool build-apks –bundle=app.aab
  9. Automate in CI: use ./gradlew, sdkmanager to install SDK components, and secure keystore handling for signing.

Tips & best practices

  • Use the Gradle wrapper in repos to lock Gradle version.
  • Keep AGP, Gradle, and JDK versions compatible (AGP 8.x → JDK 17+).
  • Script sdkmanager installs in CI to ensure deterministic environments.
  • Store signing keys securely (CI secret store) and avoid plaintext credentials in repos.
  • Use adb logcat and –no-window emulator options for headless debugging in CI.
  • Prefer AAB for Play distribution; use bundletool to replicate Play’s APK generation locally.
  • Add fast, repeatable tasks (assemble, test, lint) to CI pipelines for PR validation.

Useful commands (quick reference)

  • sdkmanager –sdk_root= “platform-tools” “build-tools;xx”
  • avdmanager create avd -n-k “system-images;android-;google_apis;x86”
  • ./gradlew assembleDebug | assembleRelease | bundleRelease
  • adb devices; adb install -r ; adb logcat
  • bundletool build-apks –bundle=app.aab –output=app.apks
  • apksigner sign –ks my-keystore.jks –out signed.apk unsigned.apk
  • zipalign -v -p 4 in.apk out.apk
  • fastboot devices; fastboot flash boot boot.img

Learning path (recommended)

  1. Master adb basics (install, shell, logcat).
  2. Learn Gradle tasks and the wrapper.
  3. Set up headless emulator and run connected tests.
  4. Automate SDK setup and builds in CI.
  5. Learn signing, apksigner, bundletool, and Play deployment steps.

If you want, I can produce a one-page cheatsheet with commands tailored to your project (Gradle/Kotlin/Java, target API, CI provider).

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *