android: workaround for slow ‘building workspace’ problem in eclipse

While developing for android on eclipse 3.6 i had the problem that each time i saved a file, eclipse blocked me several seconds with ‘building workspace…’. Similar to these:

stackoverflow – android-compilation-is-slow-using-eclipse
stackoverflow – android-eclipse-workspace-takes-a-long-time-to-build
groups.google – android-developers/thread/a16202975510de39


The best workaround i found for me:

  • disable Android Package Builder (right-click on project#Properties#Builders)
  • use ant build to deploy on emulator

This way i can work (as) fast (as usual) with eclipse, everything compiles and gets generated, but once i want the app on the emulator, i execute ‘ant install‘ from console.

Setting up the ant build is quite easy, see using-ant-to-automate-building-android for details.
In short you have to simply execute ‘android update project --path .‘ which generates your build.xml.


Note: If you have 3rd party jars put them in ‘libs’ folder, that way ant is aware of them.

Note: You also can build a signed apk with ‘ant release‘. Add therefor a build.properties with such a keystore setup:


key.store=/Users/jz/.android/debug.keystore
key.alias=androiddebugkey
key.store.password=android
key.alias.password=android



PS: i also stumbled into the ‘external folder’ synchronization problem. Closing all android projects and reopening again helped!

Notify me when the script is done

Do you know the following situation ?
You’ve done some work and, before commiting, you switch to the shell in order to start the testsuite which usually runs a couple of minutes (blessed are those projects where it is not hours).
Now you got different choices what to do in the meantime. Sometimes i find me reading news and either completely forget about the running tests or i switch continoulsy back and forth between the browser and the shell. Both can be annoying, especially if you read news for 10 minutes and then find your testsuite failed after 10 seconds. What can help ? Proper Notification!

So here is a notification technique i assembled for my environment. Its based on mac, iterm and growl but it should be applyable to other unix environments as well. It simply fires a visual or audi-visual notification for every command which takes more then 10 seconds to complete when it is complete.

Setup Growl

Get Growl and ITerm, if you havn’t yet. Growl its an notification system which integrates with all kind of applications like Mail or Skype. Once you’ve installed growl, you can configure it through the growl preference pane in System Preferences. Enable general ITerm notifications and make sure the specialized iterm notification ‘Customized Message’ is enabled as well. You might want to add a sound to this notification as well.
(There are bunch of standard notifications for iterm but i have found none of these working very well for the described purpose, so i found me rather disabling most of them.)

Setup Bash

You can fire growl notifications right from the bash to growl (see this blog post). To easify this add the following line to your .bash_profile:

growl() { echo -e $'\e]9;'${1}'07' ; return  ; }

Now you can fire notifications from iterm simply by typing:

$growl "hello world"

The only missing logic can be crafted in two lines of the .bash_profile as well.
Set a trap which sets the startTime for a command once you execute one:

trap 'if [ ! -n "$initTrap" ]; then startTime=`date +%s`; commandName=${BASH_COMMAND}; fi; initTrap="true"' DEBUG

And set a prompt-command which will be executed once the executed command returns.

export PROMPT_COMMAND='if [ $? == 0 ];then exitCode='OK'; else exitCode='ERROR'; fi;now=`date +%s`; duration=`expr $now - $startTime`; startTime=$now; echo "took $duration sec, $exitCode";if [ $duration -gt 10 ]; then dir=`pwd`; growl "\n ${commandName} \ntook $duration sec \n $exitCode";fi; unset initTrap'

With these settings every command which takes longer then 10 seconds fires of an growl notification which may include a sound. You can adjust those 10 seconds however you want, practically i found them working very well!


BTW when completing this blog post i found a similar one, with even the same kind of introduction, funny… Question: why did i find that now ? Weeks after i put the above solution together with sweat on my face ? )

And this is how it could look like:

Follow

Get every new post delivered to your Inbox.