Setting up the SDK and Dev Phonejava -> 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.
- Open a command-line (e.g.,"Command Prompt" application on
Windows, or "Terminal" on Mac/Linux) and navigate to your SDK
- 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.
- Create a new AVD using your selected Deployment Target.
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.
- 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.
Setting 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:
- you need a SIM card with a data plan (the one from my previous phone didn't)
- you need data-grade cell reception (I don't get that at home)
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):
- You need to set up ADB for this to work. It should be installed as part if the Android SDK but you could check here if you have problems.
- Plug in the phone via USB cable andopen a command line prompt
- At the command prompt, enter "adb shell" to log into the
phone, then at # enter:
am start -a android.intent.action.MAIN -n com.android.settings/.Settings
This should bring up the Wi-Fi settings dialog. Configure Wi-Fi, press Back and proceed with registration as usual.
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.