News & Info

Daily Updates and Tech Chatter

Setting Up For Android Development

I woke up a little before four in the morning and could not go back to sleep, so I decided to start working on a framework for hone quiz applications we talked about yesterday, tentatively known as A Quiz and Teaching Environment: a.k.a. “AquaTeen”.

My development came to a grinding halt because I need the sun-java6-jdk package, which I can’t get until I get to the office. Even if I could connect to the Internet right now, my connection here is slow, and that package is anything but small.  It would not finish downloading between now and then anyways.

In the mean time, here’s how I got up and running doing Android development.

1. Get the latest Java SDK.

2. Go to the Android development site and download their dev kit for your appropriate operating system.  It is a zip file around fifteen megabytes in size.

3. Unzip that file to wherever you want to store the Android tools.  On Windows I imagine this is an installer that you will be running.

3.a. If you are on Linux then I suggest making these tools available via $PATH.  For example, I installed everything in ‘/home/eric/Software/Android’.  So then I tacked that directory on to the end of my $PATH, by putting this in my Bash configuration

PATH=$PATH:/home/eric/Software/Android/tools

which lets me run the Android tools from any directory.

4. That dev kit will have a tool called ‘android’.  Run this, and you will see a GUI package manager for the Android platform.

4.a. I had to go into Settings and tell it to fetch packages over ‘http’ instead of ‘https’.

5. Refresh the package list and check off the things you want.  I installed the latest 2.1 documentation and SDK.  Then let the manager install those tools.

Then you will have all the tools you need.  Now you have to setup your development environment.  Out of the box, Android provides support for two IDEs: Eclipse and Emacs.

* Eclipse :: There is an ADT plugin that comes with the Android platform for creating Android projects and integrating with tools like the emulator.  I did not go down this route (imagine that) but it sounded simple enough to set up.  I believe you will need Eclipse 3.5 for this, which you should have anyways if you use Eclipse.

* Emacs :: In the place where you installed Android you will find a file ‘/tools/libs/android.el’.  Put this wherever you store
your Emacs libraries and (require 'android) in your Emacs configuration.  I also recommend finding ‘android-mode.el’ by R.W. van ‘t Veer and loading that as well.  It provides an Android minor-mode that let’s you spawn off things like the
emulator and debugger out of Emacs.

For development you will need an Android Virtual Device, or AVD.  You can create these using the same package manager mentioned above.  At a minimum you will need one of them, although you can create as many as you feel like.  Keep track of the name of the main one you want to use.  In Eclipse and Emacs you can designate a default AVD to use for testing.  In Emacs this is done by setting the value of android-mode-avd.  I suggest just doing this by running Customize, i.e.

M-x customize-group <RET> android

But if you wanted to put it in your config file, or a special Android config, you can write something like:

(setq android-mode-avd "MasterShake")

Once you’re environment is setup you can create a project.  I already made one for the AquaTeen project and put it into version control, so that one can simply be cloned.  But here’s how you create new projects from scratch.

1. Find out what platform versions you can target by running:

$ android list targets

You will probably only see one result.  You will need the target ID number.

2. Run the ‘android’ tool to create the project.  Here is what I did, then I’ll explain the parameters:

$ android create project     \
--target 1                 \
--path ~/Projects/AquaTeen \
--activity Quiz            \
--package com.cybersprocket.aquateen

The target is the ID of the platform you got from the first step. The path is where you want to create the project.  In that directory Android will create all the stub files you need to get up and running.  The package is the namespace you want to use for code on this project.  These things are straight-forward.

The activity is the name of the activity class you want to use, and requires the most explanation.

Android applications do not have a single-entry point.  That is to say, there is no ‘main()’ method anywhere.  One Android application can re-use parts of another Android application (if that other app allows it).  This makes it possible to re-use things like UI elements across different apps.  This is accomplished via “activities”.  Each activity in an application is responsible for providing some aspect of user interaction.  If you application lets the user do multiple things, those are all represented by separate activities, and each activity can be the starting point for running the application.

When creating a new project you provide the name of an activity, because you at least need one.

If all is right in the world, with all of this done you can go into your project directory and run:

$ ant debug

Or in Emacs ‘C-c C-c c’ to compile the project.  But that’s where I ran into the problem of not having the Java 6 JDK, so I can’t help you beyond that point.

Tags: , ,

1 Awesome Comments So Far

Don't be a stranger, join the discussion by leaving your own comment
  1. Rakotomandimby
    September 29, 2010 at 2:31 AM #

    As far as I only use Emacs (and hate Eclipse), it’s good to know that.