Developing Android apps in Eclipse

For some time now, Android development in Eclipse made me stumble in one point: the libraries. When you develop an app, there will be some third-party library you can use – and it’s easy to do so, just drop it into the “libs” directory. The Android Development Tools (ADT) take care of adding it to the classpath. But what about attaching sources to those libraries so you can debug easily? Nope. These properties are labeled as “non-modifiable” in the appropriate Eclipse dialogs.

Lately, this irritated me again, and this time I dug a little deeper and found the solution: from ADT r20 on, you can use .properties files to specify the source and/or javadoc location! Hooray! Being a typical developer, I didn’t want to create all those files by hand – here’s my script for it so you can save the time to write it. I put it into the “libs” directory. Maybe you need to change the sed call if you name your source archives differently, my convention is “library-1.2.3.jar” => “library-1.2.3-src.zip”.

#!/bin/sh
# generate .properties files for all jars
# so that the sources will be attached in Eclipse
LIBS_DIR=$(dirname $(readlink -f "$0"))
rm -f $LIBS_DIR/*.properties
ls $LIBS_DIR/*.jar | while read file; do
	src_zip=$(echo $file | sed -e 's#\.jar$#-src.zip#')
	if [ -e $src_zip ]; then
		echo "src=$src_zip" >$file.properties
	fi
done

Reference: blog entry by Daniel Ostermeier and Jason Sankey