Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,741,305 Members 42,405 Now Online
XDA Developers Android and Mobile Development Forum
View Poll Results: HOWS THE GUIDE
100% BETTER THAN OTHER GUIDE'S 16 94.12%
DIDN'T UNDERSTAND A THING 1 5.88%
Voters: 17. You may not vote on this poll

[WIN][TUTORIAL]HOW TO USE ADB,DDMS AND TAKE A LOGCAT {pictorial explanation}

Tip us?
 
Powerhouse
Old
(Last edited by Powerhouse; 16th January 2014 at 02:31 AM.)
#1  
Powerhouse's Avatar
Senior Member - OP
Thanks Meter 1966
Posts: 795
Join Date: Mar 2013
Default [WIN][TUTORIAL]HOW TO USE ADB,DDMS AND TAKE A LOGCAT {pictorial explanation}

Quote:
EXPLANATION
Quote:
Whenever you create an android app or when you develop an Rom , it is important that you must deliver GOOD QUALITY APP or ROM , that are rid of Bugs ..Eventually you might come across a situation when your APP or ROM isn't working or it is bricking the device or some things are not working .These situation can be tackled only with a proper debugging tools ..So ADB ( android debug bridge) is a powerful Debugging tool and a tool which allows us to step through each line of code and examine the value of each variable.It offers us some of the powerful tools ..Debugging is not a big deal for the people who come from a JAVA programming background .Dalvik VM in android supports java debug wire protocol to attach to the device over ADB
Quote:
ADB

ADB or ANDROID DEBUG BRIDGE is a command-line utility that is often used to communicate over the debug channel with a connected phone or virtual device (emulator). ADB can control your device over USB from a computer, copy files back and forth, install and uninstall apps, run shell commands, and more...
SETTING UP ADB :-


Quote:
Quote:
1) Install Java JDK :-
Before installing the Android SDK, you’ll have to install Oracle’s Java development kit. You can download it from here...(click me !!)

Even if you already have the Java runtime (JRE) installed, you’ll need to install the JDK as well.


After installing Java JDK , you can now download the Android SDK from Google .
NOTE:- If you see a any type of Java-related error during installation, then download and install the x86 version of the JDK, not the x64 one ..
Quote:
2) Installing android SDK:-

Download Android SDK from here...(click me !!!)

After clicking on "DOWNLOAD FOR OTHER PLATFORMS" , you will get an extended menu ..




After downloading the .exe file , then Double click on the .exe file and install it in C:\ Drive or on whichever drive you wanna install .


Quote:
Quote:
3) Android SDK Setup
Quote:
Once the Android SDK is downloaded and installed, launch the SDK Manager application from your Start menu.



Enable the Android SDK tools and SDK Platform-tools checkbox and click the Install button. This downloads and installs the platform-tools package, which contains ADB and other utilities.



After installing these packages , Go to the place where you installed ANDROID SDK . IN MY CASE , IT IS :-
Code:
Select Code
C:\Program files(x86)l\Android\android-sdk\platform-tools
If you used a different install location, you’ll find ADB in the platform-tools directory,inside your ANDROID-SDK directory .



Browse to platform tools and hold Shift and right-click inside it, and select Open command window here...


Quote:
Quote:
NOW YOU WILL SEE THIS :-



Note :- To use ADB with your Android device
Quote:
Quote:
1) you must enable USB debugging on it. You’ll find this option under Developer Options on your device’s Settings screen



Quote:
2)You must install your device drivers :- Individual OEM USB drivers for windows are available for each manufacturer and are listed in the official document ..
After you have downloaded you device drivers, then we have to install on our pc. for that :-

a) connect the device to the computer
b) right click on MY COMPUTER and click manage
c) go to devices > other devices and right click on device and select update driver software.
d) you should see an option to " BROWSE MY COMPUTER FOR DRIVER SOFTWARE" , which you nedd to click on and point to the location of your device driver installation file..


To test whether ADB is working properly, connect your Android device to your computer using a USB cable and run the following command:
Code:
Select Code
adb devices
Now it will show the devices connected



Now you have sucessfully installed ADB and now we are good to go further..

WHAT IS A LOGCAT :-


Logcat is the command to view the internal logs of the Android system. Viewing logs is often the best way to diagnose a problem, and is required for many issues. This way you'll find out what apps are doing in the background without you noticing.


TAKING AN LOGCAT :-

