Wednesday, 31 August 2011

Up and Running With Android Development on Windows

I made a bold statement at a team meeting the other day that you could go from a vanilla windows installation to writing a “hello world” application for android in an hour.
Providing you've a half decent internet connection, here's what you need to do.

1. Install Java

We’re going to develop our app using Java so we need to install the Java SE Development Kit 7  (choose your platform) and download it. Install it using the default options.

2. Install Eclipse

Eclipse is the development IDE we’ll use to develop our app in. (Note to all the Visual Studio users: “We’re through the looking glass here people! Just go with it. It’s fine….”)

Browse to the Eclipse download page and select “Eclipse Classic”.It doesn’t have an installer, it can be simply unzipped and ran so extract the contents of the zipped folder to your "program files" folder. It's nearly 200mb so takes a while to unzip though! Create a shortcut of the Eclipse.exe file on your desktop, then you're good to go.

3. Install the Android Software Development Kit

Download the Android SDK and install it.

NB There is currently a spooky bug in the Android SDK installer: When you install the SDK, you may come across one the wizard screens saying "Java SE Development Kit (JDK) not found".

AndroidSdkSetup_2

Providing of course that you have installed the Java SDK(!), to get round this you need to simply hit the back button, then "Next" again, and the wizard will say its now been found!

AndroidSdkSetup_3


Hit “Next” and select the default destination folder for the Android SDK then continue with the installation. When you reach the end of the wizard, ensure the Start SDK Manager check box is ticked then hit finish:

AndroidSdkSetup_5

This will then fire up the SDK Manager app, allowing you to choose the platform images you wish to download. I just went with the default platforms for the time being. It did take a while to download so please be patient:

You may get a message come up asking you if you want to restart the ABD. Hit “Yes” and you're almost done.

ABD_2

When the packages are installed (above), hit "close" then close down the Android SDK manager. We'll carry on with the configuration from within eclipse now.

4. Configure Eclipse for Android Application Development

Fire up eclipse and select a default workspace.

You know need to install the Android Development Tools(ADT) Plugin. Follow the instructions at http://developer.android.com/sdk/eclipse-adt.html to do this.

After you've restarted eclipse, you need to manually set the location of the Android SDK.

  1. Select Window > Preferences then in the left hand list, select "Android".
  2. Browse to the location of the SDK location we downloaded earlier and hit "Apply". You'll see the SDK target list populate.

NB: There is a bug in how the path to the Android SDK is resolved. If you have installed the SDK to “C:\Program Files (x86)\Android”, you need to enter “C:\Progra~2\Android\android-sdk” if you’re installing to a 64-bit machine or “C:\Progra~1\Android\android-sdk” if your installing to a 32-bit machine:

SDK_Path_Bug2

…more on this issue can be found on Stack Overflow.

5. Adding a Virtual Android Device

Tool_Bar_AVD_Button

When we're developing android applications, we'll want to test them locally before deploying them to a device. To do this, we'll need to create a virtual device that we will run our app on:

  1. Click on the AVD Button (above) on the eclipse toolbar and create a new Virtual Device, imaginatively called "TestDeviceOne".
  2. Select a target O/S of "Android 2.2 - API Level 8" and SD Card size of 1 GiB

It'll take a couple of seconds to create the device but then it should appear in the device list as so:

AVD_Manager_1

6. Creating a Hello World project

Tool_Bar_NewProject_Button
Just to get up an running, we'll start a new Android Project from the toolbar (above) and call the project HelloWorld and select the Build Target as Android 2.2. and we’ll enter a package name of com.helloworld.demo

Tool_Bar_Run_Button

Hit the "Run As" (above) button and select "Android Application" as the way to run the project.

The virtual device will now spin up and load your Hello world app. (NB The virtual device takes a while to get going, but you can keep it open once it's running while you work on your app).

There you have it. More “Hello Worlds” than a Wrox Demo…!

HelloWorld

Let me know if I’ve missed anything out or if you managed to get the process done in less than an hour!

3 comments:

  1. Less than an hour? You're joking, right? I managed to do all this in the end, but it took me hours to work through all the niggles. This page needs to become the canonical reference on the internet for getting started with Android development. I tried installing the J2EE JDK first but got that bug, so uninstalled and tried another one before I got it to work. Probably would've been okay with the J2EE one in the end. Oh well. I also wasted another hour uninstalling everything from "\program files" and re-installing in C:\Java to get around that unquoted path bug in step 4. I hope this turns out to be worth the hassle...

    ReplyDelete
  2. That's why I posted this, as it only takes an hour if you know about the bugs, niggles and the order in which to install the different facets that make up the development environment.

    Otherwise you might get fed up and go and develop for another platform instead!

    ReplyDelete
  3. Nice post Martin. Apart from the unbelievably slow Archive downloads I was up and running in quite a short time. I reckon less then an hour if you strip out the slow downloads!

    ReplyDelete