[TUTORIAL] Everything about ADB - A reference for everyone

Search This thread

OzBoy08

Senior Member
Feb 10, 2011
151
15
Melbourne
I have found this tutorial very helpful. It has enabled me to play around with adb on a basic level without the fear of anything going wrong. Well done and many thanks.
 

john-au

Senior Member
Feb 6, 2011
166
26
Brisbane
Quote:

Instead of executing these four commands, you can download the batch file getlog.cmd and extract it from the zip file to the folder containing adb.exe. Once you type in the following command (from anywhere in Windows), you will achieve the same result as typing the four commands as above! Ingenious, eh?

/Quote:


Not sure about getting a logcat.

I have d/led getlog.cmd and placed it in the same folder as adb.exe

Now what?

I tried typing in adb logcat and got all the info in the cmd window but how do you get it to a txt file? Also tried the four commands but kept getting an error at the echo line.

Sorry very new to adb.

Edit: I created a txt file called log.txt in the same folder as adb.exe and clicked on getlog.cmd and I think it worked. Anyone tell me if this is correct.
 
Last edited:

trust-no-one

Senior Member
Dec 19, 2011
127
22
Adelaide
Great tutorial, prior to reading this I had no idea about how to use ADB, but now I can get around reasonably well... I don't even have a Desire, or even a HTC phone yet, but I learnt on my Transformer, and it works great! My first step to becoming an Android dev I guess :p might even consider cooking a ROM soon.

tno~~
 

Droidzone

Inactive Recognized Developer
Sep 24, 2010
5,531
2,283
Kochi
www.droidzone.in
OnePlus 9 Pro
How to get Kernel error messages

Added another one to OP

You can get debug messages from a running kernel with:

Code:
adb shell
dmesg

If you have reboots due to kernel panic, you should make users capture the last_kmsg log from /proc immediately on the reboot.

Code:
adb shell 
cat /proc/last_kmsg > /sdcard/last_kmsg
Should be done immediately after the reboot..Otherwise it will just get overwritten by newer kernel message.

So in brief, if you'd like to look at what the kernel is doing right now (any errors etc), you should use dmesg. If you want to know why your kernel rebooted, use the file proc/last_kmsg


It's extremely useful!
 
  • Like
Reactions: angusc

fs1023

Senior Member
Problem - adb logcat > log.txt

Droidzone thanks for your fantasic newb guide.

I am looking at your guide to learn and get a better understanding of what went wrong with my phone the other day (all is Ok now) when I had to use Fastboot for my phone to be recognised again by pc/phone, of which i was/am clueless at what i did.

I had already installed ADB SDK files/tools a while ago in case i have a USB brick on my desire.........

I have done 'adb install' and dragged apk file to cmd which was a success but not having any luck with 'adb logcat > log.txt. Curser just hangs for about 5 mins then goes back to cmd prompt.

I have looked at post 25 (john-au) and i do not know what he did.

Regards
fs1
 

fs1023

Senior Member
Look inside the file log.txt

Sent from my HTC Desire using Tapatalk

Thanks for quick reply.

I have created a log.txt file and put it in adb exe folder.
Typed in cmd >adb logcat > log.txt hit enter and get

-waiting for device-

What an i doing wrong?

EDIT: Did a file search and it was not in folder with adb.exe but in c:\users\myname.
 
Last edited:

angusc

Senior Member
May 12, 2006
2,799
504
Beijing
If you want to see your Battery logs:

adb shell dumpsys batteryinfo

or from Android Terminal window:
dumpsys batteryinfo > /sdcard/batterystats.txt

And then check the file created on the sdcard "batterystats.txt"
 
Last edited:

TVTV

Senior Member
Jan 5, 2010
336
140
Bucharest
Thanks for the great guide! The only thing i don't like about it is the beg for "Thanks" at the end of each post. It's not elegant, if you ask me.
 

Droidzone