Now type this in the terminal
Code:
Select Code
adb logcat -v long > logcat.txt
or

Code:
Select Code
Code:
adb logcat > logcat.txt
you shall have a log file called name of logcat.txt inside your ADB folder.

Quote:
SOME OF THE USEFULL ADB COMMANDS :-

Quote:
Code:
Select Code
adb install C:\package.apk
– Installs the package located at C:\package.apk on your computer on your device.
EG -adb install G:\xda.apk
Quote:
Code:
Select Code
adb uninstall package.name
– Uninstalls the package with package.name from your device.
EG :- you’d use the name com.quoordy.xdadevelopers to uninstall the Xda developers app.
Quote:
Code:
Select Code
adb push C:\file /sdcard/file
– Pushes a file from your computer to your device. the command here pushes the file located at C:\file on your computer to /sdcard/file on your device .
EG :-adb push G:\system\framework\framework-res.apk /system/framework
Quote:
Code:
Select Code
adb pull /sdcard/file C:\file
– Pulls a file from your device to your computer – works like adb push, but in reverse. EG :-adb pull /system/app G:\rom\system\app\
Quote:
Code:
Select Code
adb logcat
– View your Android device’s log. Can be useful for debugging apps.
Quote:
Code:
Select Code
adb shell
– Gives you an interactive Linux command-line shell on your device.
Quote:
Code:
Select Code
adb shell command
– Runs the specified shell command on your device.
Quote:
Originally Posted by doctor_droid View Post

When you guys are experimenting on a custom rom (i.e. nightlies, betas, RC's, "just cooked", etc.), it's very likely that your phone might not boot correctly, fear not and instead, try using ADB there are loads of guides regarding how to properly set-up your PC for using ADB, starting by the Android SDK's page itself :P lol

Now, to do the said logcat, open a command window and do:

C:\Users\Dark> cd \\sdk\platform-tools [Hit ENTER!]

C:\\sdk\plarform-tools> adb.exe devices (just to make sure your computer detected your phone lol)

C:\\sdk\plarform-tools> adb.exe logcat -v long > somefile.txt (the "-v long" part creates a nicely formatted file )

That's it!! Remember to zip the file if it's too big

Another tip: Some phones are very catchy when under heavy issues (like mine ) in those cases, timing is essential between rebooting and getting your log, however!!! The adb logcat command makes sure to wait for the device to get detected
The Following 115 Users Say Thank You to Powerhouse For This Useful Post: [ Click to Expand ]
 
Powerhouse
Old
#2  
Powerhouse's Avatar
Senior Member - OP
Thanks Meter 1966
Posts: 795
Join Date: Mar 2013
Default DDMS

The Dalvik Debug Monitor Service (DDMS) as it is known is one of the application debugging tools that must be a part of every ANDROID app developers's toolkit..This is very very useful to the app developers.Its is a very powerful debugging tool environment and offers various unparalleled debugging features like heap information , logcat monitoring , file manager.It is available by default in ECLIPSE IDE environment or even in the ANDROID SDK.It works on top of ADB for device communication..
DDMS can be stated as a standalone application as part of ANDROID DEVICE MONITOR.The Android Device Monitor is a standalone which can be used in case you do not use the eclipse development environment , though the integration with Eclipse is something that other IDE'S could be envious of.
HOW TO USE DDMS ??
1)AS EXPLAINED IN THE ABOVE POST , INSTALL ANDROID SDK....AFTER YOU HAVE INSTALLED PLATFORM-TOOLS & SDK TOOLS..NOW GO TO ANDROID FOLDER AND OPEN TOOLS



2)NOW RUN MONITOR.bat AS ADMINISTRATOR





3)NOW ANDROID DEBUG MONITOR WILL APPEAR ..

Now let's learn about its components and it's use's

DDMS VIEW COMPONENT'S :-

DDMS offers a set of view components , each of which show relevant information related to the connected Emulator.

DEVICES :-
The device panel shows the details of each process that are running in the connected device.There are various operations that can be performed from this panel.



