Friday, July 6, 2012

How to debug android applications in real device

How to debug android applications in real device


There's a great tutorial over at Android Developers that teaches you how to develop a simple note application. In this blog post I'm going to explain how to start debugging your application on your phone together with Eclipse. You can find the document I learned from over at Developing on a Device. I found that I had some problems with permissions that the document didn't bring up. You can read the troubleshooting at the end.

1. Make your application debuggable
In Eclipse, open up the AndroidManifest.xml file. Go to the Application tab and change "Debuggable" to true.


2. Enable USB debugging on your phone
Go to Settings - Applications - Development on your phone. Check "USB debugging". I also check "Stay awake" so that the screen is always awake when debugging.


3. Setup your system to detect the phone
I use Ubuntu 9.10 (Karmic Koala) as my main development machine. To make it work you have to add a udev rules file.
Create a rules file (as root): /etc/udev/rules.d/51-android.rules
Open up the file and add: SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
"0bb4" is the vendor id for HTC phones. You can find a table with vendor id's at Developing on a Device. Change the id to the vendor of the phone that you're going to debug on.
Change the mode on the file (give all read access to the file): chmod a+r /etc/udev/rules.d/51-android.rules
You can check that the system can find the phone by using the "Android Debug Bridge". You can find it in the platform-tools folder in the SDK.
Run this command: adb devices
It should then list all the devices it can find. If it doesn't, check out the troubleshooting part in this post.
You can read how to set it up on Windows and Mac over at Developing on a device.


4. Start debugging


Now you can right-click on the project and choose "Debug as" - "Android Application". This will copy the application to the phone and start the debugging process. Then it's just like normal debugging. You can set breakpoints, step into/over breakpoints etc.
Have fun.........


What is the TTL (Time to Live)? Why is it required?


TTL is a value in data packet of Internet Protocol. It communicates to the network router whether or not the packet should be in the network for too long or discarded. Usually, data packets might not be transmitted to their intended destination within a stipulated period of time. The TTL value is set by a system default value which is an 8-bit binary digit field in the header of the packet. The purpose of TTL is, it would specify certain time limit in seconds, for transmitting the packet header. When the time is exhausted, the packet would be discarded. Each router receives the subtracts count, when the packet is discarded, and when it becomes zero, the router detects the discarded packets and sends a message, Internet Control Message Protocol message back to the originating host.