I’ve been looking for an excuse to write an Android app, and those annoying “unknown number” phone calls presented themselves at the perfect problem to solve.
My CallerID application consists of two parts: a service that runs on a server and given a phone number returns the information associated with it, and an Android app that uses the service to display information to the user upon request or when the phone rings.
exten => _., n, Set(CALLERID(name)=${CURL(http://callerid.integralblue.com/callerid.php?format=basic&num=${CALLERID(num)})})
The Android application is written in Java, licensed under the GPLv3, and is available on the Google Android Market and (hopefully) soon on the Amazon Market and f-droid. The Android app source code is also available on gitorious. The application requires at least Android 1.5 – and supporting Android 1.5 all the way to 2.3 was an interesting experience, especially in the area of the Contacts API. It uses OpenStreetMaps (osmdroid) for maps (instead of Google Maps, as not every device has Google Maps, and Google Maps is not Free Software) and roboguice as an application framework.
I initially built the app using ant, like most Android apps, but decided to switch to using Maven for a few reasons:
- Maven manages dependencies, so I don’t need to include large binaries in the source repository.
- Using a Maven multimodule approach, I can have a separate integration testing project (application-it) and application project (application), making automatic testing easy.
- I’ve used Maven for a number of projects in the past, and find it easy and sufficiently “magic” (but not overly so), compared to ant, which I find too “low level.”
- Maven automatically will run proguard (for optimization, not obfuscation), zipalign, and signing when given a “release” profile, or skip those steps when running under the default profile.
I used the maven-android-plugin as a key component of the build process. If you’re starting an Android project, I highly recommend you check it out.
- Install the Android SDK (you’ll need at least SDK versions 3 and 10)
- Set the ANDROID_HOME environment variable as described on the maven-android-plugin Getting Started page
- Install Maven (Windows and Mac installers are available for download, and it’s packaged for most Linux distributions)
- Install Git (Windows and Mac installers are available for download, and it’s packaged for most Linux distributions)
- git clone git://gitorious.org/callerid-for-android/mainline.git mainline
- cd mainline/application
- mvn clean install
- Since osmdroid is not in the Maven repository, you’ll need to manually install it. These directions can also be found in application/pom.xml:
- wget http://osmdroid.googlecode.com/files/osmdroid-android-3.0.3.jar
- mvn install:install-file -DgroupId=org.osmdroid -DartifactId=osmdroid -Dversion=3.0.3 -Dpackaging=jar -Dfile=osmdroid-android-3.0.3.jar
- mvn clean install (again) – it should succeed
The apk is located at “mainline/application/target/callerid-1.0-SNAPSHOT.apk”
These steps do not perform the integration tests. If you want to run those, in the step above that says “cd mainline/application” run “cd mainline” instead. Note that you’ll either have to have your Android phone plugged in to your computer (and running in debug mode, recognized by adb) or an Android emulator running.
To create a ready-to-release apk, which includes running proguard, zipalign, and jarsign, run this command from the “mainline” directory: mvn clean install -Prelease -Dsign.keystore=/home/candrews/projects/callerid/test-key.keystore -Dsign.alias=mykey -Dsign.storepass=testtest -Dsign.keypass=testtest Note that this command will sign using the test key. If you really want to distribute the apk, you’ll need to generate your own key using keytool. In either case, the ready to distribute apk is located at “mainline/application/target/callerid-1.0-SNAPSHOT-signed-aligned.apk”
If you want to develop the application using Eclipse, first make sure that you can successfully compile the application using the steps above. Then you need to install some Eclipse plugins:
- Select File-Import…
- Maven, Existing Maven Projects
- The Root Directory is the “mainline” directory you checked out from git
- Finish
- You should now have 3 projects in your Eclipse workspace: callerid, callerid-it, and callerid-parent
- For the “callerid” and “callerid-it” project, modify the Build Path by right clicking on the project, selecting “Build Path” then “Configure Build Path.” You need to remove “JRE System Library” and then click “Add Library” “Android Classpath Container” (see https://code.google.com/a/eclipselabs.org/p/m2eclipse-android-integration/issues/detail?id=41)
- That’s it – Eclipse should automatically build as you go, and you can use the Eclipse/Android development tools just as everyone else does.
I hope both the server portion and application portion are reasonably easy to run, build, and understand. If you have any questions or concerns, please comment – and contributions are of course very welcome to both projects!
Please note that this project is not in any way related to my employer – it is a completely personal, non-work project. This article has been cross-posted to Isobar’s blog.