How To: Android and Continuous Integration

I was impressed at how little overall pain was involved in configuring Hudson to automatically build android applications and test projects.

The android tools will generate build.xml files for ant if you use the command line tools to start, and are also able to create them after the fact (at of writing this, it worked for test projects created from inside eclipse), it’s just a matter of getting things setup in Hudson (our current preferred CI tool) to allow those android tools to work properly, and then running the proper bits and pieces through Hudson to have things do what you want/need them to do.

This assumes that the android tools are in your path (Windows or some *nix variant).

Android Application Basic Steps

  • We started with a clean Hudson install (to not mess up an existing one that is doing other things while we’re testing)
    • We tend to set HUDSON_HOME to something directly vs leaving it to default to a users home directory/temporary directory, it’s far better to keep it in a known location.
  • Add the ‘Android Emulator Plugin’
    • This makes it easy for creating emulators on the fly for your testing projects, versus having to fuss with creating one on every build machine/slave, or worry about issues if old ones get messed up.
    • From the Hudson configuration area, pull up the list of plugins, and then search for Android, the emulator plugin was (when this was written) the only one with Android in the name.
  • Add your android project
    • Hook it up to which ever SCCS you’re using (CVS/SVN/Git/Hg/etc), and decide on how you would like to trigger the build (YMMV with different SCCS options, at the very least you can build on a schedule.)
  • Add build tasks
    • Windows/Shell execution to let the android tools update the required files based on the current paths for the SDK, etc
      • android update project -p .
    • Ant build task
      • Targets: we’re using clean debug
    • Extra ANT flags required (Change to reflect your build machine/target platform):
      • sdk.dir=C:/android-sandbox/android-sdk_r06-windows
      • target=Google Inc.:Google APIs:8

Optional:

  • Trigger your test project to build after your main project completes (there’s more then one way to do this, choose your own adventure/configuration)

Test Project Basic Steps

  • Add your test project
    • Hook it up to what ever SCM you’re using
  • Configure Hudson to run an Android emulator during the build
    • I tend to lean towards creating a fresh emulator per build, that is a personal preference to avoid possible hanging issues from earlier builds, but there are benefits/drawbacks to either option.
  • Add build tasks
    • Windows/Shell execution to let the android tools update the required files based on the current paths for the SDK, etc
      • android update test-project -m <path-to-your-real-app-project-on-build-machine> -p .
    • Ant build task
      • Targets: we’re using run-tests
    • Extra ANT flags required (Change to reflect your build machine/target platform):
      • sdk.dir=C:/android-sandbox/android-sdk_r06-windows
      • target=Google Inc.:Google APIs:8

Optional:

  • Set Hudson to build this project after the main project completes (there’s more then one way to do this, choose your own adventure/configuration)

And that’s it! You’re ready to go with continuous integration builds on your Android applications and tests!

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply