# Sticky  [REFERENCE/GUIDE] Everything about ADB!



## Captainkrtek

*This workshop was held in #android-learning on irc.freenode.net by XDA Member Adrynalyne. All credit to him for this guide*, I simply am taking it and turning it into a guide. Here we go!









You can find the raw IRC log here

Good evening folks, and welcome to my ADB workshop. This is by no means a full explanation on the subject, but more of a crash course to help folks get up to speed, and get more from their devices. There may be some things you already know here, so please be patient and respect those who do not.

Reference Files

http://adrynalyne.us/files/How to install adb.pdf
http://adrynalyne.us/files/Using ADB.pdf

So, lets just start with the basics.

*What is ADB?* 
ADB stands for the android debugging bridge and is used for testing and debugging purposes by developers.

However, we like to get more out of our devices, and its a great way to fix things.
Knowing adb can mean the difference between a paperweight and a working phone.

So, to start with, we will look at *installing ADB*.
Generally speaking, the Sun/Oracle JDK is required to run all SDK functions.
ADB is but one tool in the SDK arsenal.
So, we begin by downloading and installing the JDK. This can be found here:

https://cds.sun.com/is-bin/[email protected]_Developer

Choose your OS, download and install. I recommend that 64 bit users use the regular x86/32 bit version as well.
Moving ahead, we download the Windows sdk from here:

http://dl.google.com/android/installer_r08-windows.exe

Due to already installing JDK, you won't be stopped by the install process.
Now, if you notice, I installed it to:

C:\android-sdk-windows

I did this because it makes things easier when setting up path variables.
I encourage everyone to do the same, but obviously it is not required.

So, this SDK is handy, but is only good up to 2.2. We want the latest and greatest! (Well I do)

So, we navigate to:

C:\android-sdk-windows\

and we run SDK Manager.exe

If you notice in your PDF file for installing adb, you will notice that you can update, and I made a choice not to include earlier sdk versions.

I won't go into full detail on that, but depending on the version of SDK you have, 8 or 9, it WILL make a difference in using adb.
By default, for version 8 adb.exe resides in C:\android-sdk-windows\tools
By default, for version 9 adb.exe resides in C:\android-sdk-windows\platform-tools
We will assume version 9 in this guide

Really, the *SDK is installed and adb is usable right now, but in my humble opinion, its not enough*

I like the ability to *use adb in ANY directory on my machine.*
To do this, we edit Windows's environment variables.
Specifically, the system path.

To do this, we click on start, or the orb (depending on OS), and right click on Computer, left clicking on properties in the menu.
If its windows XP, I believe it brings you into advanced system properties immediatly. Vista and 7 need a second step.
On the left hand side, as you notice I have highlighted in the pdf, left click advanced system settings.

Under advanced tab, we left click environment variables...
There are two boxes here.
We are concerned with system variables, however.
So we scroll down the list and highlight path and click edit.
Ignoring all the extra stuff in here, make sure you are at the end of the line, and type



Code:


;C:\android-sdk-windows\platform-tools

The semicolon allows us to separate it

from the previous path statement.
Click ok all the way out.
We now have ADB setup globally. We can use cmd.exe (I use powershell) and no matter what directory we are in, adb is recognized.
If it is not, make certain you entered the path into system variables, and made no typos.
If you installed to a different location, you will need to adjust the path accordingly.

*This concludes the section on installing the Android SDK to use ADB.*

This next section will be on *using ADB*, so please open that pdf now.
Now, this applies to any OS, not just Windows.
Well, with the exception of the USB drivers.
I will not go too much into that, but if you take a look at the PDF, it goes through installing usb drivers for the sdk, and how to download them.
Fiarly straightforward, in that rspect.

Now, to *setup our phones* to use with the SDK and ADB, we must change some settings.
First, we go to menu softkey, then settings.
We scroll down to Applications and tap it.
Under Development, we will check Enable USB Debugging. Please note the SGS phones are different in this respect.
The USB cable must be unplugged before enabling or disabling this setting.
Once this is done, we are now ready to play with adb

_One quick note: If you get device not found/conencted, please reboot your phone. DJ05 has a quirk in it where ADBD randomly crashes on boot.
A reboot will fix this_

ADBD= ADB Daemon

Ok, continuing on.
Lets look at installing applications. This is also known as sideloading.
Unlike installing from the SD card, it does not require unknown sources to be enabled.
The command for this is



Code:


adb install packagename

