Skip to content

This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!


Android Debug Bridge

ADB is a versatile CLI tool that lets you communicate with an android device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands.

Reference(s)

table of contents


android prerequisites

In your android device, do the following:

access android services

go in settings -> system -> developer options -> running services

access android memory stats

go in settings -> system -> developer options -> memory

access android local terminal app

go in settings -> system -> developer options -> local terminal


install

Install the android SDK platform tools:

On Arch based distros, install android-sdk-platform-tools with AUR:

$ mkdir -p ~/apps/aur-apps
$ cd ~/apps/aur-apps
$ git clone https://aur.archlinux.org/android-sdk-platform-tools.git
$ cd android-sdk-platform-tools
$ makepkg -si # --syncdeps to auto-install deps, --install to install after building
The tools will be found in /opt/android-sdk/platform-tools/.

Install android-sdk-platform-tools from here, in /opt/android-sdk/platform-tools/.


use

Reference(s)
  • Now if you connect your android device to your computer via USB, you will be able to run adb commands after running the ADB server:

    $ sudo /opt/android-sdk/platform-tools/adb kill-server
    $ sudo /opt/android-sdk/platform-tools/adb start-server
    

  • E.g. for the android finder application.

  • Enter ADB shell:

    $ sudo /opt/android-sdk/platform-tools/adb shell
    

  • Exit ADB shell:

    ...
    > exit
    

  • Print current user:

    $ sudo /opt/android-sdk/platform-tools/adb shell am get-current-user
    

  • Print installed packages:

    $ sudo /opt/android-sdk/platform-tools/adb shell pm list packages # all apps
    $ sudo /opt/android-sdk/platform-tools/adb shell pm list packages -3 # third party apps
    $ sudo /opt/android-sdk/platform-tools/adb shell pm list packages -s # system apps
    

  • Print local storage location:

    $ sudo /opt/android-sdk/platform-tools/adb shell echo $EXTERNAL_STORAGE
    

  • Extract photos:

    $ sudo /opt/android-sdk/platform-tools/adb shell echo $EXTERNAL_STORAGE
      > /sdcard
    $ sudo /opt/android-sdk/platform-tools/adb shell ls $EXTERNAL_STORAGE
      > ...
    $ sudo /opt/android-sdk/platform-tools/adb shell ls /sdcard/DCIM # this location may vary depending on your device
      > ...
    $ sudo /opt/android-sdk/platform-tools/adb pull /sdcard/DCIM/OpenCamera /path/to/your/download/folder
    


troubleshooting

device unauthorized

If you get the following error when running adb:

adb: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.

  • Restart the ADB server: adb kill-server && adb start-server

  • Next time you use adb to access the device, a pop-up will appear on the device asking to allow to connect to the adb server.


If this cheat sheet has been useful to you, then please consider leaving a star here.