Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,780,205 Members 40,497 Now Online
XDA Developers Android and Mobile Development Forum
View Poll Results: How was the guide?
It was intuitive and easy to understand 312 83.65%
It was dull and boring 11 2.95%
I am color blind and it was very hard 50 13.40%
Voters: 373. You may not vote on this poll

[GUIDE][ADB]Easiest How to use adb, logcat, etc for noobs and newbies

Tip us?
 
iamareebjamal
Old
(Last edited by iamareebjamal; 27th May 2014 at 06:55 AM.)
#1  
iamareebjamal's Avatar
Recognized Contributor / Themer - OP
Thanks Meter 4,675
Posts: 3,597
Join Date: Aug 2012
Location: Batcave
Red face [GUIDE][ADB]Easiest How to use adb, logcat, etc for noobs and newbies

ADB:-

Android Debug Bridge
Very useful program made itself by Google for Programmers and developers. Its based on command line and basically communicates with your Android to respond to certain commands. There is vast amount of knowledge about adb but its most useful commands limit to getting:-

Logcat:-
A real time log of what is happening in background of our devices. It is really useful for developers to see which component has malfunctioned and helps to narrow down their search for what failed and what needs to be fixed. Several times users are asked to give logcats of their devices which are giving errors. We will go in detail that how to get logcats in every and easiest way possible.

App Installation and Management:-
adb proves really handy if you want to install apks directly from your PC or want to batch install or delete them.

Shell Execution:-
You must have heard of Terminal Emulator. It is an app for android to execute shell commands(linux commands) which are basically present as applets in /system/bin, /system/sbin or /system/xbin(in our case) folders. A very imporant applet called busybox is installed there mainly used for execution of basic commands during root browsing or ROM installation. Many times updater script of ROMs use busybox commands to install it. Well, these commands can be initiated from your device too but they can be initiated from adb also making it easy for programmers.

Pushing and Pulling:-
Most used commands of adb. adb makes it a piece of cake for new device developers to get an ideo of structure and basic knowledge of devices by pulling command. We can pull out i.e copy any files or folders from our devices to our PC, even the root directories without rooting the devices. It help rooters and ROM chefs of new devices to get an idea and implement their mods on them. Pushing is also very useful command. It copies your files and folders from PC to your device. Very useful in pushing some /system apps and other things

Remounting and setting permissions

Basic commands:-
Of-course basic commands such as rebooting and rebooting in recovery mode and download mode are supported.

Others:-
There are several other features of adb such as fastboot, aapt, etc


Setting up ADB

Pre Requirements:-

PC(This is a windows guide, if asked I will add linux and mac guide later)
Java Runtime environment or Java Developing kit
Your Device Drivers
An Android Device

USB Debugging MUST be turned ON in the device for ADB to see it & Developer options is hidden in Android 4.2 and
above, Hitting Build number 10 times in
About Phone/Tablet reveals the menu (Thanks lilHermit for reminding me to add it)



Assuming you all these ready and working properly, we continue
If you are having trouble completing Pre-Requisites, there are several guides featuring them too




Start

1. First Download Android SDK. Roughly about 70 MB

2. There may be any compressed zip file or exe file
If zip file, then extract it to C:\android-sdk
If exe file then double click on it and install it in C:\ Drive(or any other drive you want)

3. Now to get adb and other tools, you need to download
'Platform Tools'
To download them, go to the android-sdk folder and double click on SDK Manager
It will ask you which package to download? However, it is your choice which package to Download, but here, we will only talk about platform
Tools. So, simply tick on Platform Tools and click on install. Once you have done it. Go to the platform-tools folder in the directory where you installed android-sdk. You will find several files there like adb, fastboot, aapt, etc

4. Now, you can backup the whole folder of android-sdk to any external storage that will make you not download package
again if you want to. You can have it placed in any computer and run it as it does not require registry to work


5. Now, you are just one step away from using adb. Next step is
SKIPPING SETTING ENVIRONMENT VARIABLE (If you however want to set environment variables. Click on Show Content)
 
We can easily append the sdk platform-tools and tools folder to your systems environmental path variable directly from command line(cmd) by simply issuing one command and performing a system reboot:
 


Code:
SETX PATH "%PATH%;SDK_Install_Path\platform-tools;SDK_Install_Path\android-sdk-windows\tools" -m
Just replace the "SDK_Install_Path" in the above with the proper path of your SDK installation. Example: C:\android-sdk-windows

(Thanks to WugFresh for telling me )



Many guides on internet say that it is to be done for making it easy for users and if you have some basic knowledge of Command Prompt,
you will know that to execute any application with command prompt, you first need to change the directory to the one where application is
placed. And to skip changing the directories every time you open CMD, you need to put that application is environment variable. Howeve, we will not do so.


6. Type cmd in the search bar. Copy cmd.exe from there. Go to the directory where you have installed android-sdk. Go to platform-tools folder. Paste cmd there, right click on it and in the settings, select Run as Administrator.

7. You are done. Now what to do in it?



ADB Commands


Type adb in command prompt. And several commands will show up on your screen. It is very difficult to analyse these all commands, so we will only talk about most used and important commands



Connect your device via USB cable

And open the CMD in platform-tools folder(Make a shortcut of it on desktop). And type the suitable commands

Code:
adb devices

Will show the list of devices attached to the PC andtheir serial numbers. If this shows up correctly on your PC, then it means that everything is fine for continuing.


Logcat

Code:
adb logcat
It will display the real time log of your device
Best time to do it is when your device boots up
Now, many users ask me how to copy the logcat and upload it from CM
D

There are several methods:-
1. Right click on the Title Bar of Command Prompt. Hover the cursor over edit and select mark. Select all the things you want to copy and then click enter. All the things will be copied to clipboard.
2. This is the correct way of getting logcat saved.

Code:
adb logcat > logcat.txt


This command will create a logcat.txt document in platform-tools folder with the complete logcat of the device. Ofcourse you can type any name instead of logcat.txt
3. I prefer taking logcat this way as it neatly compiles logs of different time

Code:
adb logcat -v long > logcat.txt

This is a very nice way to get logcat.



Installing Apps


Code:
adb install %PATH OF APK%


This will install an app on your Android
For example, if my app AreeB.apk is in G:\ drive (G:\AreeB.apk)
Then I will type


Code:
adb install G:\AreeB.apk
Be sure your apk is not in a folder that has space in its name, else the command will break at space bar.
For eg:-


G:\Program Files\AreeB.apk

Note:
If you have spaces in path of apk, you can execute the command without breakage if you include the path inside quotes. (Thanks to etcman)
Eg:-



Code:
adb install "G:\Program Files\AreeB.apk"




Mounting

However, I never found any problem in tweaking with system files with adb, but some users said that they couldn't do it, so the problem was that their system partition was mounted as Read Only(R/O)
So, it is necessary now to tell how to mount system partition as Read Write(R/W)


Code:
adb remount
It is easiest way to do so, if it does not work then
There is another method that we will discuss in
ADB Shell commands section




Pushing and Pulling

For pushing,
Type

Code:
adb push %PATH TO BE PUSHED% %PATH WHERE TO BE PUSHED%


Suppose I have an app named SystemUI.apk(PATH = G:\SystemUI.apk) which I want to push in /system/app/ on my android(or in other words, install an app as a system app). Then I would type


Code:
adb push G:\SystemUI.apk /system/app/
More examples
G:\Dance.txt file to be pushed in Dance folder in sdcard


Code:
adb push G:\Dance.txt /sdcard/Dance/
OR
Code:
adb push G:\Dance.txt /mnt/sdcard/Dance/


G:\Movies folder to be transferred in SDCARD in Videos Folder

Code:
adb push G:\Movies /sdcard/Videos/


G:\system\framework\framework-res.apk to be pushed in /system/framework/

Code:
adb push G:\system\framework\framework-res.apk /system/framework/


For pulling,


push command replaces with pull and paths are swapped
Code:
adb pull %PATH TO BE PULLED FROM% %PATH TO PLACE PULLED FILE%
Example,
All system apps are to be pulled to G:\ROM\system\app

Code:
adb pull /system/app G:\ROM\system\app\


build.prop to be extracted to desktop

Code:
adb pull /system/build.prop C:\Users\Areeb\Desktop\

However, if a folder is in platform-tools folder, you don't need to type full path
Suppose if I type

Code:
adb pull /system/ system
Then a folder named system will be created inside platform-tools with all the files in system in it

If a file is in platform-tools folder, then also no need to type full path
For example,
There is an app name DeskClock.apk in this folder then, to push it to /system/app, type

Code:
adb push DeskClock.apk /system/app/

ADB Shell Commands

This mode of adb allows you to execute linux shell commands from your PC

These commands can aldo be executed through the mobile using Terminal Emulator


To initiate shell mode
Type

Code:
adb shell
You will get an prompt like this
sh-3.2#

Now you are in shell mode

adb commands won't work here and a new set of commands will work here. But we will only go in a little detail here.

Assuming you are in adb shell mode, I will only type commands that will work on shell. Note:- These commands won't work if you type them alone on cmd. But, these command will directly work on your mobile's Terminal Emulator
As these commands can also work on mobile, I am going to tell you a way of taking logcat on mobile


