frriction Posted August 16, 2012 Report Posted August 16, 2012 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 Standard Edition of JDK. This can be found here: http://www.oracle.com/technetwork/java/javase/downloads/index.html 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://developer.android.com/sdk/index.html Due to already installing JDK, you won't be stopped by the install process. Now, 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 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 ;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. USING ADB 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 and uninstalling 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 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. 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 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 pm uninstall packagename where packagename is the name of the 0kb listing. DISABLE / RE-ENABLE SYSTEM APPLICATION from the system 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. How many of us have removed system applications or renamed them? adb shell su pm disable appllicationname 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. adb shell su pm enable applicationname 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 REBOOT, RECOVERY MODE AND DOWNLOAD MODE ADB can help us here. Here, we do not need to be logged into the shell If we want to merely reboot the phone: adb reboot If we want to go to recovery adb reboot recovery If we want to go to Download Mod 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. PUSHING AND PULLING or COPY AND PASTE FILE. 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: adb push filename /pathtodirectoryonphone So for instance, if I have test.txt that I want to send, I would type: adb push test.txt /sdcard/ 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: adb shell/code] [code]su[/code] We will then mount the system as writable [code]mount -o rw,remount /dev/block/stl9 /system[/code] Then we can use something like [code]cp /sdcard/test.txt /system/app/test.txt[/code] cp stands for copy 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[/code] 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[/code] if is for inputfile of= output file Not every user friendly, but probably one of the safer copy commands. [b]pulling files.[/b] 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[/code] 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[/code] 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. CHANGING PERMISSION OF THE FILES. we use something called chmod. This is used in this manner [code]adb shell su chmod 755 /pathtoapplication/applicationname[/code] Keep in mind you dont want to do this while its still on your sd card. an example [code]adb shell su chmod 755 /system/app/ADWLauncher.apk[/code] 755 is good for applications and script files. [size=12pt][color=black][b]DELETING FILES[/b][/size][/color][/size] This becomes especially handy for removing rogue applications. To do this, we must be in the adb shell. [code]adb shell su rm /system/app/ADWLauncher.apk[/code] You may need to remount system as writable with: [code]mount -o rw,remount /dev/block/stl9 /syste[/code] 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 rm -f /data/dalvik-cache/*.*[/code] I just cleared my dalvik-cache with that command very quick, very effective. If you just tried that, please reboot your phone now [size=12pt][b[color=black]]FINAL TOPIC: logcat[/color][/b][/size] 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 logcat[/code] To logcat to a certain file do [code]adb shell 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. by Captainkrtek and Adrynalyne Quote
navratn123 Posted August 16, 2012 Report Posted August 16, 2012 +1 bcz linux command is awesome...... Quote
devilhunter47 Posted August 17, 2012 Report Posted August 17, 2012 Man this is Un-F*****G-Believable!!!!!!..awesome share..+5 for you:) Mods please make this topic sticky Quote
shivam94 Posted August 17, 2012 Report Posted August 17, 2012 Great epic share bro +1 for now and more to follow later Quote
Die2mrw007 Posted August 17, 2012 Report Posted August 17, 2012 Pretty useful piece of information Thanks for sharing bro Quote
Edios Posted August 18, 2012 Report Posted August 18, 2012 Very useful information. Now I can understand what is ADB. +3 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.