Google Android
Running Android SDK Examples Using Eclipse
February 25, 2010
0

The Android SDK comes with several very nice examples.  Here’s a short guide on how to compile and run them.  This tutorial is intended for Eclipse begginners who are already familiar with programming.

This assumes you have Android SDK and Eclipse already set-up, following this previous tutorial.

    1. Start Eclipse.  If you see the welcome screen, like below, close it (using the X icon next to the word Welcome).
      az40
    2. Select this menu: Window->Open Perspective->Other.  A Window like below should appear.  Select Java (default) since Java is the language used by Android SDK.
      az63
    3. Select this menu: File->New -> Project, a dialog like below should appear, then select Android->Android Project.
      az58
    4. This dialog will open.  This is the place to create a new project, but in this tutorial, we are not going to create a new project.  Instead, we will be importing one of the Android example projects.
      az60
      If you don’t see Android 2.1 listed, check the previous tutorial.  Select Create project from existing sample in the Contents section.
    5. Now, from the Samples pulldown menu, select which sample you want to compile.  For this example, let’s chose Lunar Lander.  (Note: If the pulldown is grayed out or it doesn’t allow you to select a Sample project, make sure to click/check the checkbox under the the Build Target section again.)
      az60-copy

The project name is automatically filled for you, but you can change it if you want.

  1. Next, you can click Finish.
  2. The project should be created and you should see the Project name on the Package Explorer Window.  You can expand the list by clicking the rectangle.  Files should be listed like below.
    az64If you don’t see the Package Explorer window, go to menu: Window->Show View->Package Explorer.
  3. Select Run->Run Configurations… Select the Target tab.Check and make sure the Virtual Device you created in the previous  tutorial is listed.  This device is an emolator that will run the application.  I suggest selecting Manual so that you can select devices before the app runs.
    az67
  4. Select menu Run->Run.  A window like below should appear.  Select Android Application, then click OK.  The application should start
    az66
    If you have Manual set in the Run Configuration, the you might see a window like below.  If you have an actual phone hooked up, you should be able to select it too in the Choose a running Android device.  Select a Virtual Device or an actual device here (don’t worry if you don’t see as many devices in the Virtual Device section, the list depends on how many AVD you have created.az68
  5. For some reason, the Android simulator is slow to start, so before you conclude that something is wrong, wait — I have experienced it starting up as slow as 1 minute.  However, you should pay attention to the Console window in Eclipse (Window->Show View->Console), you should not be getting any error.  The log may be similar to below:
    [2010-02-25 22:03:37 – LunarLander]——————————
    [2010-02-25 22:03:37 – LunarLander]Android Launch!
    [2010-02-25 22:03:37 – LunarLander]adb is running normally.
    [2010-02-25 22:03:37 – LunarLander]Performing com.example.android.lunarlander.LunarLander activity launch
    [2010-02-25 22:03:37 – LunarLander]Automatic Target Mode: launching new emulator with compatible AVD ‘FPTestDevice’
    [2010-02-25 22:03:37 – LunarLander]Launching a new emulator with Virtual Device ‘FPTestDevice’
    [2010-02-25 22:03:39 – Emulator]### WARNING: SD Card files must be at least 8 MB, ignoring ‘/Users/ferrypermadi/.android/avd/FPTestDevice.avd/sdcard.img’
    [2010-02-25 22:03:43 – LunarLander]New emulator found: emulator-5554
    [2010-02-25 22:03:43 – LunarLander]Waiting for HOME (‘android.process.acore’) to be launched…
    [2010-02-25 22:03:44 – Emulator]2010-02-25 22:03:44.422 emulator[28109:903] Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz.
    [2010-02-25 22:04:22 – LunarLander]WARNING: Application does not specify an API level requirement!
    [2010-02-25 22:04:22 – LunarLander]Device API version is 7 (Android 2.1)
    [2010-02-25 22:04:22 – LunarLander]HOME is up on device ’emulator-5554′
    [2010-02-25 22:04:22 – LunarLander]Uploading LunarLander.apk onto device ’emulator-5554′
    [2010-02-25 22:04:22 – LunarLander]Installing LunarLander.apk…
    [2010-02-25 22:04:38 – LunarLander]Success!
    [2010-02-25 22:04:38 – LunarLander]Starting activity com.example.android.lunarlander.LunarLander on device
    [2010-02-25 22:04:43 – LunarLander]ActivityManager: Starting: Intent { cmp=com.example.android.lunarlander/.LunarLander }
    Here’s how the app looks in the simulator (if you see the lock screen, slide the lock to the right using the mouse.
    az65