Each of the icons present in this panel performs the functions as follow's :
  • Debug Process Icon :- It show's the state of connection of the debugger.
  • Update Heap :-Clicking on this enables Heap information for the process so that we do not have to do memory deallocation manually.
  • Dump HPROF :- Generates a Heap Dump , useful for tracing memory leaks in your app.
  • Cause GC :-Invokes the Garbage collector to collect heap data.
  • Update thread :-Show's the information about the running thread in the thread tad for selected process
  • Start Method Profiling :- Tracks the metric's related a method. It collects information like the amount of time taken to execute a method,number of calls.
  • Stop Process :-Stops the currently selected process.
  • Screen Capture :- Takes a screenshot of whatever is displayed on the screen.
  • Reset ADB :- Ast he name suggets,it resets ADB.


THREAD'S :-
The thread tab on the right of devices view shows informatiom related to the thread for each process selected in the devices view.The information shown can described as follows.
  • ID :- A unique ID assigned to each thread dby Dalvik V,, which are only odd numbers that start from 3 .
  • Tid :-The linux thread associated with each thread , ehich matches the process ID for each main thread in a process.
  • Status :- Status of the thread in VM , out of daemons are marked with an asterix.other values can be among running?sleeping/init/starting.
HEAP
:-
the heap view show a information and statistics about memory heap .To view heap usage,follow these below steps
  1. From the devices view,select the process for heap usage which has to be examined.
  2. click on update heap
  3. From heap Tab , select Cause GC to enable collecting heap data
Everytime you need to update your heap statistics.This will show you the amount of memory allocated to each

ALLOCATION TRACKER

The allocation Tracker show a real time information about allocation happening in the application over a certain period of time.To enable allocation Tracking.
  1. select the process to be tracked from device panel
  2. click on start tracking from allocation tracker tab.
  3. perform any actions on the devices or emulator that you want to be tracked.
  4. click on Get Allocations objects, since tracking was enabled .


NETWORK STATISTICS
;-
The network tab allows you to track and optimize the amount of network data your app is using.It even allows you to tag network sockets so that you can differentiate between types of data .It will indicate the speed and amount of data received /transmitted ..

EMULATOR CONTROL :-
One problem with testing Android devices using an emulator or developer device is the fact that it is unable to examine the performance of the app in the reak world conditions . like call or SMS is received/sent or when a particular location is reached.To be specific the emulator Tab allows you to to emulate the following real world conditions :
Telephony Status :- the following options are available to set the status of phones network.
  • Voice :- unregistered,home,roaming,searching,denied.
  • Data :- unregistered,home,roaming,searching,denied.
  • Speed :- Full,GSM,HSCSD,GPRS,EDGE,UMTS,HSDPA.
  • Latency :- GPRS,UMTS
  • Telephony Actions :- Telephony actions allow you to spoof the network.
  • Location Settings ;- Emulator control allows you to sppof the location

FILE EXPLORER :-

As the name says it lets you view the directory and file structure if the device and lso easily copy files to and from the emulator so as to enable easy data transfer in a manner similiar to ADB or ADB pull command.
SYSTEM INFORMATION :-

As the name says , it give's us the particular information about the GPU load , CPU load....
DDMS HAS ALSO AN INBUILT LOGCAT VIEWER :-
Happy Developing and learning



CREDITS ;-
Google inc.
@iamareebjamal
@Nabs Zains
@amogh420
@srt99
@Maxx247
@iamareebjamal
@El_Dark
@doctor_droid
@CharsiBabu
@lokeshsaini94
@hellraiser
@Zeuscluts
@Partimus.prime
@Lifehacker7


if i forgot you , just PM me .. i will be very glad to add it ..
The Following 11 Users Say Thank You to Powerhouse For This Useful Post: [ Click to Expand ]
 
Powerhouse
Old
(Last edited by poyensa; 30th November 2013 at 05:51 PM.)
#3  
Powerhouse's Avatar
Senior Member - OP
Thanks Meter 1966
Posts: 795
Join Date: Mar 2013
WIRELESS ADB

1. ROOT IS NECESSARY !!
2. Enable USB debugging.
3. Install Wireless ADB from the play store
4. Activate it .
5. In your computer, open a command line (cmd.exe for windows), go to ADB's directory and type:
Code:
Select Code
adb connect 192.168.0.3:5555
Keep in mind that the port (the :5555 part) is optional, the 5555 is the default one, usually you don't need to change it, unless you're using it
6. That's it ..!!

credits: @El_Dark


FAQ TO BE ADDED SOON .....
The Following 58 Users Say Thank You to Powerhouse For This Useful Post: [ Click to Expand ]
 
