Ack! This site is moving to tomhorsley.com since Comcast's efforts to improve their world's worst customer service ranking apparently include terminating web hosting for their existing customers.

Chapter 1 — Getting Started

I'm doing my development on a Fedora linux system and I still need to download lots of stuff just to have the command line tools for android programming. Since I need a place to put it all, I invent this place:

mkdir /zooty/andy
cd /zooty/andy

On the http://developer.android.com/sdk/index.html web page, I pick the linux SDK:

wget http://dl.google.com/android/android-sdk_r18-linux.tgz
tar xzf android-sdk_r18-linux.tgz

And now I have an android-sdk-linux directory.

In theory, I already have the Java openjdk from the Fedora repos, so that should be all the java stuff I need to get started.

The page http://developer.android.com/sdk/installing.html mentions the enviroment not to be named in many places, but I have trained my eyes to glaze over when they reach those parts of the page.

To see if this works so far, I do this:

cd /zooty/andy/android-sdk-linux/tools/
./android

This brings up a moderately confusing screen full of junk and after reading up some of the links on the google developer pages, I decide to download the Android 2.2 SDK and samples (since my phone is currently running 2.2) and the Android 4.0.3 SDK and samples (the latest released version). It also says I'll need the Android SDK Platform-tools, so I check that box.

One of the things I find confusing is that the 4.0.3 SDK offers system images for download (which the emulator will need to run), but the 2.2 SDK does not. Apparently sometime along the way they decided to make the system images separate. Turns out the image for 2.2 was downloaded along with the SDK already.

Anyway, at this point I need the SDK tools in my PATH in order to do any work with them, so I do this:

PATH="/zooty/andy/android-sdk-linux/platform-tools:$PATH"
PATH="/zooty/andy/android-sdk-linux/tools:$PATH"
export PATH

This is the point where most Android programming books seem to diverge into a long winded dissertation on the brilliance of the way Android projects work and why all the different xml and java files scattered to the four winds in a directory tree the size of the Forest of Fangorn makes so much sense, and why the Android programming model with the maze of multiple entry points into the programs you write is so magnificent.

I say: “Screw it!” — It works the way it works and you have to live with it if you want to do Android programming, so who cares if it is sublimely brilliant or utter nonsense? I don't want to justify it, I just want the shortest path from idea to working program.

Anyway, the closest I can get to a simple command line way to work with Android projects is described here: http://developer.android.com/guide/developing/projects/projects-cmdline.html

Let's try their example of project creation and see what we get:

android create project \
--target 1 \
--name MyAndroidApp \
--path ./MyAndroidAppProject \
--activity MyAndroidAppActivity \
--package com.example.myandroid

Which results in this amazing tree full 'o stuff that doesn't even actually do anything yet other than display a hello world message when it runs.

  • MyAndroidAppProject/
    • AndroidManifest.xml
    • ant.properties
    • bin/
    • build.xml
    • libs/
    • local.properties
    • proguard-project.txt
    • project.properties
    • res/
      • layout/
        • main.xml
      • values/
        • strings.xml
    • src/
      • com/
        • example/
          • myandroid/
            • MyAndroidAppActivity.java

Having created the stub project forest, this web page describes how to build: http://developer.android.com/guide/developing/building/building-cmdline.html

So let's type:

cd MyAndroidAppProject
ant debug

and see what happens...

Looks like it spews a vast amount of gibberish to the screen and leaves MyAndroidApp-debug.apk in the bin subdir (along with a lot of other junk). I guess it worked.

So, now you want to see this thing run. Poking around on the developer web pages once again, I find these things to do:

android avd

I then click “New” and tell it to make an emulator instance running the 2.2 version which I give the name “Andy2.2”

I'm done with that tool now and can exit.

Now I can run the emulator:

emulator -avd Andy2.2 &

That actually brings up the emulated Android 2.2 device (slowly) and I get a screen full of the built in apps in the launcher.

Now for the fun part:

adb install bin/MyAndroidApp-debug.apk

And like magic (or not always magic since I sometimes have to try several times before it works), the new icon for my new app appears in the emulator window, and if I run it, I get a screen that says

Hello World, MyAndroidAppActivity

A string which you will find in the res/layout/main.xml file.

You can even change it, rebuild the app, and reload it in the emulator and see the error that says it is already installed :-).

So then you can go into settings and manage applications and uninstall it, then reload it and see the new string.

If you are through with all this for a while, you probably also want to do:

adb kill-server

so the debug server doesn't keep running forever.

 
[Next] [Top] [Prev]  
Page last modified Sat Jun 16 22:49:58 2012