Wednesday, January 6, 2010

Android development: creating an AVD and a project

The next steps in learning about Android are to try to follow the HelloWorld tutorial. The first parts of this involve creating an AVD, and creating a project.

An AVD is an Android Virtual Device. The Android SDK comes with an emulator, which can emulate a variety of actual Android devices on your development computer. So, I created a simple AVD for use in my HelloWorld example:


C:\bryan\src\android\learning>android create avd --target 1 --name simple_avd
Android 2.0.1 is a basic Android platform.
Do you wish to create a custom hardware profile [no]
Created AVD 'simple_avd' based on Android 2.0.1, with the following hardware config:
hw.lcd.density=160


I appear to have created something with a Liquid Crystal Diode screen with a screen density of 160.

Then, I created a project in which to develop my HelloWorld code:


C:\bryan\src\android\learning>android create project --target 1 --name HelloAndroid --path ./HelloAndroid --activity HelloAndroid --package com.example.helloandroid
Created project directory: C:\bryan\src\android\learning\HelloAndroid
Created directory C:\bryan\src\android\learning\HelloAndroid\src\com\example\helloandroid
Added file C:\bryan\src\android\learning\HelloAndroid\src\com\example\helloandroid\HelloAndroid.java
Created directory C:\bryan\src\android\learning\HelloAndroid\res
Created directory C:\bryan\src\android\learning\HelloAndroid\bin
Created directory C:\bryan\src\android\learning\HelloAndroid\libs
Created directory C:\bryan\src\android\learning\HelloAndroid\res\values
Added file C:\bryan\src\android\learning\HelloAndroid\res\values\strings.xml
Created directory C:\bryan\src\android\learning\HelloAndroid\res\layout
Added file C:\bryan\src\android\learning\HelloAndroid\res\layout\main.xml
Created directory C:\bryan\src\android\learning\HelloAndroid\res\drawable-hdpi
Created directory C:\bryan\src\android\learning\HelloAndroid\res\drawable-mdpi
Created directory C:\bryan\src\android\learning\HelloAndroid\res\drawable-ldpi
Added file C:\bryan\src\android\learning\HelloAndroid\AndroidManifest.xml
Added file C:\bryan\src\android\learning\HelloAndroid\build.xml


There are places in the project for resources, binaries, and libraries. I'm not sure what the acronyms HDPI, MDPI, and LDPI stand for, yet, but I'll guess that H=High, M=Medium, and L=Low.

A sample Java source file is automatically generated, and an Ant build script is generated. Following the instructions, I edited HelloAndroid.java as described, then ran ant debug to build my project, and then ant install to install my project into my emulator (oh yeah I had to start the emulator).

Then, in the emulator, I saw my HelloAndroid app, and I clicked on it to run it, and it printed Hello, Android to the screen!

I have successfully completed the HelloWorld tutorial. Yay!

No comments:

Post a Comment