One of the best ways to learn when it comes to coding is to read source code. This especially applies when you’re dealing with a new language or a new platform. If you’re dealing with both a new language AND a new platform, well, you better be reading someone else’s source code (that works, of course).
When it comes to Android development, one of the best ways to start learning is to look at the APIDemos project that Google has graciously provided. This project, along with some other samples, can easily be installed following these instructions.
While trying to spin the APIDemos project up however, you might encounter an error that reads like the below.
I’ve gotten this error twice now, after I first imported the APIDemos project into a clean workspace that had been made aware of the Android libraries. While I was pretty sure I hadn’t specified anything related to “Dalvik format” or some such, I was extremely saddened to see that the project had failed to convert to said format with error 1. Funny – every time I see this error I’m reminded fondly of Dr. Who and his battles with the Daleks.
Turns out after some googling, the error is related to two copies of the Android libraries ending up on the build path. To find the build path, you have to open up the project’s properties.
Click on the Java Build Path node and select the Libraries tab.
Sure enough, looks like there are two references to the Android library on my path. How this happened, well, let’s leave that to Dr. Who to figure out. To fix my issue, I select the android.jar entry and click Remove followed by OK. Follow this up by cleaning the project (since I’m still firmly in the ranks of Eclipse n00bs, I’m including a screenshot).
After all of this, your project will have been cleansed and you can resume source code spelunking. Let’s just hope the Daleks don’t return in the next episode.