SoFunction
Updated on 2025-03-04

Android debugging tool adb command collection

1. Adb introduction
The Tools folder of the SDK contains the important command adb for Android emulator operation. The full name of adb (Android Debug Bridge is the function of the debug bridge. Through adb, we can debug Android programs through DDMS in Eclipse. With this tool, we can manage the status of the device or mobile phone emulator. We can also perform the following operations:

1. Quickly update the code in the device or mobile phone emulator, such as application or Android system upgrade;
2. Run shell commands on the device;
3. Manage the predetermined ports on the device or mobile phone emulator;
4. Copy or paste files on the device or mobile phone emulator;
2. Adb's work in an integrated development environment
The working method of adb is quite special by listening to Socket TCP 5554 and other ports to allow IDE to communicate with Qemu. By default, adb will daemon-related network ports, so when we run Eclipse, the adb process will run automatically.
1. Through adb, you can easily execute Linux shell commands. For example, adb shell dir is to list directories. In Linux, the root directory is / instead of the C drive or D drive on Windows.
2. When installing the apk program to the emulator, execute adb install, so that the installation package named Android123 will be installed in the Android emulator, provided that the file needs to be placed in the SDK/Tools directory.
3. Transfer files to the emulator. Use the adb push /tmp/ command to transfer files under SDK/Tools to the /tmp/ folder of the emulator. It should be noted that the contents in the /tmp/ folder will be cleared when the Android emulator is restarted.
4. Return files from Android emulator to computer
The adb pull /tmp/ command will return the files in the tmp folder of the emulator to the computer SDK/Tools directory.
3. A complete collection of commonly used adb commands
1. Display all Android platforms in the system:
    android list targets
2. Display all AVDs in the system (simulator):
    android list avd
3. Create an AVD (Simulator):
android create avd --name name --target platform number
4. Start the emulator:
emulator -avd name -sdcard ~/name.img (-skin 1280x800)
5. Delete AVD (Simulator):
android delete avd --name name
6. Create an SDCard:
mksdcard 1024M ~/name.img
7. AVD (Simulator) location:
    Linux(~/.android/avd)      Windows(C:\Documents and Settings\Administrator\.android\avd)
8. Start DDMS:
    ddms
9. Show all the simulators currently running:
    adb devices
10. Execute commands to a certain emulator:
abd -s emulator number command
11. Install the application:
adb install -r application.apk
12. Get the file in the emulator:
      adb pull <remote> <local>
13. Write files to the simulator:
      adb push <local> <remote>
14. Enter the shell mode of the emulator:
      adb shell
15. Start the SDK, Document, and Instance Download Manager:
      android
16. Strong load apk package:
      adb shell
      cd data/app
rm apk package
      exit
adb uninstall apk package main package name
adb install -r apk package
17. Check the adb command help information:
      adb help
18. View LOG information on the command line:
adb logcat -s tag name
19. The commands followed by the adb shell mainly come from:
Source code\system\core\toolbox directory and source code\frameworks\base\cmds directory.
20. Delete the system application:
adb remount (remount the system partition to make the system partition rewriteable).
      adb shell
      cd system/app
      rm *.apk
21. Obtain administrator permissions:
      adb root
22. Start Activity:
adb shell am start -n package name/package name + class name (-n class name, -a action, -d date, -m MIME-TYPE, -c category, -e extension data, etc.).
23. Publish port:
You can set any port number as the host's request port to the emulator or device. like:
adb forward tcp:5555 tcp:8000
24. Copy the file:
You can copy files to or from a device,
Copy a file or directory to the device or emulator:
adb push <source> <destination></destination></source>
For example: adb push /tmp/
Copy a file or directory from the device or emulator:
     adb pull <source> <destination></destination></source>
For example: adb pull /addroid/lib/.
25. Search for examples of simulator/device:
Get the list of instances of the currently running emulator/device and the status of each instance:
    adb devices
26. Check the bug report:
adb bugreport
27. Record wireless communication log:
Generally speaking, there are a lot of logs for wireless communication, so there is no need to record them during operation, but we can still set the records through commands:
    adb shell
    logcat -b radio
28. Obtain the device ID and serial number:
     adb get-product
     adb get-serialno
29. Access the database SQLite3
     adb shell
     sqlite3
#cd system/sd/data //Enter the specified folder in the system
#ls //The list displays the current folder contents
#rm -r xxx //Delete folder with name xxx and all files inside
#rm xxx //Delete file xxx
#rmdir xxx //Delete xxx folder