Android Logo MathCS.org - Android

Setting up the SDK and Dev Phone

java -> android -> setting up ...

There are several real existing devices that run on Android; at least two are available through T-Mobile in the US (the G1 and the MyTouch 3G); other carriers have added their own Android devices - the list is growing.

In addition, some devices such as the G1 are available in an unlocked developer's edition that can run on any SIM and can run your own applications directly. It does cost $399, there is a limit of one per developer, and you need to register as an Android developer with Google (which is free). If you got such a developer's phone, here are some tips for setting it up.

But you do not necessarily need a developer's phone, or for that matter any Android phone. You can develop your entire program using a software emulator that is included in the free software developer's kit - but it helps to have access to a real device.

Setting up the SDK

First you need to setup the SDK, if you haven't already. You can get it from the Android Developer's site at http://developer.android.com/ - just follow the instructions carefully. Be sure to install Eclipse with it, including the ADT plugin. If all goes well, you can write your first Android program as described later, but first you need to setup the "Android Virtual Device (AVD)", i.e. the Android emulator which allows you to run Android programs without a physical Android device.

Setting up the AVD (Emulator)

Before you can run the program on the emulator, you need to create an Android Virtual Device.

  1. Open a command-line (e.g.,"Command Prompt" application on Windows, or "Terminal" on Mac/Linux) and navigate to your SDK package's tools/ directory.
  2. You need to select a Deployment Target. To view available targets, execute:
    android list targets

    This will output a list of available Android targets, such as:

    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: QVGA-P, HVGA-L, HVGA (default), QVGA-L, HVGA-P
    

    Find the target that matches the Android platform upon which you'd like to run your application. Note the integer value of the id — you'll use this in the next step.

  3. Create a new AVD using your selected Deployment Target. Execute:
    android create avd --name <your_avd_name> --target <targetID>

    where you could use for example my_avd for the name and 2 for the target id.

  4. Next, you'll be asked whether you'd like to create a custom hardware profile. If you respond "yes," you'll be presented with a series of prompts to define various aspects of the device hardware (leave entries blank to use default values, which are shown in brackets). Otherwise, press return to use all default values ("no" is the default).

That's it; your AVD is ready and can be used when launching your application on an emulator. To learn more about creating and managing AVDs, please read the Android Virtual Devices documentation.

Android SDKSetting up the Developer's G1

The first thing you have to do when you get your G1 (developer's or retail version) is to sign in to your Google account. If you don't have one, you need to create one (preferably with a PC). Signing in, however, turned out to be tricky for me:

So my device was useless - it does nothing but ask you to sign into Google first. Fortunately I found instructions for temporarily suspending the Google login request and to configure Wi-Fi on the device to first connect to my home network (so that I can then sign in to my account):

After connecting through Wi-Fi I could sign in to Google and I was all set. Except that the device came with Android 1.0, so I had to upgrade it to Android 1.5/1.6 or the latest version as described here.