If you have been in relation with the Android sphere, I assume you know of what ADB is. Even if you don’t, you shall now recite it as here we’re going into a little depth about the same. We will begin our journey with defining and explaining its structure, commands and end it with setting it up and exploring its daily applications for Android users/developers. Lets now lean forward towards the basic, followed by the complications.
This guide and the information indulged in it is meant for anyone and everyone related to Android. You shall find its necessity on several occasions like taking logs, flashing firmware images, updating phone software, flashing ROMs/Recoveries & even while developing a ROM/Kernel/Application. ย So, from users to developers, it will come in handy.
What is ADB?
ADBย orย Android Debug Bridgeย is a fullyย equippedย and loaded command-line tool which is put to use in order to communicate with an Android device. ADB tool is provided alongside the Android SDK and one could easily find this tiny but versatile tool under <SDK>/platform-tools/
It comprises three basic and important components:
- The Client
It is what runs on your development machine - The Server
It is held responsible for communication between the client and daemon running on a device/emulator - The Daemon
It runs as a background process on each device/emulator instance
Now, let’s see how can a user set up ADB on his various OS incl. Windows, Linux & Mac. Since ADB is bundled with Android SDK, so you need it prior for your respective OS. Below are a few easy steps to setup ADB easily on your OS without muchย hassle. SDK and ADB work on JAVA, so make sure that you have JDK6 or higher running on your OS.
How to Setup ADB and Fastboot on Windows within Seconds
Easily Setup ADB and Fastboot on Mac, Linux and Chrome OS
How to Setup ADB on Windows
- Download the Android SDK package for Windows [android-sdk_r21.1-windows.zip]
- Extract the zip files to your C:\ drive. Now you have a folderย android-sdk-linux
- Double click onย SDK Managerย to initiate the SDK manager. You shall perceive the following window.
- Make sure everything is un-ticked. Now selectย Android SDK Platform-toolsย and install it.
- During the next window, you will be prompted. Accept the license and click onย Install.
- When the installation is complete, close the window.
- The SDK manager has now downloaded the platform-tools successfully, which certainly includes our prior ADB.
- The next step is to define the path where ADB is present.
- Go toย C:\android-sdk-windows\platform-toolsย and take note of this path.
- Go to desktop, right click onย Computerย and selectย Properties.
- On the left pane, click onย Advanced System Settingsย and a new window shall open.
- Selectย Environment Variablesย underย Advancedย tab.
- Selectย Pathย variable and click edit.
- Now add the path we noted in step #9 to theย variable valueย and hitย OK.
- Confirm and apply all the changes.
- To confirm that ADB has been configured properly, open CMD window and type in:
adb
- You now have ADB successfully installed and configured on your Windows machine.
How to Setup ADB on Linux
You can setup ADB easily on any Linux distribution including Ubuntu, Fedora, openSUSE, Linux Mint etc.
- Download the Android SDK package for Linux [android-sdk_r21.1-linux.tgz]
- Place the downloaded file in your “HOME” folder.
- Right click on the file and selectย Extract here
- Now, you shall see a folder namedย android-sdk-linux.
- Open the terminal in the Home folder and type in the following commands:
cd android-sdk-linux/tools
./android
- Make sure everything is un-ticked. Now selectย Android SDK Platform-toolsย and install it.
- During the next window, you will be prompted. Accept the license and click onย Install.
- When the installation is complete, close the window.
- The SDK manager has now download the platform-tools successfully, which certainly includes our prior ADB.
- The next step is to define the path where ADB is present.
- Open the terminal again and type in the following commands to add the SDK Path to theย .bashrcย &ย .profile.ย Here “gedit” is the default text editor in Ubuntu. In case you are running other Linux distribution, replace it with the name of the corresponding text editor. For example, in the case of Linux Mint, you shall use: gksudo pluma ~/.bashrc and so on for other distributions.
gksudo gedit ~/.bashrc
- Go towards the end and add the following lines:
# Android tools export PATH=${PATH}:~/android-sdk-linux/tools export PATH=${PATH}:~/android-sdk-linux/platform-tools export PATH=${PATH}:~/bin
- Let’s do the same for .profile. Open Terminal and type:
gksudo gedit ~/.profile
- Scroll to the very end of the file and add the following line:
PATH="$HOME/android-sdk-linux/tools:$HOME/android-sdk-linux/platform-tools:$PATH"
- Reboot your system now to take effect.
- To confirm the configuration, open Terminal and type:
adb
- You have now successfully installed and configured ADB on your Linux machine.
How to Setup ADB on Mac OS
At present Android SDK and its components like ADB only supports systems runningย Mac OS X 10.5.8 or higher. So, make sure that you meet the requirement.
- Download the Android SDK package for Mac OS [android-sdk_r21.1-macosx.zip]
- Extract the downloaded zip package to your Home directory.
- Now, you shall see a folder namedย android-sdk-macosx
- Navigate insideย android-sdk-macosx/tools/
- Double-click “android” to execute the SDK Manager.
- Make sure everything is un-ticked. Now selectย Android SDK Platform-toolsย and install it.
- During the next window, you will be prompted. Accept the license and click onย Install.
- When the installation is complete, close the window.
- The SDK manager has now downloaded the platform-tools successfully, which certainly includes our prior ADB.
- The next step is to define the path where ADB is present.
- Open terminal window and type following:
nano ~/.bash_profile
- This shall open theย .bash_profileย file. Now enter the following line to define the ADB path.
export PATH=${PATH}:~/android-sdk-macosx/tools export PATH=${PATH}:~/android-sdk-macosx/platform-tools
- Reboot your system now to take effect.
- To confirm the configuration, open Terminal and type:
adb
- You have now successfully installed and configured ADB on your Mac OS machine.
Guide to ADB Commands
ADB commands are independent of the OS you’re using them on. Once you have set up the SDK and hence, the ADB, you can move forward and make use of any of these commands upon your requirement. Lets hit the basic commands.
- What if you connected your Android device to your machine and you want to make sure that it’s correctly detected? You got to put to use this simple command.
adb devices
Now, what it does is, start a daemon (background process) and output the device debugging serial. So, if it does so, then you can be sure that your device has made a successful connection with the machine.
- The second most made-in-use command is logcat. Most used, because it’s not only used by users to report the errors in Apps, Kernel, ROMs etc but also by the developers to track the bugs and fix them. So, it holds a great importance in Android development.
Once, you have started to log, you also need to put a barrier of stoppage when you think that you have acquired sufficient knowledge about what you seek, to do this pressย Ctrl + C.Logcat command can itself be used in several ways. To display a real-time log of the device, Its best to take a log since boot, which gives a more appropriate knowledge. This command in most cases is used by developers to simply take note of the log of their developed Apps, ROMs, Kernels etc. To take in a real-time log, type the following command in your CMD (Windows) or Terminal (Linux/Mac).
adb logcat
Cases arise when you’re a user and at certain situations, you’re required to take note of the log and upload it for the developer assistance/help. But, recording the log over CMD/Terminal is pretty messy and so this command makes it simple. What it shall do is, take the log and store it decently in a .txt file, so that a user can carry it or transfer it easily. Again, its better to log since boot until you are considerate about logging a single process. Type in the following command:
adb logcat > logcat.txt
Here, “logcat.txt” is the name of the file, you may vary it in accordance to your needs. For Eg. adb logcat > ROMlogcat.txt
The same file shall be stored inย C:\Users\<username>ย for Windows & Linux
- Pull/Push commands hold equivalent importance as it saves the trouble of manually extracting a specific apk using a file manager with Root permissions and then transferring it to the PC. What it does is, directly pull out/push in the desired apk from/to any location under the device without much hassle.To pull an apk file, type:
adb pull <filepath)
eg. adb pull /system/app/SystemUI.apk
To push/copy over an apk file to the device, type:
adb push <filename> <filepath>
eg. adb push SystemUI.apk /system/app/SystemUI.apk
NOTE: The file names and file paths in these commands are case-sensitive. Also, in case of system apks, its advised to first mount using the following command.
adb remount
- There are several occasions when a user has to use his device accessed in shell mode and ADB makes it easier. To initiate a shell connection with the device/emulator, type in the following command:
adb shell
While in the ADB shell, a user has access to some unique and new commands which are as following:
cd <path>
The above commands changes the CMD/Terminal directory to a specified directory inside the Android device/emulator.
e.g: cd /system/appls <path>
The above command lists all the files in the current shell directory
e.g: ls /system/apprm <file_path>
The command removes a specified file from the directory
e.g: rm /system/app/SystemUI.apkcp <file_path> <copy_path>
The command copies a specified file to another location
eg. cp /system/app/SystemUI.apk /sdcard/SystemUI.apkTo exit the shell, type:
exit
- Booting commands also hold their place and come in very handy while rooting processes and even while Android development. Below are stated such 3 commands:
adb reboot
The command simply reboots your device at any instance
adb reboot recovery
The command reboots a device into recovery mode
adb reboot bootloader
The command reboots a device into its bootloader (fastboot) mode
- In case you’re in bootloader mode, your device shall never show any response to ADB commands. But, here comes fastboot in action, which has a limited, but a few and very useful commands. This is the same reason that bootloader mode is often referred to as fastboot mode.
fastboot devices
Displays the device ID of the Android device connected while in bootloader mode.
fastboot reboot
Reboots a device
fastboot reboot-bootloader
Reboots the bootloader
fastboot oem unlock
Initiates the bootloader unlocking sequence
fastboot oem lock
Re-locks the device bootloader
fastboot flash recovery <recovery_image_name.img>
Flashes a recovery image to the device
eg: fastboot flash recovery clockworkmod-6.0.3.1_mako.imgfastboot flash radio <radio_file_name.img>
Flashes the Radio (baseband) image file
eg. fastboot flash radioย radio-crespo-i9020xxki1.imgfastboot flash bootloader <bootloader_file_name.img>
Flashes a bootloader image to the device partition
eg. fastboot flash bootloaderย bootloader-crespo-i9020xxlc2.img
This is all! We’ve guided you set up Android SDK, ADB and use the simple command-line tool. We do not expect everyone to grasp this knowledge all at once, so in case you’re in any trouble while setting up or while using these commands, comment below and we shall give you a helping hand.
plz link
thanks. you saved my day.!!!
When I try to perform step 5 it says I need to install java, which I did. Tried restarting to no avail.
After I enter: export PATH=${PATH}:~/android-sdk-macosx/tools
export PATH=${PATH}:~/android-sdk-macosx/platform-tools
Nothing happens in the terminal, is this normal? I continued with the tutorial after this anyway and it didn’t work.
Now we have easier guides to get ADB Fastboot working: https://www.droidviews.com/tag/adb-and-fastboot/
Been trying cmd promp in IOROOT25 and having a hard time with it seeing my phone. sometimes it will say offline but most tries it doesn’t see anything. once it had my serial number with unauthorized. my computer sees my phone and I can open my files but cmd promp will not in IOROOT25..
Reinstall the drivers. Connect device in download mode to computer. Open Windows Device Manager and set the COM Port to COM41. See here for details: https://www.droidviews.com/how-to-restore-lg-g2-to-stock-firmware/
I did every step for windows and when I got to editing path variables there are two, users and system. I am not sure which one to change to – C:DownloadsSoftwareandroid-sdk_r21.1-windowsplatform-tools
Open Platform-tools, launch a cmd window, connect your device and type ‘adb device’ to check if your device is detected. If yes, you can use other commands too.
Been trying cmd promp in IOROOT25 and having a hard time with it seeing
my phone. sometimes it will say offline but most tries it doesn’t see
anything. once it had my serial number with unauthorized. my computer
sees my phone and I can open my files but cmd promp will not in
IOROOT25.
ok tried cmd window in platform-tools and ran fastboot devices but still no devices. I am running vista is that a problem ?
Followed step by step twice. Device isn’t detected..
samsung GS$ i9505 continually vibrates twice and screen with phones name flashes up for a few seconds then disappears
Did this 5 times step by step… still get “command not found” on #14.
hi! i have unzipped it to c: and installed sdk platforms-tools but i can’t see the directory C:android-sdk-windowsplatform-tools. There is no such folder named C:android-sdk-windowsplatform-tools. plz help
now i m DONE. Thank You.
Glad for that ๐