Inactive Recognized Developer
Sep 24, 2010
5,531
2,283
Kochi
www.droidzone.in
OnePlus 9 Pro
Who's begging for thanks? Thanks is just an indicator of how many people found a post useful. Hit the button or not, I couldn't care less. Much better than begging for thanks in ones signature, or begging for money any day.

Swyped on my Htc Desire running on Supernova Extreme - Gingerbread goodness with 2 GB of Internal memory
 
  • Like
Reactions: Sharkeyd

Droidzone

Inactive Recognized Developer
Sep 24, 2010
5,531
2,283
Kochi
www.droidzone.in
OnePlus 9 Pro
thank you for this guide, i have been learning a lot quickly using this. saved me multiple times.:D

There's a lot more about adb to explain. There are advanced filters you can set, and commands to make the phone obey instructions like open an app, click a button etc. Will add more when I have time.

Swyped on my Htc Desire running on Supernova Extreme - Gingerbread goodness with 2 GB of Internal memory
 
  • Like
Reactions: tanddhusa

Top Liked Posts

  • There are no posts matching your filters.
  • 121
    TUTORIAL - EVERYTHING ABOUT ADB - Fully Illustrated
    adb1.jpg


    This will be part of a series of Tutorials compiled to better educate the Beginner-Intermediate users in XDA thread, and help them get rid of the "n00b" or "newbie" tag thrown at them! ;)



    1. WHAT IS ADB?

    ADB or Android Debug Bridge is a command line program which is used to communicate with your Android phone (or an emulator used by programmers). The use of Adb for Android phone users ranges from using it as a tool to get the logcat- A realtime log of the Android system, which allows one to know the cause of any errors. It is very helpful to app hackers to know exctly what block of code does what, and to modify apps accordingly

    2. HOW TO USE ADB - Running adb.exe

    adb.exe is part of a package of tools called Android SDK or Software Development Kit. For users, the main applications useful for them are adb.exe, fastboot.exe and aapt.exe.

    2.1 Installing adb.exe (Windows)


    1. First, download the Android SDK package(exe file) from here The installer will prompt you to download and install the JDK (Java Development Kit) if you dont have it already installed
    2. Next install the exe file and note the location where you install it to.
    3. After install is over, use Windows explorer and navigate to the folder where you installed the SDK.
    4. Double-click the SDK Manager.exe/SDK Setup.exe file at the root of the Android SDK directory.
    5. This will open up the SDK Installation window, where you can choose from a list of packages to install
    6. If you want to use only adb.exe and fastboot.exe, choose to install only the "Android SDK Tools" from the list (See fig 1 below)
    7. That's it, adb.exe is now installed


    Fig1:
    sdk_manager_packages.jpg


    Take a note of where you install it. It usually installs to a folder named Android-sdk-windows. Once you have it installed, you can copy the entire folder on a portable usb key/CD and use it on any other PC without a need to install it. I recommend that you make it a part of your Android CD (with rooting tools, unrooting tools, gold card etc).

    2.2 Using adb.exe-Preparing your PC for running adb.exe quickly

    Adding Adb to your Windows Path
    Once installed, you should add the location of adb.exe to the* Windows Environment Path variable. To do that, go the subfolder of Android-sdk-windows where adb.exe can be found. Click on the Windows Explorer path displayed on Top, and copy the path to the Clipboard

    0.jpg


    Go to Start Menu, and Right click Computer, Choose Properties

    1.jpg


    Choose Advanced System Settings and then Environment variables

    2.jpg


    Now, add the Location you copied to the Clipboard earlier, to the end of the current path, after adding a ";"(without the quotes) to the end of the current path.

    3.jpg


    So, in my case, the current path shows:
    c:\droidzone\windows; c:\droidzone\blahblah

    It now becomes:
    c:\droidzone\windows; c:\droidzone\blahblah;C:\Software\Phone\android-sdk-windows\tools

    Hit Enter to everything.

    From now, whenever you open a Command prompt in Windows, you will be able to execute Adb and Fastboot from there without needing to navigate to the folder where they are installed.


    Next step: Elementary Adb commands

    Don't forget to Hit the Thanks button to let me know that my posts helped you!
    110
    Elementary Adb commands

    Ok, now that you've got adb all setup and prepared your computer to use it, you're ready to learn some basic adb commands. I'll be teaching some of them in this section.


    Understanding how adb and the shell works


    Let's first check if adb is working by asking it to communicate with our phone. Connect the phone with a usb cable to the PC. Note that you should have installed the HTC drivers already (They come with HTC Sync)

    From your Windows Start Menu, Click on Run, then type the following and press enter. That should open a command shell:

    Code:
    cmd
    5.jpg


    Once there, type out the following:

    Code:
    adb devices
    This will display a list showing the connected phones with their serial numbers (and emulators-But let us not worry about what these are, right now)

    6.jpg


    Great, now we have confirmation that adb is working! We're now ready to issue our basic commands.

    First thing to note is the basic command to enter the Android custom linux shell. Like Windows has cmd.exe to enter the dos shell, the graphical eyecandy with Sense overlay that you see on your device has a custom linux kernel running, so basically the language of its shell is the Linux shell language.

    Accessing the Linux terminal (adb shell) is what we do to issue commands. To enter the shell of our device, the basic command is:

    Code:
    adb shell
    Immediately, you will get a prompt like this:
    Code:
    sh-3.2#
    Now we can type out any (most) linux commands and these will be executed in our device.

    The file system on Android is laid out over MTD partitions in your device's NAND (Internal memory), and the SD card. The Nand is strictly organized in a Linux system with Linux file permissions and ownership rights (Just know that these exist, for now)

    So, right now, you will be dropped in the "root" of the filesystem, from where you can navigate to other places.

    Note! An important difference between Linux and Windows is that while Windows uses the Backslash (\), Linux/Android uses the forward slash (/) to depict directory hierarchies. Another one you shouldnt forget is that in Linux/Android, a file named boot.img is different from Boot.img, BOOT.IMG and BoOt.img, while on Windows, they are all the same.


    My tutorial is about adb commands, and not linux, so I'll give only a short summary of elementary linux commands below. I will expand the list and explanation for this at a later date if you require it:
    pwd-Shows the current working directory
    cp-copy a file
    mv-move a file (copy a file and then delete the original file)
    chmod-set file permissions
    chown-set file ownerships
    rm-delete a file
    cd-change directory
    rmdir-delete a directory

    Elementary Adb commands


    Installing applications with adb
    You can install any apk from your PC to the phone very easily. Open a cmd shell, and then type in:
    Code:
    adb install
    followed by a space. Now drag an apk file in Windows explorer to the shell we have opened. Immediately, the path of the file becomes inserted in our prompt that it becomes:

    Code:
    adb install C:\Desktop\TitaniumBackup.apk
    assuming that the file TitaniumBackup.apk was present in the location C:\Desktop. Hit enter and you will notice that it gets installed.

    Transferring files to the sdcard without connecting the device as Disk drive:

    Code:
    adb push C:\Desktop\TitaniumBackup.apk /sdcard/
    will trasfer the file C:\Desktop\TitaniumBackup.apk to the root (main) directory of your sdcard. Likewise, you can transfer any file from the PC to any location on your device.

    Eg: I want to transfer a file called wallpaper.zip to a location /data/local. The command would be:

    Code:
    adb push C:\Desktop\wallpaper.zip /data/local/
    Contd..

    Don't forget to Hit the Thanks button to let me know that my posts helped you!
    56
    Getting an adb logcat

    Many a time, you might have heard people telling you to get a logcat to report your error with a Rom installation.

    What is a logcat?

    A logcat is a report from the Android logging system, which takes place in the background the whole time your phone is on. It starts the moment you switch on the phone, and continues till you shut it down completely. This log is extremely useful for finding out what went wrong with your system. It is useful to find out why your phone is having bootloops or force closes. It is infact useful for all errors!

    How to get the logcat?
    Basically, you can view the logcat log with the following command:
    Code:
    adb logcat
    But that means getting overwhelmed by an endless haze of output flowing at a rate that you cant read and will overwhelm your command shell's capacity very soon.

    So the system we normally use is to output the log to a file from which we can read later. This is done by the following command:
    Code:
    adb logcat > log.txt
    My Technique
    As a Rom developer and apk patcher, I have to constantly check for errors in my system. So I've devised an ingenous method to easily log logcat, and view them readily. I use a combo of commands executed in succession:

    Code:
    adb kill-server
    echo "" > log.txt
    start log.txt
    adb logcat > log.txt
    These commands essentially create a blank file named log.txt in the same path as the command shell you've opened. Then, it opens the file log.txt (which is blank at this point of time. Then it logs logcat output to that file. Once you refresh the opened file, it will show the output of logcat to this point of time. Refresh it once again, and it updates once more. You should install Notepad++ and associate .txt files with it, to get best results.

    Instead of executing these four commands, you can download the batch file getlog.cmd and extract it from the zip file to the folder containing adb.exe. Once you type in the following command (from anywhere in Windows), you will achieve the same result as typing the four commands as above! Ingenious, eh? :D

    Don't forget to Hit the Thanks button to let me know that my posts helped you!

    53
    More elementary adb commands:

    Getting a file from your phone to your PC:

    To get a file /system/etc/init.d/01data to your PC, you would type out the following:

    Code:
    adb pull /system/etc/init.d/01data
    which will transfer the spcified file to the location on your pc where you have opened the cmd.exe shell.

    Mounting the system partition as Read Write to transfer files to your /system partition:

    Method 1:

    Code:
    adb remount
    Method 2:
    This can also be accomplished with the more advanced mount command in the adb shell. First we need to know the mount point of the partitions.

    Type:
    Code:
    adb shell
    mount
    For me, it displays:
    Code:
    rootfs / rootfs rw,relatime 0 0
    tmpfs /dev tmpfs rw,relatime,mode=755 0 0
    devpts /dev/pts devpts rw,relatime,mode=600 0 0
    proc /proc proc rw,relatime 0 0
    sysfs /sys sysfs rw,relatime 0 0
    /sys/kernel/debug /sys/kernel/debug debugfs rw,relatime 0 0
    none /acct cgroup rw,relatime,cpuacct 0 0
    tmpfs /mnt/asec tmpfs rw,relatime,mode=755,gid=1000 0 0
    tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0
    tmpfs /app-cache tmpfs rw,relatime,size=8192k,mode=755,gid=1000 0 0
    none /dev/cpuctl cgroup rw,relatime,cpu 0 0
    [B]/dev/block/mtdblock3 /system yaffs2 ro,relatime 0 0[/B]
    /dev/block/mtdblock4 /cache yaffs2 rw,nosuid,nodev,relatime 0 0
    /dev/block/mtdblock5 /system/data yaffs2 rw,nosuid,nodev,noatime,nodiratime 0 0
    /dev/block/mmcblk0p2 /data ext4 rw,nosuid,nodev,noatime,nodiratime,commit=50,bar
    rier=0,stripe=64,data=ordered,noauto_da_alloc 0 0
    /dev/block/vold/179:1 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,u
    id=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset
    =iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
    /dev/block/vold/179:1 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,relat
    ime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,ioch
    arset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
    tmpfs /mnt/sdcard/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0
    sh-3.2#
    Note that the entry for system partition shows:
    /dev/block/mtdblock3 /system yaffs2 ro,relatime 0 0

    The ro means that /system is mounted as RO-i.e Read Only. The whole line means that the Nand MTD block device on /dev/block/mtdblock3 is mounted on the mount point /system, to use technical jargon.

    We need to mount it as RW (Read Write)
    The command is:
    Code:
    mount -o rw,remount /dev/block/mtdblock3 /system
    This essentially mounts the /system as Read Write so that you can write to it (Normally you cant write to the /system partition), which is what "adb remount " also does. However the commands above can be executed from a Terminal Emulator application too.

    Next: Getting an Adb logcat

    Don't forget to Hit the Thanks button to let me know that my posts helped you!
    35
    Summary of other adb commands

    The following is the partial list of commands supported by adb. You can obtain this list by the following command:

    Code:
    adb /?
    Code:
    C:\Users>adb /?
    Android Debug Bridge version 1.0.26
    
     -d                            - directs command to the only connected USB devic
    e
                                     returns an error if more than one USB device is
     present.
     -e                            - directs command to the only running emulator.
                                     returns an error if more than one emulator is r
    unning.
     -s <serial number>            - directs command to the USB device or emulator w
    ith
                                     the given serial number. Overrides ANDROID_SERI
    AL
                                     environment variable.
     -p <product name or path>     - simple product name like 'sooner', or
                                     a relative/absolute path to a product
                                     out directory like 'out/target/product/sooner'.
    
                                     If -p is not specified, the ANDROID_PRODUCT_OUT
    
                                     environment variable is used, which must
                                     be an absolute path.
     devices                       - list all connected devices
     connect <host>:<port>         - connect to a device via TCP/IP
     disconnect <host>:<port>      - disconnect from a TCP/IP device
    
    device commands:
      adb push <local> <remote>    - copy file/dir to device
      adb pull <remote> [<local>]  - copy file/dir from device
      adb sync [ <directory> ]     - copy host->device only if changed
                                     (see 'adb help all')
      adb shell                    - run remote shell interactively
      adb shell <command>          - run remote shell command
      adb emu <command>            - run emulator console command
      adb logcat [ <filter-spec> ] - View device log
      adb forward <local> <remote> - forward socket connections
                                     forward specs are one of:
                                       tcp:<port>
                                       localabstract:<unix domain socket name>
                                       localreserved:<unix domain socket name>
                                       localfilesystem:<unix domain socket name>
                                       dev:<character device name>
                                       jdwp:<process pid> (remote only)
      adb jdwp                     - list PIDs of processes hosting a JDWP transport
    
      adb install [-l] [-r] [-s] <file> - push this package file to the device and i
    nstall it
                                     ('-l' means forward-lock the app)
                                     ('-r' means reinstall the app, keeping its data
    )
                                     ('-s' means install on SD card instead of inter
    nal storage)
      adb uninstall [-k] <package> - remove this app package from the device
                                     ('-k' means keep the data and cache directories
    )
      adb bugreport                - return all information from the device
                                     that should be included in a bug report.
    
      adb help                     - show this help message
      adb version                  - show version num
    
    DATAOPTS:
     (no option)                   - don't touch the data partition
      -w                           - wipe the data partition
      -d                           - flash the data partition
    
    scripting:
      adb wait-for-device          - block until device is online
      adb start-server             - ensure that there is a server running
      adb kill-server              - kill the server if it is running
      adb get-state                - prints: offline | bootloader | device
      adb get-serialno             - prints: <serial-number>
      adb status-window            - continuously print device status for a specifie
    d device
      adb remount                  - remounts the /system partition on the device re
    ad-write
      adb reboot [bootloader|recovery] - reboots the device, optionally into the boo
    tloader or recovery program
      adb reboot-bootloader        - reboots the device into the bootloader
      adb root                     - restarts the adbd daemon with root permissions
      adb usb                      - restarts the adbd daemon listening on USB
      adb tcpip <port>             - restarts the adbd daemon listening on TCP on th
    e specified port
    networking:
      adb ppp <tty> [parameters]   - Run PPP over USB.
     Note: you should not automatically start a PPP connection.
     <tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
     [parameters] - Eg. defaultroute debug dump local notty usepeerdns
    
    adb sync notes: adb sync [ <directory> ]
      <localdir> can be interpreted in several ways:
    
      - If <directory> is not specified, both /system and /data partitions will be u
    pdated.
    
      - If it is "system" or "data", only the corresponding partition
        is updated.
    I will add notes for these if you require them.