If you want to get started with Android development, you’ll need to setup some things like the SDK, an IDE and an AVD. In this post I will walk you through the setup of these things, creating a test project and getting the project running on the emulator. When you’ve done all that, you are ready for some Android development, which I will cover in future posts.
Download the Android SDK
First of all, you need to download the Android SDK. You can find on the Android developers site, in the SDK section. I’m using the mac x86 1.5 R3 version in this tutorial which is 175MB when writing this post.
When downloaded, extract the zip file (I recommend you do this in a folder you know will never move, like /programming/sdk) and we are finished with this folder for now.
Installing Ecipse and the Android Development Tools
I’m using Eclipse for most of my development and it looks like google did a great job on their Android Eclipse plugin, so that’s what we’ll use for our development.
- In order to use this plugin, we will need Eclipse itself. Download Eclipse for java developers from the Eclipse site. I recommend the Cocoa version.
- Extract the downloaded file into your /Applications folder and fire up Eclipse.app.
- In your application menu select: Help > Install New Software …
- Hit the Add button and give a name that makes sense (“adt” or “android development” tools for example). For location, enter https://dl-ssl.google.com/android/eclipse.
- When you push the Ok-button, Eclipse will load the the available components. Select Developers Tools (make sure the nested components are checked as well) and hit next.
- You’ll be presented with an overview of installations, just click next. Then accept the license and hit finish. Eclipse will now install ADT.
- Restart Eclipse.
- Now we need to let ADT know where he (or she) can find our SDK. Go to your preferences (windows: window > preferences. Mac: Eclipse > preferences).
- In the left panel, select Android (you might get a warning your SDK is not setup yet, but you can ignore that because that’s what we are doing now). Click browser and navigate to the sdk folder we extracted. This must be the root map you downloaded. The one with folders like tools and platforms in it.
Create an Android app.
Now that we have everything ready to go, it’s time to see if everything is set up correctly and create our first Android app.
- In your menu, select: File > New > Project.
- In the dialog that should pop up, select Android Project and hit Next.
- Now we can set some parameters for our new project. Give a name (“HelloAndroid” for example).
- Choose a build-target. Unless you have some specific needs, you should choose the lowest version possible. We’ll go for 1.1.
- Give an application name. This is the human readable name for your app.
- Give a package for your source to go. I’ll go for be.dimitrivanheucke.blog.android.helloandroid.
- Make sure Create an activity is checked. This will create a Class for us that is our main starting point. Call it HelloAndroid
- Your dialog box should now look something like this;
- Hit Finish and ADT will create your project
Testing your application
Before we can test our application, we need to create an AVD (Android Virtual Device). This will be used to present our application in the emulator.
- Open your terminal and go to the tools folder inside your downloaded SDK folder.
- To create an AVD we need to specify a target. To get a list of targets type;
./android list targets
The outcome should look like this;
Available Android targets: id: 1 Name: Android 1.1 Type: Platform API level: 2 Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P id: 2 Name: Android 1.5 Type: Platform API level: 3 Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P id: 3 Name: Google APIs Type: Add-On Vendor: Google Inc. Description: Android + Google APIs Based on Android 1.5 (API level 3) Libraries: * com.google.android.maps (maps.jar) API for Google Maps Skins: HVGA (default), HVGA-L, QVGA-P, HVGA-P, QVGA-L
- Now we can actually create our AVD. Type;
./android create avd --name myavd --target 3
Of course you can change the name (myavd) in whatever you like. I used target 3 so we can use this AVD for other projects as well (for example when we integrate Google Maps).
So we will have a 1.5 OS on our virtual device but we can run any application that targets that sdk version or lower.
We are done with terminal now, so we can go back to Eclipse.
- Now we are ready to test or application! Hit the run button in the toolbar at the top of your window and select Android Application in the Run As dialog that pops up. After clicking Ok your emulator should load and open your application. This can take a while, your emulator first has to install your application. You might have to unlock the screen first by clicking on the menu button at the bottom of your (android) screen.
If, like me, you get some errors on your console panel at the bottom of the window looking like this;
[2009-08-12 15:02:57 - HelloAndroid] no classfiles specified [2009-08-12 15:02:57 - HelloAndroid] Conversion to Dalvik format failed with error 1
You should go to the properties of your project (right mouse click on the project > properties), go to java build path and make sure Android 1.1 is checked in the Order and Export tab.
That’s all for setting up your environment and run a first test project.
I’m planning on doing some more of these but haven’t decided on the topics yet. So if you want to see something in particular, let me know in the comments. For the next one I was thinking about integrating Google Maps.