Install the Android SDK command-line tools, platform tools, and the required platform or system image before using these commands. Set ANDROID_HOME to the SDK directory and add its cmdline-tools/latest/bin, platform-tools, and emulator directories to PATH.
Android Debug Bridge #
adb connects the host client to the local ADB server and the device-side adbd daemon. Select a target explicitly with -s SERIAL whenever more than one device or emulator is available.
adb devices -l
adb -s SERIAL get-state
adb -s SERIAL shell getprop ro.build.fingerprint
adb -s SERIAL rebootadb devices -l reports a target as device, offline, or unauthorized. Accept the device’s RSA-key prompt to resolve unauthorized; use adb kill-server followed by adb start-server only when the local server state is stale. The shell user is not root on production builds.
Packages and Files #
Install an APK with --replace to retain its data. Use install-multiple for split APKs and pm from a shell for package metadata and permission management.
adb -s SERIAL install --replace app.apk
adb -s SERIAL install-multiple base.apk config.arm64_v8a.apk config.en.apk
adb -s SERIAL uninstall com.example.app
adb -s SERIAL shell pm path com.example.app
adb -s SERIAL push local.txt /sdcard/Download/
adb -s SERIAL pull /sdcard/Download/report.txt .adb push and pull operate under the permissions available to shell; scoped storage and application-private directories can restrict access. Use run-as PACKAGE only for debuggable applications.
Shell, Logs, and Diagnostics #
Use exec-out for binary or unmodified command output because it does not allocate a pseudo-terminal. Filter Logcat at the source to avoid transferring an unbounded log stream.
adb -s SERIAL shell cmd package list packages
adb -s SERIAL exec-out screencap -p > screenshot.png
adb -s SERIAL logcat -c
adb -s SERIAL logcat -v threadtime MyTag:D '*:S'
adb -s SERIAL bugreport report.zip
adb -s SERIAL shell dumpsys activity activitiesbugreport captures logs and system state, and may contain sensitive data. dumpsys exposes service-specific diagnostic output; run adb shell dumpsys -l to list available services.
Networking and Wireless Debugging #
forward makes a device service reachable through a host port. reverse makes a host service reachable from an emulator or USB-connected device.
adb -s SERIAL forward tcp:8080 tcp:8080
adb -s SERIAL reverse tcp:3000 tcp:3000
adb pair HOST:PAIRING_PORT
adb connect HOST:CONNECT_PORTWireless debugging requires Android’s authenticated pairing flow. Use it only on trusted networks, and disconnect with adb disconnect HOST:CONNECT_PORT when finished.
Fastboot #
fastboot communicates with the bootloader rather than the running Android system. Enter fastboot mode through the device UI or adb reboot bootloader. The command set, available partitions, and unlock policy are device-specific.
fastboot devices -l
fastboot getvar product
fastboot getvar current-slot
fastboot reboot fastbootUse fastboot getvar all to inspect bootloader variables, although some devices restrict its output. A/B devices expose slots through current-slot; use the image package’s documented flashing procedure instead of inferring partition names.
Flashing and Recovery #
Verify the selected device, image hash, partition name, slot, and bootloader policy before a write operation.
shasum -a 256 boot.img
fastboot flash boot boot.img
fastboot --set-active=a
fastboot rebootUnlocking, flashing critical partitions, and slot changes can erase data or make a device unbootable. Do not use fastboot flash against an unknown device or an image built for a different product.
Miscellaneous #
SDK and Virtual Device Management #
sdkmanager installs SDK packages, and avdmanager creates Android Virtual Devices (AVDs).
sdkmanager --list
sdkmanager "platform-tools" "platforms;android-35"
sdkmanager "system-images;android-35;google_apis;x86_64"
avdmanager create avd --name api-35 --package "system-images;android-35;google_apis;x86_64"Accept licenses with sdkmanager --licenses. Pin package revisions in CI because an unqualified package update can alter the build environment.
Emulator #
emulator -list-avds
emulator -avd api-35 -no-snapshot
emulator -avd api-35 -wipe-dataUse -no-snapshot for a clean boot and -wipe-data only when resetting state is intended.
APK and App Bundle Inspection #
apkanalyzer reads APK metadata and bytecode without installing the application.
apkanalyzer manifest application-id app.apk
apkanalyzer apk summary app.apk
apkanalyzer dex packages app.apkbundletool converts an Android App Bundle into installable APK sets and selects device-specific splits.
java -jar bundletool-all.jar build-apks --bundle=app.aab --output=app.apks
java -jar bundletool-all.jar install-apks --apks=app.apksUse --connected-device with get-device-spec when reproducing split selection. Treat signing keys and generated .apks archives as release artifacts.
Gradle #
The Gradle wrapper provides reproducible project-local build tooling.
./gradlew assembleDebug
./gradlew installDebug
./gradlew lintDebug
./gradlew connectedDebugAndroidTestRun the wrapper rather than a globally installed Gradle version. connectedDebugAndroidTest requires an available emulator or USB-connected device.
Comments
Read or comment on GitHub (sign-in required to comment)