Powerhouse
Old
(Last edited by Powerhouse; 28th December 2013 at 09:23 AM.)
#4  
Powerhouse's Avatar
Senior Member - OP
Thanks Meter 1966
Posts: 795
Join Date: Mar 2013
How to Remount system partition as R/W

Go into Platform tools which can be found in your Android folder..


Hold shift button and right click ..Select "open cmd window here" in the pop-up window ...

first type

Code:
Select Code
adb shell
Get Root Privileges ..

Code:
Select Code
su
then type
Code:
Select Code
mount grep system
and then you'll get


Code:
Select Code
mount grep system
Usage: mount [-r] [-w] [-o options] [-t type] device directory
Here fill the above command with neccesary system partition,appropriate device path and mount point ..Like

Code:
Select Code
mount -o rw,remount -t yaffs /dev/block/stl12 /system

This is how it looks :

 
Code:
Select Code
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb shell
adb server is out of date.  killing...
* daemon started successfully *
$ su
su
# mount grep system
mount grep system
Usage: mount [-r] [-w] [-o options] [-t type] device directory
#
The Following 2 Users Say Thank You to Powerhouse For This Useful Post: [ Click to Expand ]
 
-NickHalden-
Old
#5  
-NickHalden-'s Avatar
Recognized Contributor
Thanks Meter 1845
Posts: 1,038
Join Date: Apr 2012
Location: Gotham

 
DONATE TO ME
nice one added to Guide Ride
Guide Ride-Everything you need, From a Noob to a Dev. 80+ awesome guides to help you in all your endeavors

Device hierarchy. Galaxy MINI>Xperia Tipo Dual>HTC Pico>Moto G

Agree or disagree, idgaf. Adios ! Savvy, aye?
The Following 3 Users Say Thank You to -NickHalden- For This Useful Post: [ Click to Expand ]
 
FAdrums
Old
#6  
FAdrums's Avatar
Senior Member
Thanks Meter 881
Posts: 2,646
Join Date: Apr 2012
Excellent guide!
Device: Nexus5
Rom: Paranoid Android 4.3 Beta 6
Kernel: Franco r50
Audio: Viper 2.3.3
Recovery: TWRP 2.7.0
 
hepi_hape
Old
#7  
hepi_hape's Avatar
Senior Member
Thanks Meter 67
Posts: 459
Join Date: Mar 2013
COOL finnaly i found some tutorial
thx
 
sgt. meow
Old
#8  
sgt. meow's Avatar
Recognized Contributor
Thanks Meter 2765
Posts: 4,318
Join Date: Dec 2011
Location: Dhaka
Nice guide. But you may wanna fix the problem.txt bit in the logcat part. It should be logcat.txt.
 

https://www.dropbox.com/s/ho7noezbf3ph0l6/CrossMiranda.png
R.I.P. Miranda Nicole
An innocent soul, who deserved to live a lot longer. We all miss you.

R.I.P Alif Shahriar
A true friend, no longer here in this world, but always there in our hearts. We sorely miss you.


Owner and creator of Oxydo kernels for Nexus 7 2012 (Grouper/Tilapia) and Xperia X8 (Shakira)
Maintainer of AOSPAL for Nexus 7 2012 (Grouper).


My blog: http://alltheengsawesumz.blogspot.com/
Circle or chat: https://plus.google.com/+FayadChowdhury
 
Powerhouse
Old
(Last edited by Powerhouse; 11th October 2013 at 09:00 AM.)
#9  
Powerhouse's Avatar
Senior Member - OP
Thanks Meter 1966
Posts: 795
Join Date: Mar 2013
Thank you to you all ,for showering me with you best wishes.

Quote:
Originally Posted by sgt. meow View Post
Nice guide. But you may wanna fix the problem.txt bit in the logcat part. It should be logcat.txt.

i will edit , just a second .thnk you for you little help.
The Following 3 Users Say Thank You to Powerhouse For This Useful Post: [ Click to Expand ]
 
ai6908
Old
#10  
ai6908's Avatar
Senior Member
Thanks Meter 265
Posts: 3,603
Join Date: Nov 2006
Location: Land of Lincoln

 
DONATE TO ME
nice guide bro...very good work...
Hit "THANKS" button if you like the above post!!
Moto Atrix HD ROM - Batakang
HTC Flyer (WiFi) ROM - Stock Honeycomb3.2 No Root
My UnderVolt Tweak for cfX

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes