Sunday, December 1, 2013

Android Debugging

Quick overview of some features for debugging Android app under Eclipse. I'll add them as I discover them...

If you look at the bottom right of your IDE (at least that's where it is for me), you can see the following panel. If for any reason, you prefer to edit in full screen mode (double clicking on the tab of the given source file), then this screen will pop when you run the app.


There are several tabs. If you click on Devices, you can see whatever device is connected to the computer. Also, on the same tab, you can get a snapshot of the screen of the selected device. We are going to look now into the LogCat tab. This has to do with Android logging. You can have the program output messages (logs) into your console as it is executing. Very useful to trace what is happening. Simply use something like Log.v("TAG", "Stuff to log");
  1. The "v" in log v indicates "verbose". You can use others (see the link) but I seldom do. 
  2. TAG is whatever you want to put so that you can group/filter the logs/messages. TAG can be just text that you put right there, between "" or some folks will make it part of a constants class and use Log.d(Constants.LOG, "started recording"); In our case/picture above, TAG=MyActivity.
  3. "Stuff to log" is the message itself (something that you write to yourself). You can see things like "Scoped Thread Stopped"
An older method to do this was System.out.println("started recording"); but the one above is more proper logging with all its advantages (filtering, etc...). See here the difference between the two.

Also, careful with the use of BuildConfig.DEBUG. This is intended to be able to disable the logging once you are ready for release but some folks say that it doesn't work. Although some say it does.

While all this debugging is done over USB cable, there may be a method for debugging over Wi-Fi
The link above didn't make it all that clear, so, found this other one. Unfortunately, I never got it to work (they say that you may need a rooted device). I do the adb kill-server. Then adb tcpip 5555 gives me a message as daemon started successfully but gets stuck on the "restarting in TCP mode port:5555"

Anyhow, not a great post but hope it was useful to somebody... I'll update this as I get it to work...

No comments:

Post a Comment