Type
Code:
logcat

You will see log of your device

To save this

Type
Code:
logcat > /sdcard/log.txt


A file named log.txt will be generated in sdcard


Uninstalling Applications

Code:
cd /data/app

This will change the directory to /data/app

Code:
ls

This will show the list of files in there

Suppose, there is an app named com.opera.browser (Opera Mobile) you want to uninstall it
Type
Code:
rm -r com.opera.browser


This will uninstall the app

Mounting Command:-

Code:
mount -o rw,remount /dev/block/mtdblock3 /system


Miscellanous commands:-

su: Initiates root request
du: Shows file foldrs and size
date: Shows todays date
ls: Shows list of directory
cd: Changes working directory
rm: Removes the file
logcat: Displays logcat
mount: Mounts the partition
busybox: Busybox Applets




Credits

Google: For Android and several searchings
Samsung: For Galaxy Ace s5830I

paxChristos for amazing logcat guide
Broadcom: For their Open Sourceness
XDA Forums : For the precious knowledge
The Following 207 Users Say Thank You to iamareebjamal For This Useful Post: [ Click to Expand ]
 
iamareebjamal
Old
#2  
iamareebjamal's Avatar
Recognized Contributor / Themer - OP
Thanks Meter 4,675
Posts: 3,597
Join Date: Aug 2012
Location: Batcave
Reserved
The Following 7 Users Say Thank You to iamareebjamal For This Useful Post: [ Click to Expand ]
 
iamareebjamal
Old
#3  
iamareebjamal's Avatar
Recognized Contributor / Themer - OP
Thanks Meter 4,675
Posts: 3,597
Join Date: Aug 2012
Location: Batcave
Reserved Once More
The Following 3 Users Say Thank You to iamareebjamal For This Useful Post: [ Click to Expand ]
 
iamareebjamal
Old
#4  
iamareebjamal's Avatar
Recognized Contributor / Themer - OP
Thanks Meter 4,675
Posts: 3,597
Join Date: Aug 2012
Location: Batcave
Last One
The Following 4 Users Say Thank You to iamareebjamal For This Useful Post: [ Click to Expand ]
 
dabeez98
Old
#5  
dabeez98's Avatar
Senior Member
Thanks Meter 65
Posts: 370
Join Date: Jul 2012
Location: Malmö
Reserve the guide
I'm Back.
Former devices and why:
Galaxy S II: Screen shattered in microscopic parts
PiPo Smart S1: Broken speaker wires, don't have a clue about soldering
The Following User Says Thank You to dabeez98 For This Useful Post: [ Click to Expand ]
 
angel.sea
Old
#6  
Senior Member
Thanks Meter 36
Posts: 222
Join Date: Jan 2013
Location: rome
Default install full rom

how to install a full rom from adb?
 
kubukoz
Old
#7  
Member
Thanks Meter 9
Posts: 63
Join Date: Jun 2012
Location: Zduńska Wola

 
DONATE TO ME
Default Re: [GUIDE][ADB]Easiest How to use adb, logcat, etc for noobs and newbies

Pretty sure it's impossible. Sorry.

Sent from my E15i using XDA Premium App
 
jisharka
Old
#8  
jisharka's Avatar
Member
Thanks Meter 21
Posts: 57
Join Date: Oct 2012
Location: Dubai
Default Perfect Guide to use ADB Commands..

It is very clear and perfect guide to use ADB commands.. I tested this all and works fine..
The Following User Says Thank You to jisharka For This Useful Post: [ Click to Expand ]
 
sgdva
Old
#9  
sgdva's Avatar
Senior Member
Thanks Meter 19
Posts: 116
Join Date: Apr 2012
You can use apks to do logcats from the phone too, I use catlog.
Devices/ROM:
Moto G/Upgraded KK 4.4.2 (suggested for a very cheap price, is still fast)
PipoS1/Upgraded JB 4.2.2 (suggested for a very cheap price, is still fast)
Zopo C2/Stock 4.2.1 Broke Screen (Not suggested)
Momo9/CM10 Not used anymore(Not suggested)
SGAi/Simplicity V5 Not used anymore(Not suggested)
The Following User Says Thank You to sgdva For This Useful Post: [ Click to Expand ]
 
Chris s5830i
Old
#10  
Chris s5830i's Avatar
Member
Thanks Meter 53
Posts: 82
Join Date: Jan 2013
Location: between my chair and PC
About Broadcom being open sourced made me laugh hahaha.

The Following 4 Users Say Thank You to Chris s5830i For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes