Post

Basic Commands of Android Debug Bridge

Basic Commands of Android Debug Bridge

Android Debug Bridge Android Debug Bridge commands that are frequently used in Android Software Development.

๐‚๐จ๐ง๐ญ๐ž๐ง๐ญ ๐จ๐Ÿ ๐ญ๐ก๐ข๐ฌ ๐š๐ซ๐ญ๐ข๐œ๐ฅ๐ž:

  • ๐”๐ฌ๐ž ๐€๐ƒ๐ ๐ฐ๐ข๐ญ๐ก๐จ๐ฎ๐ญ ๐ฐ๐ซ๐ข๐ญ๐ข๐ง๐  ๐Ÿ๐ฎ๐ฅ๐ฅ๐ฉ๐š๐ญ๐ก ๐ญ๐จ ๐ž๐ฑ๐ž๐œ๐ฎ๐ญ๐š๐›๐ฅ๐ž
  • ๐‚๐จ๐ง๐ง๐ž๐œ๐ญ ๐ญ๐จ ๐๐ž๐ฏ๐ข๐œ๐ž ๐จ๐ฏ๐ž๐ซ ๐–๐ข-๐…๐ข
  • ๐€๐ƒ๐ ๐ฎ๐ง๐š๐›๐ฅ๐ž ๐ญ๐จ ๐œ๐จ๐ง๐ง๐ž๐œ๐ญ ๐ญ๐จ ๐๐ž๐ฏ๐ข๐œ๐ž
  • ๐ˆ๐ง๐ฌ๐ญ๐š๐ฅ๐ฅ, ๐”๐ง๐ข๐ง๐ฌ๐ญ๐š๐ฅ๐ฅ ๐š๐ง๐ ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐ ๐š๐ฉ๐ค
  • ๐‘๐ž๐œ๐จ๐ซ๐ ๐ฏ๐ข๐๐ž๐จ ๐Ÿ๐ซ๐จ๐ฆ ๐ฌ๐œ๐ซ๐ž๐ž๐ง
  • ๐’๐œ๐ซ๐ž๐ž๐ง๐ฌ๐ก๐จ๐ญ ๐œ๐š๐ฉ๐ญ๐ฎ๐ซ๐ž
  • ๐‘๐ž๐œ๐จ๐ซ๐ ๐‹๐จ๐ ๐‚๐š๐ญ

Use ADB without writing fullpath to executable

If ADB was installed on Windows with Android Studio then executable probably located at:

1
C://Users/{USER_NAME}/AppData/Local/Android/Sdk/platform-tools

By default to launch adb command user need to either move to directory with adb executable or write full path to it. To avoid it and be able to lunch adb by just typing ยซadbยป in terminal, user can edit Operation System enviroment variable PATH. This variable is used by operation system to recognize commands and operable programs.

To edit this variable on Windows:

  1. Press Windows button.
  2. Type ยซEdit the system enviroment variablesยป.
  3. Press ยซEnviroment Variablesโ€ฆยป button.
  4. In ยซSystem variablesยป table look for ยซPathยป Varialbe.
  5. Select ยซPathยป varialbe and click ยซEditยป button.
  6. Add full path to the ADB directory.
  7. Restart command line utility.

After this user can lunch adb commands without writing full path to adb executable.

Simmilar thing can be done on Mac and Linux operation systems.

Connect to device over Wi-Fi

Connect

1
adb connect 172.16.107.156:2111

IP adress and port of android device can be displayed on Android Notification Shade or in the Android Settings:

  1. Go to Developer Options
  2. Turn on Wireless debugging
  3. Look for IP address & Port

Note that PC and Android device should be connected to the same network.

List connected devices

1
adb devices

Disconnect

1
adb disconnect

ADB unable to connect to device

Some devices, especially POS-terminals and Smart TVs may not connect in a first try. The fast way to fix it is to:

  1. Turn off and turn on Android device Wi-Fi.
  2. On Android devices try to browse web.
  3. Restart adb:
    1
    2
    
    adb kill-server
    adb start-server 
    
  4. Double check correctness of ip adress and the fact that PC and Android device are connected to the same network. Try to connect again:
    1
    
    adb connect 172.16.107.156:2111
    

Install, Uninstall and Download apk

Install

1
adb install -r full_path_to_file.apk

List installed apps

1
adb shell pm list packages -f com.package

Uninstall app

1
adb shell pm uninstall com.package.fullname

Download apk from Android device

Get the full path name of the APK file for the desired package

1
adb shell pm path com.package.fullname

Use this full path with pull command

1
adb pull /data/app/com.example.fullname.apk

Record video from screen

Start recording

1
adb shell screenrecord /sdcard/example.mp4

Stop recording

1
Ctrl+C

Download recording from device

1
adb pull /sdcard/example.mp4 .

Remove recording from device

1
adb shell rm /sdcard/example.mp4

Recording time limit is 3 minutes

Note that time limit for this utility is 3 minutes. You can make .bat file with content:

1
2
3
adb shell screenrecord --bit-rate 8000000 /sdcard/sr1.mp4
adb shell screenrecord --bit-rate 8000000 /sdcard/sr2.mp4
adb shell screenrecord --bit-rate 8000000 /sdcard/sr3.mp4

to subsequently capture screen recordings for further merging into longer videos.

Screenshot capture

Take screenshot and download it on PC:

1
adb shell screencap -p /sdcard/screencap.png && adb pull /sdcard/screencap.png

Screenshot will apear in current directory of terminal session.

Record LogCat

Clear logs

1
adb logcat -c

Save log output to file

1
adb logcat > logcat.txt
This post is licensed under CC BY 4.0 by the author.