'

Getting started with Android

In a couple of years, Android is expected to be powering millions of cell phones, making it a major platform for application developers. Whether you're a hobbyist or a professional programmer, whether you're doing it for fun or competing for the Google $10 million developer prize, it's time to learn more about developing for Android. This article will help you get started.

Getting started with Android

Android is the new mobile phone SDK created by Google and the Open Handset Alliance. In a couple of years, it's expected to be powering millions of cell phones, making Android a major platform for application developers. Whether you're a hobbyist or a professional programmer, whether you're doing it for fun or competing for the Google $10 million developer prize, it's time to learn more about developing for Android. This article will help you get started.

[ Read: More coverage of Android ]

Installing First you need a copy of Java. All the Android development tools require it, and programs you write will be using the Java language. JDK 5 or 6 is required. It's not enough to just have a run-time environment (JRE); you need the full development kit.

Next, download the latest Android SDK from Google. The Android download page has packages for Windows, Mac OSX, and Linux. After downloading the SDK, unpack the .zip file to a suitable location (for example C:\Google). By default the SDK will be unpacked into a subdirectory like android_sdk_windows_m3-rc37a. This is your SDK install directory; make a note of the full path so you can refer to it later.

To make development easier, Google has written a plug-in for Eclipse called the Android Development Tools (ADT). To use it, you need to have Eclipse 3.2 or later. Get the Eclipse IDE for Java or Java EE Developers, or the Eclipse Classic (SDK) package from the Eclipse download page if you don't already have it. Then start Eclipse and use the Update Manager to install the Android plug-in. Restart Eclipse, and update your Android preferences (Window > Preferences > Android) to point to the SDK install directory.

Note: Plug-ins for IDEs other than Eclipse are in the works so if you can't use Eclipse, keep an eye out for them at your IDE's community site. Since Eclipse support is the most mature, and it's used by the Google developers themselves, the rest of this article will assume you are using Eclipse and the ADT plug-in.

Once everything is installed it's time to write your first program.

Hello, Android Select File > New > Project to open the New Project dialog. Then select Android > Android Project and click Next. Enter the following information:

Project name: HelloAndroid Package name: org.example.hello Activity name: Hello Application name: Hello, Android

when you're done it should look something like this:

New Android Project

Click Finish. The Android plug-in will create the project and fill it in with some default files. Eclipse will take care of building and packaging it up. All that's left is to try running it.

In the Package Explorer, right-click on the HelloAndroid project, and select Run As > Android Application. The Android Emulator window will start up and boot the Android operating system. The first time you do this it will take a while, so be patient. After about 30 seconds or so, your program will be launched and you should see it running in the emulator:

Android Emulator

Just to prove we can, let's change the text displayed in this application. Leave the emulator window up and go back to Eclipse.

The user interface for Android programs is normally described in text files very similar to HTML. Under the res/layout directory, double-click on main.xml. Find where it says "Hello World, Hello" and change it to say "@string/greeting". This is a reference to a string resource that doesn't exist yet. To define it, double-click on res/values/strings.xml and add this line:

<string name="greeting">Android rocks!</string>

Now save all the files (Ctrl+Shift+S) and re-run the program (Ctrl+F11). In a couple of seconds, the Emulator screen will refresh and show the new text you entered.

Emulator showing new text

Note: You may notice something wrong with the exclamation point as displayed in the emulator. I'm sure little problems like that will be worked out soon. This is, after all, pre-release software.

Next steps The Android SDK comes with hundreds of classes you can use for telephony, animation, music, video, networking, geo-location, and more. Google provides extensive documentation and reference information on their web site, and a number of sample applications are included with the SDK. There is also a FAQ and a forum especially for beginners.

But before delving into that, I recommend you take half an hour to watch a few videos from the Android Developers Channel on YouTube. In particular, there's a 3-part series of educational videos by Mike Cleron (technical lead for Android) that should not be missed. Once you grasp the basic concepts like Intents and Activities, the rest will be much easier to understand.