This assumes that you are working from the directory where the file is located.
This will install the application to /data/app.
It will also show sometimes useful errors if install fails.
That is not something you will see from the Android GUI.
Now, a lot of us have probably deleted files with apps like Root Explorer. While this isn't really a bad thing, it leaves behind databases and data for the application removed.
This is where the 0kb applicaiton entries come from.
If you take that application entry name, you can uninstall the extra data via adb.
First we go to the adb shell which logs into the phone.



Code:


adb shell

If we end up with a $, we will want admin rights, in many cases. This is not one of them, I don't beleive.
To get admin rights, you want to type



Code:


su

Look at your phone if this is the first time, it may prompt you to allow access. Else you will get permission denied.
If you are not rooted, this will not work either.
Ok, now that we are logged in, we will type



Code:


pm uninstall packagename

where packagename is the name of the 0kb listing.

Now this seems like a pain in the a** and I agree.
HOWEVER
There will be a time where Manage applications crashes when you try to uninstall it from the phone. In this case, a factory reset, or this method is the only effective way to fix the problem.
Moving on.
How many of us have removed system applications or renamed them? Did you know that you can simply disable them from the system?



Code:


<br />
adb shell<br />
su<br />
pm disable appllicationname<br />

This will disable it, and the system will ignore it.
This can be seen as safer than deleting or renaming things, but your mileage may vary.
On the other hand, you can also re-enable these applications.



Code:


<br />
adb shell<br />
su<br />
pm enable applicationname<br />

Please note: Not all applications will properly re-enable. I believe a factory reset or reinstall of said application will fix the issue.
Also, application names are absolutely case sensitive.

*nix based Operating Systems see the letter 'a' and 'A' as two different things.
when you log into adb shell, you are playing by android rules


Ok, a lot of us tweak and mod our phones and turning off the device to get to clockwork recovery, or battery pulls, or multiple button holds to get into Download mode are troublesome and annoying at best.
ADB can help us here.
Here, we do not need to be logged into the shell
If we want to merely reboot the phone:


Code:


adb reboot

If we want to go to recovery (works well with voodoo5)


Code:


adb reboot recovery

If we want to go to Download Mode because we need Odin, heaven forbid:


Code:


adb reboot download

Its instant. No waiting on animations or anything else.
Its also handy if Android has locked up, but yet still works in adb.
I for one hate taking my case off to battery pull.

*So now we move on to pushing and pulling files.*
Sometimes, I don't feel like mounting my sd card to copy a file over to my phone.
I can use this command to push a file straight to my sd card:


Code:


adb push filename /pathtodirectoryonphone<br />

So for instance, if I have test.txt that I want to send, I would type:



Code:


adb push test.txt /sdcard/

and there it goes.


----------



## Captainkrtek

Ok moving on
Pushing files can be done _to any directory_, however, some are protected.
For instance, /system is going to give you a permission denied or a read only filesystem error.
To get around this, the easiest thing to do is push the file to your sdcard, then log into the shell:


Code:


adb shell




Code:


su

We will then mount the system as writable


Code:


mount -o rw,remount /dev/block/stl9 /system

Then we can use something like 


Code:


cp /sdcard/test.txt /system/app/test.txt

cp stands for copy
and it requires the path of the file and destination path. The name of the file is optional
When you copy it, you can rename it to whatever you like.
For instance, if we wanted to backup a file


Code:


cp /sdcard/test.txt /sdcard/backuptest.txt

Now, lets assume you _do not_ have busybox installed.
You non rooted users will not.
Then you must use a slightly more complicated command called dd
This is used like this:



Code:


dd if=/sdcard/test.txt of=/system/app/test.txt

if is for inputfile
of= output file

Not every user friendly, but probably one of the safer copy commands.

*Ok, moving on to pulling files.*
Lets say you want to get a file from your phone, to modify, backup, etc.
To do this, we simply use adb in this manner:


Code:


adb pull /pathtofile/filename destinationname

For instance, if I wanted to backup ADW launcher in system/app
I would do this



Code:


adb pull /system/app/ADWLaucnher.apk ADWLauncher.apk

And it will pull the file from the phone and put it in the current directory.
Like above, you can specifcy where it goes.

pushing files to the sdcard, it seems prudent to talk about changing permissions.
sdcards are typically fat32, which destroys permisisons, and Android is heavily permission based.
So if you push an application to your sd card, then try to copy it to /system/app/ bad things are going to happen, or the app may not even show up.

So in that case, we use something called chmod.
This is used in this manner


Code:


adb shell<br />
su<br />
chmod 755 /pathtoapplication/applicationname

