New Library: joda-time-android

I've just published a new Android library: joda-time-android. The readme explains why you might want it and how to use it. I wanted to go into detail on two topics I learned about while making it. While the library itself was a simple task (as most of it is imported from joda-time) I'd never before taken the effort to add tests or work on maven deployments before.

Testing

Tests were a key goal for this project. I wanted to verify that my additions to the codebase weren't mucking anything up, especially next time I need to update the joda-time code to a new version.

It turns out that testing a library on Android is tricky, especially if you're building it in the aar format. I originally tried using the maven-android-plugin to build the library and test it, but there's no way to directly test the library - I'd have to build an intermediary APK and test that. Not my cup of tea.

Gradle also has its problems as there is currently no good support for unit tests. That meant my dream of headless robolectric tests would not become reality.

Ultimately I bit the bullet and decided to use the Android Testing Framework with gradle (and an emulator). I assume that one day the gradle android plugin will support unit testing and in the meantime this proved the simplest solution.

Deployment

I decided on two release formats:

  1. The project would be in the form of a standard Android library. That way anyone using Eclipse/ADT can consume it.
  2. The project would be packaged as an aar. (I was able to skip the apklib format because maven-android-plugin supports aar now.)

Generating an aar is simple; just use the gradle plugin android-library. Uploading it to Maven Central so that you can easily pull in the library was a bit more tricky due to my inexperience. Ultimately, a few handy guides got me through it: