Results 1 to 6 of 6
Like Tree2Likes
  • 2 Post By voku1987

Thread: [HowTo] Android Debug Bridge (adb)

777
  1. [translate]    #1
    Senior Member
    Join Date
    May 2010
    Location
    /dev/null
    Posts
    1,704

    Default [HowTo] Android Debug Bridge (adb)

    If someone finds a mistake, please notify me by PM and I will correct it.

    PLEASE NOTE THAT I AM NOT RESPONSIBLE FOR YOU MESSING UP YOUR PHONE!

    Introduction
    The Linux terminal is a commandline interface that you can use for all types of operation on the Android OS. Alot of users are afraid to use it because it 's not a GUI, and to be honest, if you don't know the basics it's pretty hard to learn by yourself. - http://developer.android.com/guide/d...tools/adb.html

    Why is this useful? So you do not have to rely on apps like Root Explorer/Astro File Manager/Estrongs File Explorer/etc... for some operations.

    In this tutorial I will get you started with the basics of the terminal in a way everyone can understand.

    1. Preparation
    First, we must look at the Android-SDK -> download and install or you can also use the "Terminal Emulator"-App to access to the Android-Shell but you can clearly work better with a keyboard (PC) on the shell.

    1.1) Drivers
    If you have never connected your phone to your PC, you may need to also install the drivers.


    “Windows XP” -> “SAMSUNG New PC Studio”

    “Windows 7” -> “SAMSUNG Kies“

    ... here you can also find the drivers for Spica -> Samsung USB Drivers


    1.2) Installation
    first extract "android-sdk*.zip" and we copy "android-sdk-windows" to C: and run the included "SDK Manager.exe".


    1.3) activate USB Debug
    Enable USB debug on the phone ...
    Settings – Application – Development: „USB-Debugging“
    ... and then connect your Android to your PC via USB.


    2.) ADB-Commands
    Now start the Windows command line ...

    ... and can now run the following commands.

    # change in folgndes Directory
    Code:
    cd C:\android-sdk-windows\platform-tools
    # display ADB-Help
    Code:
    adb -h
    # shows the connected Android devices
    Code:
    adb devices
    # Android will be re-launched
    Code:
    adb reboot
    # Android will be started in recovery mode
    Code:
    adb reboot recovery
    # start the Android-shell
    Code:
    adb [-s ] shell
    # show the Android-Logfile
    Code:
    adb logcat
    V —> Verbose (lowest priority)
    D —> Debug
    I —> Info
    W —> Warning
    E —> Error
    F —> Fatal
    S —> Silent (highest priority, on which nothing is ever printed)

    # e.g. Error messages
    Code:
    adb logcat *:E
    radio —> View the buffer that contains radio/telephony related messages.
    events —> View the buffer containing events-related messages.
    main —> View the main log buffer (default)

    # e.g. all event messages
    Code:
    adb logcat -b events
    # installed an app from your PC
    Code:
    adb install \
    # Upload a file from your computer (local file) to mobile
    Code:
    adb push
    # Download a file from phone to your PC
    Code:
    adb pull
    e.g.: screenshots with a 24BPP kernel (download from here)
    Code:
    adb pull /dev/graphics/fb0 fb0
    ffmpeg -vframes 1 -vcodec rawvideo -f rawvideo -pix_fmt rgb32 -s 320x480 -i fb0 -f image2 -vcodec png image.png
    # a TCP port of Android directly connect to a TCP port of our operating system
    Code:
    adb forward tcp:5901 tcp:5901
    In the CyanogenMod - wiki, there are other useful commands:ADB - CyanogenMod Wiki


    --- The following commands are executed in the "adb shell" ---


    In this case, most of the following commands can be used in other Linux systems ...


    # displays the log file
    Code:
    logcat
    # shows on the kernel debug info
    Code:
    dmesg
    # shows the system apps (ls = dir in Windows)
    Code:
    ls /system/app/
    # shows the installed apps
    Code:
    ls /data/app/
    # displays data on your SD card
    Code:
    ls /mnt/sdcard/
    # displays the contents of a file or copy it :-)
    Code:
    cat lall.txt
    cat lall.txt > lall_copy.txt
    # shows who you are ;-)
    Code:
    whoami
    # displays the running processes
    Code:
    ps
    # shows the system utilization
    Code:
    top | tail
    # shows all mounted partitions
    Code:
    mount
    # grep filters e.g. Expenditure
    Code:
    mount | grep system
    # root privileges (su = substitute user)
    Code:
    su
    # partitions can now be described
    Code:
    remount rw
    # e.g. the partition /system may now be written (read & write)
    Code:
    remount rw /system
    # the partition /system may no longer be written (read only)
    Code:
    remount ro /system
    # e.g. deletes a system app (rm = del in Windows)
    Code:
    rm /system/app/
    # deletes an installed app
    Code:
    rm /data/app/

    3.) Basic operations
    2.1. File Paths
    2.1.1 Absolute paths

    Absolute paths work everywhere, from every folder. They always start with "/", which is the root (the start). On android, then you have some subfolders like "system", "data" and "sdcard" (which is the sdcard).
    An example of an absolute path would be /sdcard/videos (the folder videos on your sdcard)

    2.1.2 Relative paths
    Relative paths are relative to your position as the name would suggest.
    If you currently are in the /sdcard folder, you can just switch to the videos directory by using the command:

    Code:
    cd videos
    2.2 File operations

    There are several commands for file operations. They will be explained in the next section. Please note that removing important system files may harm your system. If you're not 100% sure, don't try it before you are!

    2.2.1 Copy a file/folder
    Type:

    Code:
    cp [source file/folder] [target file/folder]
    Examples:
    Code:
    cp /sdcard/bootanimation.zip /system/media/bootanimation.zip
    will copy bootanimation.zip from the sdcard to the folder where it is loaded at boot. It will overwrite the current bootanimation.zip in that folder.
    You could also type:
    Code:
    cp /sdcard/bootanimation.zip /system/media/
    for the same effect.

    Another example:
    Code:
    cp /sdcard/fonts/segoeui.ttf /system/fonts/DroidSans.ttf
    will replace the default android font with segoeui, and rename segoeui.ttf to DroidSans.ttf so Android recognises it. Note that this can also be used to simply rename files by copying itself to itself

    2.2.2 Move a file/folder
    Type:

    Code:
    mv [source file/folder] [target file/folder]
    This works the same as cp, except that it will move a file instead of copy it.

    2.2.3 Remove a file/folder
    Type:

    Code:
    rm [file/folder]
    Example:
    Code:
    rm /system/app/twitter.apk
    This will remove the built-in twitter app from your system ROM.

    2.3 Navigation through folders
    Another basic of terminal usage

    2.3.1 Changing Directories
    You can easily change directory by using the cd command.
    Once you are in a directory can access files and folder relatively

    To change a folder type:

    Code:
    cd [absolute or relative folderpath]
    Example:
    Code:
    cd /system
    will navigate to /system

    2.3.2 List the contents of a directory
    To see what's in a directory type or see the file information:

    Code:
    ls [directory/file]
    OR while being in the directory type:

    Code:
    ls
    Example:
    Code:
    cd /sdcard/videos
    ls
    will navigate to /sdcard/videos and show what's inside it.

    2.4 File Permissions
    Once in a while permissions of files get corrupted. It does not happen alot, but sometimes it is necessary to correct them.

    First you need to know how permissions work in Linux.
    It works with 3 numbers: xyz

    x is what the owner can do
    y is the permission for the public user
    z is what other users can do (public)

    x,y and z can have different values:

    7 full (read, write, execute)
    6 read and write
    5 read and execute
    4 read only
    3 write and execute
    2 write only
    1 execute only
    0 none

    To set the permissions on a file type

    Code:
    chmod xyz [file]
    Example:
    Code:
    chmod 777 /system/fonts/segoeui.ttf
    will make the segoeui.ttf file fully accessible by all users.

    To check the currenct permissions of a file use the -l parameter of ls, example:

    Code:
    ls -l /sdcard/update.zip
    will return the permissions and extra file info on the file.

    2.5 Android Properties
    A nice and fast way to see some android properties is Getprop. Just type:

    Code:
    getprop
    and scroll through all the settings available in the .prop files aswell as running services.

    You can manually set these settings with the setprop command.

    Example:
    Code:
    setprop ro.modversion bananas
    will set the Android version info to "bananas".

    BE VERY, VERY CAREFUL WITH SETPROP, IF YOU SET SOMETHING WRONG IT MIGHT RUIN YOUR INSTALLATION AND EAT ALL YOUR COOKIES!

    2.6 Writing output from a command to a file or the screen
    For this echo is very useful. You use echo in this way

    Code:
    echo bananas
    will return a line that says bananas

    Now that itself is not very useful but combined with > it can send your text to a file.

    Example:
    Code:
    echo bananas > /sdcard/bananas.txt
    will make a txt file on your sdcard with bananas as content. Still not useful enough?

    Try this:
    Code:
    echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    This will set your CPU scaling_governor to performance (always 800Mhz). Note that this is not a recommended setting as it will wear your CPU out quickly and eat battery like the cookiemonster would eat... well cookies :P

    Set it on ondemand using the same command:
    Code:
    echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    Good to know: Apps like SSSCFG set your scaling governor dynamically according to the state of your screen. It probably uses a similar script to set the governor (not 100% sure about this).

    You can also write output from a command to a file with >

    Example:
    Code:
    logcat > /sdcard/logcat.txt
    will do a logcat and write it to a txt file on your SD card (useful for debugging problems)




    NOTES:
    * Commands and folders are CASE-SENSITIVE
    * If a command completed succesfully, it will say nothing and start a new line.
    * When you see a file does not have the correct permissions, start with giving it 777 to see if that's your problem. If you want you can make the permissions more strict later on.



    ... Since I have the "CyanogenMod" installed for me, I want many more programs such as an SSH-server (dropbear), wget ... available, the commands shown here should work even without this mod.

    Last edited by voku1987; 05-06-2011 at 02:50 PM. Reason: update ... thx @minus30
    kenjimovic and Baenajose like this.

  2. [translate]    #2
    Senior Member
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    2,839

    Default

    There is no need to install NPCS or KIES- drivers are aviable separately, download links are in 'Usb drivers' thread

    Sent from my GT-I5700 using Tapatalk
    Code:
    setprop persist.world.domination 1

  3. [translate]    #3
    Senior Member
    Join Date
    May 2010
    Location
    /dev/null
    Posts
    1,704

    Default

    Quote Originally Posted by darth_llamah View Post
    There is no need to install NPCS or KIES- drivers are aviable separately, download links are in 'Usb drivers' thread

    Sent from my GT-I5700 using Tapatalk
    ... thread-link to the 'Usb drivers' added!

  4. [translate]    #4
    Senior Member
    Join Date
    Mar 2010
    Location
    Belgium
    Posts
    233

    Default

    You know, the day before you posted this I just typed up a complete terminal-for-rookies guide for Android :P
    I won't post it now since yours is better but I'll make some suggestions and PM you my guide. Maybe you can merge them or something ;-)

    Suggestion for now is to add chmod usage to fix permissions and writing data to a file using ">". PM with my guide sent

  5. [translate]    #5
    Junior Member
    Join Date
    Mar 2011
    Location
    Scotland
    Posts
    11

    Default

    cool

  6. [translate]    #6
    Junior Member
    Join Date
    Dec 2011
    Location
    Phonix
    Posts
    8

    Default

    Thanks a lot..its useful

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •