No-Eclipse Android Hello World

Despite my earlier post on IDE’s I’m not really a fan of them, they’re far too bulky and complex for me, so it shouldn’t come to surprise you when I say that I got to playing with Android today and I refused to use the Eclipse of Netbeans plugin for it. So for all of you who are with me and against IDE’s, I’ll show you how it’s done. Before we start, make sure you have the android sdk installed from your local repository or from the google website.

So, first thing’s first, let’s create a directory for our project, so run:

mkdir HelloAndroid
cd HelloAndroid

Now that we’re in the project directory, let’s run the following command to create our project:

android create project \
--name HelloAndroid \
--target 2 \
--package com.android.helloandroid \
--path ./ \
--activity HelloAndroid

So, what this does is creates a project (create project) in the current directory (–path ./) named HelloAndroid (–name HelloAndroid) with a main activity/class called HelloAndroid (–activity HelloAndroid) in the package “com.android.helloandroid” (–package com.android.helloandroid) targeted for the 1.1 API (–target 2, note this may be different for your system, to get a list of targets, run “android list targets”). Now, this also generates a handy dandy antbuild, so make sure you have apache-ant installed because it will make your life a billion times easier. It also generated the default generated code, resource files and everything else. Now you can go ahead and follow the instructions on the tutorial for the code editing part.

When it comes to running your compiled code, you have two options, installing it to your device, or installing it to your emulator. To first option is the best because to tell the truth, the emulator sucks. It’s incredibly slow. But I don’t have an android phone, so I’m going to go ahead and show how to use the emulator. First thing is first, you’re going to create your AVD (Android Virtual device) it’s pretty simple, so go ahead and run this command:

android create avd -n myAVD -t 3

This creates an AVD named “myAVD” for the target id 3. (Hint: To obtain a list of targets, use “android list targets”)
Now you can run your AVD using the emulator command, but be warned, the emulator is painfully slow, you’ll see the text “Android_” with a blinking cursor, followed by a shiny fancy Android and then the home screen, this can take anywhere from 2 minutes to 20 minutes for some reason so you’ll have to be patient.

emulator -avd myAVD

While that’s happening, go get some coffee, play some XBOX, do whatever, but keep an eye on it for when it’s done.

Once your system is booted up, you can go ahead and compile and install your HelloAndroid app to the emulator. To do this, use the ant build:

ant install

Once the install is complete, you can go to the application menu (the middle bottom button in the emulator, with the grid) and run your application. See below for an example result:

And that’s all there is to it. You don’t need to keep reopening the emulator when you update your software, you can just rerun “ant install” so it’s best to just keep the emulator open and not worry about the long startup. You may also want to open the emulator when you start programming so it’s there to test on when ever you want to quickly build. If you’ve got any other questions, let me know in the comments.

Related posts:

  1. A Hello World Application In C With Just Xlib
  2. Eclipse vs. Netbeans
  3. Hello World WordPress Plugin
  4. Broadcom Wireless Driver Support on Slackware
  5. Aliasing RM to Move To Trash — Linux Recycle Bin

About hkothari

I am software developer and enthusiast. I enjoy trying out new software, but prefer to use light and easy to use software. I’m currently still in high school, but working my way through it. I intern in a college computer science department, using flex and java, but I prefer C/C++, PHP and Lua. I enjoy running and swimming too. I’m a devout slackware user, but I try out a ton of other linux distros for fun and in order to learn more.
This entry was posted in Howto/Tutorial, Programming and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

Comments are closed.

blog comments powered by Disqus