ADB log and Important ADB commands

ANDROID

3/18/20234 min read

a close up of a keyboard
a close up of a keyboard

How to collect ADB and Important ADB command

What is ADB and How to collect ADB log

ADB stands for Android Debug Bridge. It is a command-line tool that is used to communicate with and control Android devices from a computer. ADB is primarily used by developers to test and debug Android applications, but it can also be used for a variety of other purposes, such as installing or uninstalling apps, transferring files, taking screenshots, and collecting logs. ADB requires a USB cable to connect an Android device to a computer and it also requires that USB debugging is enabled on the device. ADB can be accessed through the Android SDK (Software Development Kit) or can be downloaded separately as a standalone tool.

How to collect ADB log
(Download platform tools,Enable USB debugging,Collecting ADB log)

  • Download the Android SDK Platform Tools on your PC from https://developer.android.com/studio/releases/platform-tools

  • Extract the ZIP file at any location

  • Open a CMD at %extract_location%/platform-tools/

  • Test ADB by typing 'adb devices'. This should return an empty response for now.

  • USB debugging needs to be enabled on the device in order to enable ADB features. In order to enable USB debuggining, you may do the following:

  • The "Secure Debugging" feature requires that you manually approve your computer for an ADB connection. Developer Options are hidden.

  • To enable Developer Options, navigate to Settings > About Phone.

  • Tap Build Number 7 times. You will see a toast message stating you are now a developer.

  • Go back to main Settings menu and find the sub-setting called Developer Options.

  • Navigate to Developer Options, then check USB Debugging.

  • Getting Started with ADB

  • Connect your device to your PC via a USB port

  • Accept the prompt to trust the computer on the device

  • To confirm that all necessary drivers have been installed and that USB Debugging has been successfully enabled, run adb devices on the CMD prompt and confirm that the device shows up (list is not empty).

  • If the device does not appear, you are likely missing device drivers. To find all necessary device drivers on your PC, open a web browser and search (via Google, Yahoo, etc.) for adb drivers for device X. Download and install the drivers on your local PC with admin rights.

  • Check that adb devices is pulling up the device in question. If the devices shows up as unauthorized, unplug the device, plug back in, and accept the prompt to trust the PC.

  • If you run the command adb devices and then devices shows up with your serial number then you are good, you can start replicating your issue.

  • After replicating the issue, you can dump the ADB log by running command adb logcat - d > filename.txt
    Here is an example - adb logcat - d > log1.txt
    Log 1.txt is the ADB log which you will find under platform tools folder.

  • Sometimes after running the command you may not find your file under platform tool that means adb log file size is large and it is still getting dumped so in that case after waiting for few minutes, you can type CTRL+C command in your cmd prompt, after this you should be able to see your log file under platform tools folder.

Here are few important ADB commands

  • adb devices: This command is used to list all the Android devices that are connected to your computer via USB cable. Example: adb devices

  • adb logcat: This command is used to display the device log in real-time. This is useful for debugging applications and tracking system-level errors. Example: adb logcat

  • adb install: This command is used to install an Android application on a connected device. Example: adb install myapp.apk

  • adb uninstall: This command is used to uninstall an Android application from a connected device. Example: adb uninstall com.example.myapp

  • adb shell: This command is used to open a remote shell on the connected device, allowing you to execute commands directly on the device. Example: adb shell pm list packages

  • adb pull: This command is used to copy a file from the connected device to your computer. Example: adb pull /sdcard/myfile.txt C:\Users\MyUsername\Downloads

  • adb push: This command is used to copy a file from your computer to the connected device. Example: adb push myfile.txt /sdcard/

  • adb reboot: This command is used to reboot the connected device. Example: adb reboot

  • adb backup: This command is used to create a backup of the device's data. Example: adb backup -apk -shared -all -f backup.ab

  • adb restore: This command is used to restore a previously created backup to the device. Example: adb restore backup.ab

  • adb forward: This command is used to forward a network port from the device to the host machine. Example: adb forward tcp:8080 tcp:8080

  • adb sideload: This command is used to install a package (typically a firmware update) onto a device from a ZIP file on the host machine. Example: adb sideload update.zip

  • adb shell dumpsys: This command is used to dump system-level information to the device's log. Example: adb shell dumpsys activity

  • adb shell screencap: This command is used to capture a screenshot of the device's screen. Example: adb shell screencap /sdcard/screenshot.png

  • adb shell screenrecord: This command is used to record the device's screen to a video file. Example: adb shell screenrecord /sdcard/video.mp4

  • adb shell monkey: This command is used to simulate random user input on the device, which is useful for testing application stability. Example: adb shell monkey -p com.example.myapp -v 500

  • adb logcat -s: This command is used to filter the logcat output to only show logs from specific tags or processes. Example: adb logcat -s MyTag

  • adb shell am: This command is used to interact with the Android Activity Manager, which is responsible for managing application lifecycle. Example: adb shell am start -n com.example.myapp/.MainActivity

  • adb shell pm: This command is used to interact with the Android Package Manager, which is responsible for installing and uninstalling applications. Example: adb shell pm list packages

  • adb devices -l: This command is used to list all the Android devices that are connected to your computer, along with additional information such as device serial number and hardware properties. Example: adb devices -l


Related Stories