MrBool
You must be logged in to give feedback. Click here to login
[Close]

You must be logged to download.

Click here to login

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

How to debug the Android Application

In this article we will see the process to debug Android applications, searching for some errors.

[close]

You didn't like the quality of this content?

Would you like to comment what you didn't like?

We know that the client-server program has three components: client, server and daemon.

Talking about the client, it is present on the development machine. Shell can be used to invoke the client which is normally done with the help of some important commands. And then we have server that normally functions in the background on the machine. Also is used to handle the communications that are normally done between the client and the bridge that is used to debug the application. Finally we have the daemon that is being operated in the background on emulator as well as the devices.

Once the client is started, the first check would be for the presence of the server and in the absence of the same, the server process is started. And then the purpose of the server would be to recognize the commands that are being sent from the client post which the connection is set up with the emulator and devices. And then if the server finds the daemon, the connection is set up with it at the port and the point to note here is that a pair of ports needs have acquired by the emulator as well as the device and is required to be done at the even number ports in case you are going for console connections. Else we need to go for odd numbered at the time of port connections.

Below lists the example of the same:

Emulator 1, console: Port 5549, Emulator 1, adb: Port 5550
Emulator 2, console: Port 5551, Emulator 2, adb: Port5552

We will now see the commands that can be made use of in case someone wants to look at the port capabilities. These commands also help in managing the emulator as well as device state. There is no need to review the adb port from the command line in the case where eclipse is made use of o develop the Android application. Also we have a adt plug in with this eclipse that has the reputation of giving the combination of adt-Eclipse iDE. And still we can make use of adb ports directly for the debugging purposes.

How to issue client commands?

The client commands can be issues with the help of the command line that is present on the machine of the developer.

The usage is:

adb [-s <serialNumber>] <client adb command>

The client is invoked by the program in the case when the command is issued and you will be happy to know that it is not necessary to associate the client with any instance of the emulator. So this is usefl in the case of multiple emulators wherein the need will be just to make use of the options that would help in specifying the target to which command is supposed to be triggered.

Querying for Emulator/Device Instances

Prior to issuing the client commands, it is good if we gain knowledge on different emulators as well as the devices connected to the server. And the lost of such devices/emulators can be retrieved from using the following command: adb devices

As a result, the below details are retrieved for each of the output received from the above command

Serial number, that is considered to be a short string and helps in recognizing the connected device as well as the emulator with the help of the port number.

Format: <type>-<consolePort> and the example is serial number: emulator-5549

State, defines the connection status or rather the state of the emulator or the device and the supported states are offline and device. Offline state is the one where your emulator/device is not connected to the client and in case of the device, we see the same being connected to the server and responding.

The point to note in case of device mode is that do not take it granted that the system is completely booted, it is operational though because of the reason that system keeps on booting.

Below lists the output of the emulator/device:

[serial_Number] [status]

Also below is the example displaying the command used in the devices and also displays its outcome:

$ Client adb devices
List of devices attached
emulator-5549 device
emulator-5550 device
emulator-5551 device

Assuming there is no emulator/device running, in that case the client commands would not give you back any device.

Directing Commands to a Specific Emulator/Device Instance

Now let’s suppose we have lots of emulators as well as the devices operating at the same time, in that cse we would need to clearly give the name of the target device at the time of triggering the client commands. For that one can use the client commands and the usage of the same is displayed below

Client adb -s <serial_Number> <s-command>

As specified, the target device is mentioned and it is done making use of a serial number and also we can make use of many more client commands so as to retrieve the serial numbers of the different emulators a well as the devices.

Installing an Application

The client commands can be used in order to copy the application from the development machine and then make it install on the device or the emulator.

The following command need to be made use of in order to achieve this. And also the path to the file needs to be specified where the installation needs to take place.

adb installation <filepath>

The point to note here is that when using the Eclipse with the ADT plug in installed, there is no need to make use of the adb client so as to install the application on the emulator as well as the device. Rather we can make use of ADT plugin that is used to package and install the application.

How to forward the client Ports

The command that can be used to set the forwarding of the port is the forward command. Also it can be used to forward the request on the specified host and below lists the example or rather the process to do the same.

adb client_forward tcp:5949 tcp:7300

The other options is to make use of the client commands as illustrated below

adb client_forward tcp:5949 local:logs

It’s time now to copy the files to the emulator as well as the device and also versa where the files are copied from the emulator as well as the device.

The easiest way is to make use of the adb command. This will help to pull as well as push the files from the emulator and the device. The advantage of pull and push command is that it help the developers to copy the directories irrespective of any location in the emulator as well as the device.

Use the below command

adb client_pull <remote_file> <localpath>

The below command helps to copy the file to the emulator and the device

adb client_push <localpath> <remote_file>

How to enable logcat Logging

We can see the system debug output with the special technique of Android logging system. We can make use of the circular buffers to store logs from the different applications. It can then be filtered which is done by making use of the logcat command.

Logcat command

Figure 1: Logcat command

How to filter Log Output?

Tag and priority are two things we will always find in a Android log message where tag is nothing but a string and is used to tell about the component of the system. And then we have a priority defined in the following ascending order: V, D, I, W, E, F, S ( Verbose, Debug, Info, Warning, Error, Fatal, Silent)

Run the logcat and then one can get the tags list. This is the list which is used in the system. The below lists the logcat output example. It displays the priority level "I" and then we have a tag "ActivityManager" as well:

ActManager(-s): Initiating activity

Make use of the filter expressions if you want to get the log output reduced. The benefit of this is that it will help in indicating the system about the combination of tags and priority.

Format: tag:priority and we have a tag showing the interest tag. One can make use of priority to tell the bug priority. There is no limit to the tag:priority use and can be used any number of times.

See below now the filter expression example. It is used to compress the messages of the log. However the ones that have the "ActivityManager" tag is an exception to this.

client logcat ActManager: MyApplication:S
Logcat

Figure 2: Logcat

What is the purpose of the element S? It is used to set the level of priority. It is being set to "silent" and makes certain on only "View" and "MyApp" log messaged. This element is perfect in order to make sure that output of the log is limited to the filters. These are the filters that were specified and helps in the output of the logs.

Look at the below expression that provides the log messages. Also given is the priority level "warning".

adb client_logcat :W (indicatesbwarning)

Developers making use of have the option to set a default filter expression. This is done by exporting a value for the environment variable. The variable is ANDROID_LOG_TAGS:

Android_tags="ActManager: MyApplication:S"

Android_tags is one such filter that cannot be used for exporting to the emulator. This also holds valid for the devices.

Conclusion

The tutorial is now completed and we have learnt in brief on the process to debug the android application.



Working in Software Development domain from 7 years now and is well equipped with programming languages like HTML, CSS, Java, PHP, .NET etc.

What did you think of this post?
Services
Know how to keep MrBool Online
SUPPORT US
SUPPORT US
With your help, we can keep providing free content and helping you to be a better professional
support us
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually � in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits � in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login