Advertisement
atreyu187

Droid Guides : Setup ADB Windows/Linux/MACOSX

Feb 25th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.35 KB | None | 0 0
  1. What is ADB?
  2. 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 along side the Android SDK and one could easily find this tiny but versatile tool under <SDK>/platform-tools/
  3.  
  4. It comprises of three basic and important components:
  5.  
  6. The Client
  7. It is what runs on your development machine
  8. The Server
  9. It is held responsible for communication between the client and daemon running on a device/emulator
  10. The Daemon
  11. It runs as a background process on each device/emulator instance
  12. Now, lets 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 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.
  13.  
  14. How to Setup ADB on Windows
  15. Download the Android SDK package for Windows [android-sdk_r21.1-windows.zip]
  16. Extract the zip files to your C: drive. Now you have a folder android-sdk-linux
  17. Double click on SDK Manager to initiate the SDK manager. You shall perceive the following window.
  18. Make sure everything is un-ticked. Now select Android SDK Platform-tools and install it.
  19. During the next window, you will be prompted. Accept the license and click on Install.
  20. When the installation is complete, close the window.
  21. The SDK manager has now download the platform-tools successfully, which certainly includes our prior ADB.
  22. The next step is to define the path where ADB is present.
  23. Go to C:android-sdk-windowsplatform-tools and take note of this path.
  24. Go to desktop, right click on Computer and select Properties.
  25. On the left pane, click on Advanced System Settings and a new window shall open.
  26. Select Environment Variables under Advanced tab.
  27. Select Path variable and click edit.
  28. Now add the path we noted in step #9 to the variable value and hit OK.
  29. Confirm and apply all the changes.
  30. To confirm that ADB has been configured properly, open CMD window and type in:
  31. adb
  32. You now have ADB successfully installed and configured on your Windows machine.
  33.  
  34.  
  35. How to Setup ADB on Linux
  36. You can setup ADB easily on any Linux distribution including Ubuntu, Fedora, openSUSE, Linux Mint etc.
  37.  
  38. Download the Android SDK package for Linux [android-sdk_r21.1-linux.tgz]
  39. Place the downloaded file in your “HOME” folder.
  40. Right click on the file and select Extract here
  41. Now, you shall see a folder named android-sdk-linux.
  42. Open the terminal in the Home folder and type in the following commands:
  43. cd android-sdk-linux/tools
  44. ./android
  45. Make sure everything is un-ticked. Now select Android SDK Platform-tools and install it.
  46. During the next window, you will be prompted. Accept the license and click on Install.
  47. When the installation is complete, close the window.
  48. The SDK manager has now download the platform-tools successfully, which certainly includes our prior ADB.
  49. The next step is to define the path where ADB is present.
  50. 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 corrospoding text editor. For example, in case of linux mint, you shall use: gksudo pluma ~/.bashrc and so on for other distributions.
  51. gksudo gedit ~/.bashrc
  52. Go towards the end and add the following lines:
  53. # Android tools
  54. export PATH=${PATH}:~/android-sdk-linux/tools
  55. export PATH=${PATH}:~/android-sdk-linux/platform-tools
  56. export PATH=${PATH}:~/bin
  57. Lets do the same for .profile. Open Terminal and type:
  58. gksudo gedit ~/.profile
  59. Scroll to the very end of the file and add the following line:
  60. PATH="$HOME/android-sdk-linux/tools:$HOME/android-sdk-linux/platform-tools:$PATH"
  61. Reboot your system now to take effect.
  62. To confirm the configuration, open Terminal and type:
  63. adb
  64. You have now successfully installed and configured ADB on your Linux machine.
  65.  
  66.  
  67. How to Setup ADB on Mac OS
  68. 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.
  69.  
  70. Download the Android SDK package for Mac OS [android-sdk_r21.1-macosx.zip]
  71. Extract the downloaded zip package to your Home directory.
  72. Now, you shall see a folder named android-sdk-macosx
  73. Navigate inside android-sdk-macosx/tools/
  74. Double-click “android” to execute the SDK Manager.
  75. Make sure everything is un-ticked. Now select Android SDK Platform-tools and install it.
  76. During the next window, you will be prompted. Accept the license and click on Install.
  77. When the installation is complete, close the window.
  78. The SDK manager has now download the platform-tools successfully, which certainly includes our prior ADB.
  79. The next step is to define the path where ADB is present.
  80. Open terminal window and type following:
  81. nano ~/.bash_profile
  82. This shall open the .bash_profile file. Now enter the following line to define ADB path.
  83. export PATH=${PATH}:~/android-sdk-macosx/tools
  84. export PATH=${PATH}:~/android-sdk-macosx/platform-tools
  85. Reboot your system now to take effect.
  86. To confirm the configuration, open Terminal and type:
  87. adb
  88. You have now successfully installed and configured ADB on your Mac OS machine.
  89.  
  90.  
  91. ADB Commands
  92. ADB commands are independent of the OS you’re using them on. Once you have setup 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.
  93.  
  94. What if you connected your Android device to your machine and you want to make sure that its correctly detected? You got to put in use this simple command.
  95. adb devices
  96. 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.
  97.  
  98. The second most made-in-use command is logcat. Most used, because its 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.
  99. Once, you have started to log, you also need to put a barrier of stopage 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).
  100. adb logcat
  101. 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:
  102.  
  103. adb logcat > logcat.txt
  104. Here, “logcat.txt” is the name of the file, you may vary it in accordance to your needs. For Eg. adb logcat > ROMlogcat.txt
  105. The same file shall be stored in C:Users<username> for Windows & Linux
  106.  
  107. 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:
  108. adb pull <filepath)
  109. eg. adb pull /system/app/SystemUI.apk
  110.  
  111. To push/copy over an apk file to the device, type:
  112.  
  113. adb push <filename> <filepath>
  114. eg. adb push SystemUI.apk /system/app/SystemUI.apk
  115.  
  116. 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.
  117.  
  118. adb remount
  119. 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:
  120. adb shell
  121. While in the ADB shell, a user has access to some unique and new commands which are as following:
  122.  
  123. cd <path>
  124. The above commands changes the CMD/Terminal directory to a specified directory inside the Android device/emulator.
  125. e.g: cd /system/app
  126.  
  127. ls <path>
  128. The above command lists all the files in the current shell directory
  129. e.g: ls /system/app
  130.  
  131. rm <file_path>
  132. The command removes a specified file from the directory
  133. e.g: rm /system/app/SystemUI.apk
  134.  
  135. cp <file_path> <copy_path>
  136. The command copies a specified file to another location
  137. eg. cp /system/app/SystemUI.apk /sdcard/SystemUI.apk
  138.  
  139. To exit the shell, type:
  140.  
  141. exit
  142. 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:
  143. adb reboot
  144. The command simply reboots your device at any instance
  145.  
  146. adb reboot recovery
  147. The command reboots a device into recovery mode
  148.  
  149. adb reboot bootloader
  150. The command reboots a device into its bootloader (fastboot) mode
  151.  
  152. 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.
  153. fastboot devices
  154. Displays the device ID of the Android device connected while in bootloader mode.
  155.  
  156. fastboot reboot
  157. Reboots a device
  158.  
  159. fastboot reboot-bootloader
  160. Reboots the bootloader
  161.  
  162. fastboot oem unlock
  163. Initiates the bootloader unlocking sequence
  164.  
  165. fastboot oem lock
  166. Re-locks the device bootloader
  167.  
  168. fastboot flash recovery <recovery_image_name.img>
  169. Flashes a recovery image to the device
  170. eg: fastboot flash recovery clockworkmod-6.0.3.1_mako.img
  171.  
  172. fastboot flash radio <radio_file_name.img>
  173. Flashes the Radio (baseband) image file
  174. eg. fastboot flash radio radio-crespo-i9020xxki1.img
  175.  
  176. fastboot flash bootloader <bootloader_file_name.img>
  177. Flashes a bootloader image to the device partition
  178. eg. fastboot flash bootloader bootloader-crespo-i9020xxlc2.img
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement