blog.deanwild.co.uk

me@deanwild.co.uk


All | Cars | General | Tech

My ultimate list of useful ADB commands

January 25, 2024 | Tech

I've been working on Android / AOSP development since 2010 so needless to say I've gathered quite a repertoire of useful ADB commands over the years.

ADB Commands

Set a large logcat buffer (16MB):

adb logcat -G 16M

Enable verbose logging:

adb shell setprop persist.log.tag V

Revert to debug logging:

adb shell setprop persist.log.tag D

Retrieve list of all packages installed on device:

adb shell 'pm list packages -f' | sed -e 's/.*=//' | sort

Retrieve info about a specific package:

adb shell dumpsys package {packageName}

Kill an app:

adb shell am force-stop {packageName}

Clear data for an app:

adb shell pm clear {packageName}

Capture a screenshot:

adb exec-out screencap -p > screen.png

Get APK location for a specific package:

adb shell pm path {packageName}

Get the current foreground Activity:

adb shell dumpsys | grep mCurrentFocus

Resolve the launcher activity:

adb shell cmd package resolve-activity -c android.intent.category.HOME -a android.intent.action.MAIN

Uninstall a system app (requires an engineering build):

adb shell pm uninstall -k --user 0 {packageName}

Get total device RAM:

adb shell cat /proc/meminfo | grep MemTotal

Soft reboot (restarts zygote without a full reboot):

adb shell setprop ctl.restart zygote

Factory reset via ADB (requires engineering build):

adb shell am broadcast -a android.intent.action.MASTER_CLEAR -n android/com.android.server.MasterClearReceiver

or

adb shell am broadcast -a android.intent.action.FACTORY_RESET -n android/com.android.server.MasterClearReceiver

Other useful Android related commands:

Extract manifest file from an APK:

aapt list -a {apkFile.apk} | sed -n '/ activity /{:loop n;s/^.*android:name.*="\([^"]\{1,\}\)".*/\1/;T loop;p;t}'

Various methods for viewing/verifying an APK signature:

apksigner verify -v filename.apk
jarsigner -verify -certs filename.apk
keytool -printcert -jarfile filename.apk

View info about a keystore:

keytool -list -keystore {keystoreFilePath} -storepass {password}

Manually sign an APK using jarsigner:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore {keystoreFilePath} {apkFile.apk} {keystoreAlias}

Manually sign an APK using apksigner:

apksigner sign --verbose --ks {keyPath} --ks-pass pass:"{keyStorePassword}" --ks-key-alias {keyAlias} --key-pass pass:"{aliasPassword}" --out ${outputApk} {inputApk}

Extract build fingerprint from an AOSP OTA update package:

unzip -p {ota.zip} META-INF/com/android/metadata | grep "post-build="

Currently there are no comments, so be the first!