Skip to content

ADB essentials ​

With a phone in the device state, a handful of commands cover most of a working day: install an app, remove it, copy files, ask the phone questions and capture its screen. This lesson shows each one, what it prints, and where the same action lives in DroidDeck.

Every command here acts on one device. If you have more than one connected, add -s and the serial, as in lesson 1.

Packages and APKs ​

Two words first.

  • An APK (Android Package) is the file an app is installed from, ending in .apk. It is a zip archive holding the app's code, images and a manifest that lists what the app is and what it needs.
  • A package name is the app's unique ID, written like a reversed web address: com.android.chrome, com.example.notes. The name under the icon is only a label. Every tool, including ADB, uses the package name.

Install and uninstall ​

Install an APK from your computer:

text
$ adb install notes-1.4.2.apk
Performing Streamed Install
Success

Useful options:

OptionWhat it does
-rReplace an app that is already installed, keeping its data. This is an update.
-tAllow a test-only APK, the kind a development build can produce.
-dAllow installing an older version over a newer one (a downgrade).
-gGrant every runtime permission the app asks for, without the pop-ups.

When an install fails, the reason is in capitals inside Failure [...]:

text
$ adb install -r notes-1.4.2.apk
Performing Streamed Install
adb: failed to install notes-1.4.2.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.example.notes signatures do not match previously installed version; …]

That one means the installed copy was signed by a different key, for example a store version, and this APK cannot replace it. Lesson 5 explains signatures. Other common reasons are INSTALL_FAILED_VERSION_DOWNGRADE (use -d if you mean it) and INSTALL_FAILED_INSUFFICIENT_STORAGE.

Remove an app by its package name, not its file name:

text
$ adb uninstall com.example.notes
Success

Uninstalling deletes the app and its data. adb uninstall -k keeps the data and cache folders, but most of the time you want everything gone or nothing touched.

Push and pull files ​

ADB's words for copying are from the computer's point of view:

text
           push  ──────────────►
 COMPUTER                          PHONE
           ◄──────────────  pull
text
$ adb push notes.txt /sdcard/Download/
notes.txt: 1 file pushed, 0 skipped. …

$ adb pull /sdcard/DCIM/Camera/IMG_20261109_101500.jpg .
/sdcard/DCIM/Camera/IMG_20261109_101500.jpg: 1 file pulled, 0 skipped. …

The . at the end of pull means "the current folder". Both commands copy whole folders too.

/sdcard is the phone's shared storage, where photos, downloads and documents live. Most of the rest of the phone, such as other apps' private data in /data/data, is closed to ADB on a normal phone. That is deliberate: apps keep their data private from each other and from you.

WARNING

push replaces a file of the same name on the phone without asking, and pull does the same on your computer. Check the destination first.

The shell ​

Android is built on Linux, so every phone has a command line. adb shell opens it:

text
$ adb shell
emu64x:/ $ ls /sdcard
Alarms  Android  DCIM  Documents  Download  Movies  Music  Pictures  …
emu64x:/ $ exit

The $ in the prompt means you are the ordinary shell user, not root. You can also run one command and come straight back:

bash
adb shell ls /sdcard/Download

The shell commands worth knowing first:

pm: the package manager ​

text
$ adb shell pm list packages -3
package:com.example.notes
package:org.mozilla.firefox
…
$ adb shell pm path com.example.notes
package:/data/app/~~…/com.example.notes-…/base.apk

pm list packages lists every app; -3 keeps only the ones a user installed, -s only system apps. Add a word to filter: pm list packages chrome. pm path shows where an app's APK files are, which is how you can copy an app's APK out with adb pull.

getprop: facts about the phone ​

text
$ adb shell getprop ro.build.version.release
14
$ adb shell getprop ro.build.version.sdk
34
$ adb shell getprop ro.product.model
Pixel 7

These are system properties, settings the system keeps as name and value pairs. release is the Android version people talk about; sdk is the API level, the number developers use. Run getprop with no name to see them all. Your values will differ from these.

input: press buttons and type ​

bash
adb shell input keyevent 4          # Back
adb shell input keyevent 3          # Home
adb shell input text "hello"        # type into the focused field
adb shell input tap 540 1200        # tap at x=540, y=1200 pixels

Handy for repeating the same steps while testing, or for typing a long test value into a phone.

screencap and screenrecord: capture the screen ​

bash
adb exec-out screencap -p > screen.png

screencap -p writes a PNG. exec-out passes the bytes straight to your computer, so the > saves the picture there.

bash
adb shell screenrecord /sdcard/demo.mp4
adb pull /sdcard/demo.mp4
adb shell rm /sdcard/demo.mp4

screenrecord runs until you press Ctrl + C or it reaches its limit of 180 seconds. Set a shorter limit with --time-limit 30. The video has no sound, and Android records a frame only when the screen changes, so tap and scroll while it runs. The last line tidies up the copy left on the phone.

The same in DroidDeck ​

Each DroidDeck button runs one of these commands for you on the device in the device picker:

You want toCommandDroidDeck
Install an APKadb install -r -tApps tab › Install APK, or drop the file on the tab
Uninstalladb uninstallApps › an app's Actions menu › Uninstall…
Copy an app's APK outpm path, then adb pullActions › Extract APK
Push filesadb pushFiles tab › Push here
Pull a fileadb pullFiles › the file's menu › Pull to ~/Downloads
Screenshotadb exec-out screencap -pScreen tab › Capture
Record the screenadb shell screenrecord --time-limitScreen › Screen recording › Start
Press Back or Homeadb shell input keyeventShell tab › Quick actions
Any other commandadb shellThe Shell tab's terminal

The guides: Manage apps, Browse and transfer files, Use the screen tools, Use the shell and quick actions. The full list of commands is in the DroidDeck reference.

When you do not need ADB ​

To move a few photos or documents between your phone and a computer, you do not need debugging at all. NearShare receives files on Linux from the phone's own Quick Share, over Wi-Fi, with a PIN shown on both screens, and USB debugging can stay off. Use ADB when you need what only ADB can do: install builds, read logs, run commands.

Stay safe ​

  • Shell commands run at once, with no undo. rm deletes for good; there is no recycle bin on the phone. Do not paste commands you do not understand, especially from a forum post.
  • Uninstall deletes the app's data. Copy out anything you need first.
  • Install only APKs you trust. An app installed over ADB gets the same powers as one from a store. Lesson 5 shows how to check one.
  • Screenshots and recordings capture everything on screen, including notifications and messages. Look before you attach one to a bug report.

Check yourself ​

QuizADB essentials

Question 1 of 6

Which command copies notes.txt from your computer to the phone's Download folder?

Score: 0

What you learned ​

  • adb install and adb uninstall add and remove apps; uninstall uses the package name and deletes the app's data.
  • push copies to the phone, pull copies from it; /sdcard is the shared storage ADB can reach.
  • adb shell opens the phone's command line: pm for packages, getprop for facts, input for keys and taps, screencap and screenrecord for the screen.
  • Each DroidDeck button is one of these commands.

Next steps ​