Saturday, January 30, 2010

Writing Your First Android App: HelloWorld

Most first time Eclipse users will be wondering how to create their first Android project. This tutorial will give you the steps on how to.

Creating Android Project
  1. Launch your Eclipse, if you haven't already.
  2. Click on File -> New -> Other... or simple press Ctrl + N on your keyboard.
  3. Toggle Android then select Android Project then click Next.
  4. Specify the following:
    • Project name: HelloWorld
    • Build Target: Android 2.1
    • Application name: HelloApplication
    • Package name: org.droidtutorials
    • Create Activity: HelloActivity
  5. Click Finish to create the project.
Correcting the X mark
  1. If you get this X mark on your project folder, do this extra step.
  2. Go to Project -> Properties.
  3. Click Apply, then click OK to close the Properties dialog.
  4. The X mark should be gone now.
Compiling and Testing HelloWorld
  1. Click Run -> Run or simply press Ctrl + F11.
  2. Select Android Application then click OK.
  3. Wait for your emulator to initialize so your App will be installed and running. Below shows the stages that the emulator goes to before finally loading your HelloWorld application.


If you could notice, I have waited at least 3 minutes to finally see my app running on the emulator.

That's it for now. Next part, we will discuss the files of a default project.

How to Setup Development Environment

Downloading the Tools.
  1. Download Android SDK r4.
  2. Download Eclipse Classic 3.5.1.
  3. Download Android Development Tools 0.9.5.
Installing the Tools.
  1. Extract the SDK at your root directory (ex: C:\)
  2. Extract Eclipse and run eclipse.exe
  3. On Eclipse, click Help -> Install New Software.
  4. Click Add... button, Add Site dialog will pop-up.
  5. Click Archive... button and browse for then click OK.
  6. Specify ADT as Name then click OK.
  7. Toggle-on Developer Tools then click Next to install.
  8. Now set the path of the SDK. Click Window -> Preference. Select Android, and set the SDK Location to: C:\android-sdk-windows, then click OK.
    Installing the Android API.
    1. With the SDK path set, click Window -> Android SDK and AVD Manager.
    2. Select Available Packages. Then toggle-on the following:
      • Documentation for Android 2.1, API 7, revision 1
      • SDK Platform Android 2.1, API 7, revision 1
    3. And optionally, toggle-on:
      • Google APIs by Google Inc., Adroid API 7, revision 1
      • Usb Driver package, revision 3
    4. Click Install Selected then accept the license and click Install Accepted.
    Creating Android Virtual Device (AVD or what we call Emulator).
    1. Again, click Window -> Android SDK and AVD Manager.
    2. Specify the Name (ex: MyAndroidEmulator)
    3. Choose Android 2.1 - API Level 7 as the Target.
    4. On Hardware, click New and OK repeatedly until all Properties has been added.
    5. Click Create AVD.
    Now you can start writing Android Apps!