Keep in mind
you dont want to do this while its still on your sd card.
an example


Code:


adb shell<br />
su<br />
chmod 755 /system/app/ADWLauncher.apk

755 is good for applications and script files.

Just a couple more topics to cover.
*Lets go over deleting files.*
This becomes especially handy for removing rogue applications.
To do this, we must be in the adb shell.



Code:


adb shell<br />
su<br />
rm /system/app/ADWLauncher.apk

_You may need to remount system as writable with:_



Code:


mount -o rw,remount /dev/block/stl9 /system

That applies when using chmod as well.
So what I did above was delete ADW Launcher from system/app
However, what if I wanted to delete the entire contents of a directory?
Same thing as before, except


Code:


adb shell<br />
rm -f /data/dalvik-cache/*.*

I just cleared my dalvik-cache with that command

very quick, very effective.

If you just tried that, please reboot your phone now

*Ok....this leaves us with the final topic: logcat*
logcat allows us to log what the OS is doing, and possibly delve information for when things are not working
its quite simple Reading it is another. 
To use logcat



Code:


adb shell<br />
logcat

To logcat to a certain file do



Code:


adb shell<br />
logcat > /sdcard/logcat.txt

 Now we let the log settle down to a reasonable amount of data coming in and not a wall of scrolling, then start the app in question. When it gives an error, we hit ctrl-C and kill the adb shell session.

This should have captured enough data to see the error.	Now, I prepared an example. A user came to me on IRC, and Google Maps was force closing. Clearing data didnt fix it, Clearing dalvik-cache, and fix permissions did not fix it. In this case, the user did not know how to use adb So I had him grab an app called alogcat from the market and email me the log. This is also a very valid method.
this file explains what the problem was, and highlights what to look for as an example.

http://adrynalyne.us/files/logcat.pdf
___________________________________________________________________
*This concludes the guide from Adrynalyne, there will be more workshops such as this one in irc.freenode.net #android-learning.*
Thanks to everyone in #samsung-fascinate !

Kang'd from myself from XDA: http://forum.xda-developers.com/showthread.php?t=879701


----------



## xoomdev

Beast of a thread man. Bookmarked so I can send people to this when they ask questions about adb. Not that I ever get fits from doing stuff in windows and need help myself....







awesome post


----------



## abtre

+1 for sure. I read through it all and I knew a good deal of it, but learned a few things as well. Great write-up. Thanks.


----------



## Steady Hawkin

Great guide, thanks bruh!


----------



## dustinmj

Quick tip: mount system using the following commands it is easier ( device irrespective as far as I know.) :

* Mount read/write *



Code:


 mount -o remount,rw /dev/null system

* Mount read only *



Code:


 mount -o  remount,ro /dev/null system


----------



## sbmootyar

One question that I have, I can not seem to get the Google drivers to load for my droidX. I installed the SDK and the Google drives but it keeps telling me that it can not install. The rest of this write up is great.


----------



## socomdark

Have you downloaded the motorola drivers?

Sent from my HTC Glacier using Tapatalk


----------



## sbmootyar

NO I did not as I thought that is what the google ones are for I will do so.


----------



## sbmootyar

Ran into a problem, trying to load the drivers and i installed the motorola ones it won't install when I plug in the phone.


----------



## Droid-Xer

When you connect the phone, the drivers don't autoinstall? Reboot the phone while its connected and see if it does that. Also, you have USB debugging on right? And you need the motohelper 4.9.0 driver from here http://www.google.com/m/url?ei=OW_z...oQFjAB&usg=AFQjCNFkzMMZGQjLDHn8G69Jxqz6oL-9Gg


----------



## sbmootyar

I understood they won't auto install. I was following the directions and getting no where. Thank you I will work on this again tonight. Sure that it is something simple I missed.


----------



## Droid-Xer

Ok well post back if you have more issues.


----------



## sbmootyar

I will post back if I still cant get it to work.. Sorry for that last post I may have sounded like a dick.


----------



## sbmootyar

That worked for me thank you now I can use adb


----------



## AndroidSims

For Droid x I use the drivers supplied by moto on their site and it works fine with adb.

Great write up. +1

Sent from DroidX


----------



## JBirdVegas

Also adb and all the drivers are in the android sdk

If you are a linux user you will need to setup udev 
*I can provide a link if anyone needs it.

Sent from my DROID2 using Tapatalk


----------



## Droid-Xer

Namyar said:


> That worked for me thank you now I can use adb


Cool. Glad ya got it.


----------



## litso

Awesome thread, thanks Cpt and Adrynalyne.


----------



## sbmootyar

So does anyone have info on running apk files in avd? Or can someone help me put my theme files I have changed into adb for debugging?

Thank you


----------



## linuxmotion

You can also remount the system in rw using 'adb remount' on aosp/cm roms. It only persists for a single adb connection. If the cord comes out or you reboot it has to run again. I use this command all the time to allow pushing to my system directories

Sent from my Incredible using Tapatalk


----------



## krylon360

awesome job man. Bookmarking and will be tweeting about this also.


----------



## JBirdVegas

If people run linux I can help them setup on that platform ... [email protected] or pm be but email is best

Sent from my DROID2 using Tapatalk


----------



## Tahl

I also have created an ADB Auto-Installer for Linux Mint and Ubuntu that will pretty much do everything for you (see sig) or head down to the Linux forums and I can help you out. The script will work from a fresh install of either OS and should download, install, and setup everything you need from the SDK, NDK, Eclipse, ADB, DDMS, and setup your udev for you. All you have to do is make the installer executable, sudo ./installer.sh, and then accept some licensing agreements a while later after the downloads are done.


----------



## JBirdVegas

Good work

Sent from my DROID2 using Tapatalk


----------



## Tahl

Made the ADB Auto-Installer even easier.. there are now 32-bit and 64-bit .deb packages so it's just a double click install. Haven't tested the 32-bit version yet, but the 64-bit version seems to work fine.. If anyone still needs to install it and uses it, let me know in the Linux forums or in a PM if it works.


----------



## crashbang

Tahl said:


> Made the ADB Auto-Installer even easier.. there are now 32-bit and 64-bit .deb packages so it's just a double click install. Haven't tested the 32-bit version yet, but the 64-bit version seems to work fine.. If anyone still needs to install it and uses it, let me know in the Linux forums or in a PM if it works.


I'm still rather new to Linux, but am I right that this will not help when adb and fastboot do not recognize my devices? With Ubuntu adb recognizes it but fastboot does not. My Crunchbang does not recognize either with adb or fastboot. My understanding is that I need to set up udev rules but I am rather unclear on how to do this with multiple devices. I have about five that I would like to use in Linux. I hate being forced to use windoze out of ignorance. I would appreciate it if someone could point me in the right direction. Thanks


----------



## linuxmotion

crashbang said:


> I'm still rather new to Linux, but am I right that this will not help when adb and fastboot do not recognize my devices? With Ubuntu adb recognizes it but fastboot does not. My Crunchbang does not recognize either with adb or fastboot. My understanding is that I need to set up udev rules but I am rather unclear on how to do this with multiple devices. I have about five that I would like to use in Linux. I hate being forced to use windoze out of ignorance. I would appreciate it if someone could point me in the right direction. Thanks


This is my script that sets up udev rules for you. https://github.com/linuxmotion/AndroidUdevPermissionsScripts download using git or from the browser. Then make the files executable. Then run the create rules script. It has all the device permission that Google has given out from android.com. it will also restart udev and restart adb. Hope it helps

Sent from my Incredible using Tapatalk


----------



## crashbang

Thanks for your reply. Do I need to move these files into my platform-tools folder with adb for it to work properly? it says it's for Ubuntu 10.10 but I'm running it on a debian derivative. Does that matter? Thanks again.


----------



## linuxmotion

crashbang said:


> Thanks for your reply. Do I need to move these files into my platform-tools folder with adb for it to work properly? it says it's for Ubuntu 10.10 but I'm running it on a debian derivative. Does that matter? Thanks again.


No you can run it from any dir. It should work on any Linux distro that uses udev from /etc/udev/rules.d/

Sent from my Incredible using Tapatalk


----------



## crashbang

I'm confused. I keep getting this....



> Creating the 51-android.rules in the /etc/udev/rules.d directory
> 
> Restarting udev to read the new rules
> Stopping the hotplug events dispatcher: udevd.
> Starting the hotplug events dispatcher: udevd.
> 
> Killing the adb server
> ./create_android_rules.sh: line 18: adb: command not found
> 
> *******************************************************
> Please unplug and replug any currently connected devices
> Press enter to continue
> 
> *******************************************************
> ./create_android_rules.sh: line 29: adb: command not found
> [email protected]:~/documents/UdevScripts$


----------



## linuxmotion

crashbang said:


> I'm confused. I keep getting this....


The rules should be created but means adb isn't in your path

Sent from my Incredible using Tapatalk


----------



## crashbang

So I do have to put the scripts in with adb? it still says no permissions when I try to get adb to recognize my devices. Here's the 51-android.rules it created. Doesn't look right to me.



> SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="0502", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="413c", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="0489", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="091E", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="12d1", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="0482", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="1004", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="22b8", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="0955", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="10A9", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="04e8", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="04dd", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="0fce", MODE="0666"
> SUBSYSTEM=="usb", SYSFS{idVendor}=="19D2", MODE="0666"


----------



## linuxmotion

crashbang said:


> So I do have to put the scripts in with adb? it still says no permissions when I try to get adb to recognize my devices. Here's the 51-android.rules it created. Doesn't look right to me.


Your vendor may not have been in there. I just updated it with more vendors and ran it myself for a fascinate.

Sent from my Incredible using Tapatalk


----------



## crashbang

Okay, I got your new files, ran everything the same way, and still not working for my Nexus s 4g. Here's everything I did. Maybe I'm doing it wrong? I feel like such a n00b. Thanks again man.



> [email protected]:~$ cd /home/crashbang/documents/UdevScripts
> [email protected]:~/documents/UdevScripts$ chmod u+rx /rules.sh
> chmod: cannot access `/rules.sh': No such file or directory
> [email protected]:~/documents/UdevScripts$ chmod u+rx rules.sh
> [email protected]:~/documents/UdevScripts$ chmod create_android_rules.sh
> chmod: missing operand after `create_android_rules.sh'
> Try `chmod --help' for more information.
> [email protected]:~/documents/UdevScripts$ chmod u+rx create_android_rules.sh
> [email protected]:~/documents/UdevScripts$ ./create_android_rules.sh
> 
> *******************************************************
> Add device permisions to the udev rules by LinuxMotion
> [sudo] password for crashbang:
> 
> Creating the 51-android.rules in the /etc/udev/rules.d directory
> 
> Restarting udev to read the new rules
> Stopping the hotplug events dispatcher: udevd.
> Starting the hotplug events dispatcher: udevd.
> 
> Adb found, killing the adb server
> ./create_android_rules.sh: line 20: adb: command not found
> 
> *******************************************************
> Please unplug and replug any currently connected devices
> Press enter to continue
> 
> *******************************************************
> ./create_android_rules.sh: line 31: adb: command not found
> [email protected]:~/documents/UdevScripts$ cd /home/crashbang/documents/android-sdk-linux_x86/platform-tools
> [email protected]:~/documents/android-sdk-linux_x86/platform-tools$ ./adb devices
> List of devices attached
> ????????????	no permissions
> 
> [email protected]:~/documents/android-sdk-linux_x86/platform-tools$


----------



## linuxmotion

crashbang said:


> Okay, I got your new files, ran everything the same way, and still not working for my Nexus s 4g. Here's everything I did. Maybe I'm doing it wrong? I feel like such a n00b. Thanks again man.


See if this file exists. Use 'cat /etc/udev/rules.d/51-android*'. It should have the contents of the rules.sh basicly. If it does try rebooting. If it still doesn't work those are all the permission given by Google.

Sent from my Incredible using Tapatalk


----------



## crashbang

Okay, so apparently Wheezy changed something in udev that didn't get changed in Ubuntu. I had to edit /lib/udev/rules.d/91-permissions.rules



> # usbfs-like-devices
> SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", \MODE="0664"


To


> # usbfs-like-devices
> SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", \MODE="0666"


after restarting udev it recognized my Nexus S 4g, Gtab 10.1, and Sensation 4g. Thank you linuxmotion for all of your help. Hope this helps someone else that likes to use debian that can't figure out what's wrong. Thanks again.


----------



## th3taman

I am trying to install ADB through the SDK Manager, but I can't get it to connect because of my PC's "security". Anyway to install manually? Really bummed that I can't get ADB installed. It's keeping from doing some theming I want to do to the status bar.


----------



## kidman-nicole

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

* Next install the exe file and note the location where you install it to.
* After install is over, use Windows explorer and navigate to the folder where you installed the SDK.
* Double-click the SDK Manager.exe/SDK Setup.exe file at the root of the Android SDK directory.
* This will open up the SDK Installation window, where you can choose from a list of packages to install
* 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)
* That's it, adb.exe is now installed


----------



## whodisname

Damn. Hell of a job with this extremely valuable information. Thank you.


----------



## naxa

dead links with pdfs.

could you repost them please? they seem valuable , just like the guide


----------

