Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

View RSS Feed


Setting up a workstation for Android development (without an IDE)

Rate this Entry
Hi! My name is Chris and I love to program. This is the first of what I hope will be many blog entries on Android development. At times, the content may appear scattered like I have A.D.D. or something. That is because I will be adding things as I work; links, snippets, etc (who am I kidding, I just smoke too much pot). This is not a tutorial, I will not hold your hand and lead you towards enlightenment. Think of this more like breadcrumbs I leave along the path to becoming a brilliant Android developer (*suddenly the floor cracks open and yet another over confident programmer gets sucked into the void*).

Let's get started
Firstly, we need to download a few things and get our workstations speaking the same language. At the time of writing (January 2012) the latest JDK is 7_u2 and the Andoird SDK is r16. I am using Windows XP 32 bit.

In addition to this, we will also need a Webserver (I am familiar with Apache, but it doesn't matter what you use). It is also a good idea to get the latest version of ANT and some kind of version control software (I like GIT, but again it doesn't really matter). The windows installer for GIT comes with MingW, but I also installed CygWin. Also, because I am brave I use VIM for my text editor.

As you are installing the SDK's, bear in mind that at some point you are going to have to pay attention to your systems PATH. Past experience has taught me that using the default install locations ie C:\Program Files\jdk1.7.0_02 is a *really* bad idea. The reason is that the windows command prompt sucks. It hasn't changed much in the last 20 YEARS!!. Back in the old DOS days you couldn't use spaces in filenames or directories. At some point they realized people did not like this and added the functionality for spaces in filenames but they only bodged up the command prompt with a quick fix (since by now we had Windows 3.1 and they figured nobody would use it any more) so it is pretty hard to work with. If you followed my advice on GIT you will now have a MingW console (which is much better) and Cygwin is even better. But you still need to play nicely with the ancient command prompt. For this reason; here is where I install my SDK's:

  • E:\jdk1.7.0_02
  • E:\android-sdk
  • Yours may be different, just avoid spaces and make note of where things live

Grab yourself a cup of coffee and then take a gander at the readme files. Browse around the directories to get a feel for things.

Now later on we need to set up a few environmental variables to make life easier. For now, just make a note of where the home directories are.

  • JAVA_HOME E:\jdk1.7.0_02
  • ANT_HOME E:\apache-ant-1.8.2
  • ANDROID_HOME E:\android-sdk
  • GIT_HOME E:\Git
  • VIM_HOME E:\Vim\Vim73
  • CYGWIN_HOME E:\cygwin
  • HT_DOCS E:\Apache\Apache2\htdocs

(http://localhost points to the contents of this htcos folder when apache is running. So does my phone through wifi by using my workstations ip address - cool huh)

Actually, now I have gone and done it; mentioned the phone. I have a HTC Desire running Android 2.2. You don't technically need a phone for android development but in a lot of ways you will be running around in the dark without one. At the least, you will be running around in slow motion because as you will see, the emulator can be very slow. While the phones can be expensive, but I consider them to be an invenstment in my hobby as a programmer because they are a powerful and flexible computer in their own right.... Dammit am I rambling again?

Crank up the Android SDK manager and take a look at this pie chart illustrating which versions people are using. It's a balancing act here between giving your program the latest features while targeting the most number of people who can actually use your program. I am targeting 2.2. So go ahead and download all the items under 2.2 plus the core ones. At the time of writing this cuts a 1/8th wedge of users out of the pie ... hmmm pie.

Would you shut about pie already and run this in the command prompt.
echo %PATH%
blah blahs ablhalhs blah blahs blahs

It will return a heap of crap directories. That's what all the blah blahs are. It's probably rubbish right now because we haven't fixed it. Before we do, it's worth making a copy incase we mess it up.... Yep that's right, ctrl-c won't work. You gotta right click the prompt, click mark, drag a square over the output, then press ENTER for some reason and finally, manually delete all the newlines in a text editor (*finishes bashing head against keyboard for a while*). I did mention that command prompt sucks didn't I.

Setting it up
At this point I was less than enthusiatic about arguing with the command prompt about how I wanted to set up the environment but luckily for me, cygwin finished installing.

Go to your home directory in cygwin: E:\cygwin\home\Chris and open up the file .bashrc. This is the configuration file that gets run every time cygwin runs. You set up your environmental variables like so:
export VIM_HOME="/cygdrive/e/vim/vim73"
export JAVA_HOME="/cygdrive/e/jdk1.7.0_02"
export ANDROID_HOME="/cygdrive/e/android-sdk"
export GIT_HOME="/cygdrive/e/Git"
export ANT_HOME="/cygdrive/e/apache-ant-1.8.2"
export HT_DOCS="/cygdrive/e/Apache/Apache2/htdocs"
export PATH="/usr/local/bin"
export PATH="/usr/bin:$PATH"
export PATH="$JAVA_HOME/bin:$PATH"
export PATH="$JAVA_HOME/jre/bin:$PATH"
export PATH="$ANDROID_HOME/tools:$PATH"
export PATH="$ANDROID_HOME/platform-tools:$PATH"
export PATH="$ANT_HOME/bin:$PATH"
export PATH="${HOME}/bin:${PATH}"
export PATH="$PATH:."

Check that everything is accessable:
Chris@chris ~
$ javac -version
javac 1.7.0_02
Chris@chris ~
$ java -version
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode, sharing)
Chris@chris ~
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Chris@chris ~
$ git --version
git version

Now for the fun stuff:
Chris@chris ~
$ android.bat list targets
Available Android targets:
id: 1 or "android-8"
     Name: Android 2.2
     Type: Platform
     API level: 8
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
     ABIs : armeabi

Time to create a new project called MyFirstAndroidApp using 'android-8' as the target.
Chris@chris ~
$ mkdir MyFirstAndroidApp
Chris@chris ~
$ cd MyFirstAndroidApp/
Chris@chris ~/MyFirstAndroidApp
$ android.bat create project --target "android-8" --name MyFirstAndroidApp --path ./MyFirstAndroidApp --activity MyFirstAndroidApp --package com.lowware.myfirstandroidapp

That last code creates the project structure and a heap of files. Now build the project like so:
Chris@chris ~/MyFirstAndroidApp/MyFirstAndroidApp
$ ant debug

Now we need to create a virtual android device for our emulator. Open up the Android virtual device manager and create a new device. I like to be really specific with the name of the device since later on I may need to test my apps of a variety of configurations (a good programmer looks after their users). I called my device android22_hvga_480x800_32mb.

Now lets crank up the emulator:
Chris@chris ~/MyFirstAndroidApp/MyFirstAndroidApp
$ emulator.exe -cpu-delay 0 -no-boot-anim -avd android22_hvga_480x800_32mb -sca
le 150dpi &
[1] 4684

The apersand at the end makes it run in the background. Just remember not to close the prompt or it will be killed. All those extra flags reduce the loading time but the emulator can be very slow at times. Give it a few mintues if it doesn't seem to be doing much.

Now, with the emulator running you can install your MyFirstAndroidApp to the emulator.

ant debug install

Click the middle button at the bottom of the emulator and run the program. Those brilliant googlers even put the 'Hello World' part in for you! Open up the bin directory of the project and find the .apk file. Copy this file to your htdocs, browse to your workstations ip address with the phone and open the file. It will install the apk and you can now access your MyFirstAndoirdApp as you do any other app.

Pretty cool huh!
Tags: android, java


  1. JavaPF's Avatar
    Very good tutorial Chris! Thanks