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)
- Install SDK tools and platform-tools with sdkmanager; accept licenses.
- Start or create emulator via avdmanager / emulator.
- Build debug APK: ./gradlew assembleDebug
- Install to device: adb install -r app/build/outputs/apk/debug/app-debug.apk
- Run instrumentation tests: ./gradlew connectedAndroidTest
- Produce release AAB: ./gradlew bundleRelease
- Sign & verify release APK/AAB: apksigner sign/verify; zipalign if needed
- Convert AAB to device APKs for local testing: bundletool build-apks –bundle=app.aab
- 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)
- Master adb basics (install, shell, logcat).
- Learn Gradle tasks and the wrapper.
- Set up headless emulator and run connected tests.
- Automate SDK setup and builds in CI.
- 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).
Leave a Reply