Thursday, May 26, 2011

Tools of an Android developer

LogcatImage by Gubatron via Flickr

Being an Android developer for about 9 months I have collected a number of tools, methods and solutions that help with some of the problems and challanges when creating on Android apps.
Some of them were found on the Internet, some of them in books others by accident or cracking my head against some issues again and again.
In a series of posts I'd like to share some of them with you.

Let's start with some tips on Logcat which is a powerful logging tool and can help you greatly in daily developement.
  •  Resetting logcat - Logcat does not like too long log entries. When given such it stops displaying other logs and informs :
  • Logcat read - invalid argument error 
  • There is a simple solution for that - be careful what you log. ;)
  • Clearing (flushing) the log solves works well to and it can be done by running :
  • adb logcat -c
  • Note that this works for a logcat run from a command line but unfortunately Eclipse needs to be restarted after that.
  • 'Where' did I log ? - I have encountered two ways of getting meaningful messages on logs :
    • Define a public static final String field that will be instantiated with YourClass.class.getName() - and use it as first Log.* argument, the method name and 'what' can be the second argument.
    • Create a class with a static method that would throw an exception, catch it, log its stacktrace and log your message, if any.
  • If you are using a lot of logs to check what's happening, perhaps you might want to use Android's debbugger which works very well or better yet - write some tests.
  • Try to be as consistent as possible when chosing your log level (debug, info etc.) because when you use Proguard to remove some of them on your production version (this will be explained later on) you might lose some useful information.

That would be all on Logcat at this point. My next posts will show you how to work with a mavenized Android project in Eclipse, how can you use Spring for Android, some different Proguard configs (to remove Logcat for example), some hints on persisting data, especially the data you use in your current task and more.

Also you might want to check out my other post (in polish) on a Android-themed meeting in my company. We were talking about Android's success from both user's and developer's perspectives.