← home

Android Development on the Command Line

I love Android but I really hate Eclipse, and the whole IDE paradigm in general. I prefer to do development using Vim, screen, and a few shells running whatever commands are relevant for the project I'm working on. However, the Android project make it pretty clear that they support Eclipse+ADT first and foremost, so I gave it a try, if only to see what magical features I would need to figure out how to replace. Thankfully, doing so is pretty easy. Here's what you need to do to develop for Android with just a shell and your favorite text editor.

Bootstrap Ant

Ant is the build tool you'll use to build and deploy your project while developing, and to make a release when ready. But you can't run Ant in a project created in Eclipse with ADT, because ADT doesn't give you the necessary build files. But they're easy to populate, using android update project.

Before running android update project, you need to find out the ID of the target you want to use for your project. Run android list targets and find the ID for your target. Now run android update project --target your-target-id --name your-project-name --path /path/to/your/project. It will populate your project with build.xml and local.properties. It'll also say that it's updating default.properties, but it left it unchanged for me.

Bonus tip: If you want to avoid Eclipse completely and start your project from scratch on the command line, you can simply run android create project with the --target, --name, --path, --activity, and --package options populated appropriately. This is the more direct route, instead of starting a project in Eclipse and then later running android update project like I did.

Building and Installing

This part is simple. See ant help for more details.

  • ant compile will compile your code and re-generate R.java.
  • ant debug will do the above, plus build and sign a package (apk) file.
  • ant install will do all of the above plus install it to the emulator/phone.

Automated App Launching

I don't like Eclipse but I do like that it automatically launches my app on the emulator when I build it. It took some asking in IRC to figure out how to do this, but here it is:

adb shell 'am start -n your.package.name/.YourActivityName'

So a full build+run command might look something like:

ant install && adb shell 'am start -n your.package.name/.YourActivityName'

Watching Logs

See what your app is saying with adb logcat.

Ctags for Autocompletion

Install exhuberant-ctags and run ctags -R src gen in the root of your project to generate a tags file that many editors will automatically use for autocompletion.

Further automation

I'm planning on eventually writing a script that uses inotify (inotifywait -m -r) to watch for source code changes and automatically rebuild and re-scan the code with ctags. (Although I'm not sure if editors will detect changes to the tags file on the fly... must research that.)

Other Stuff

There are some parts of Eclipse/ADT that don't really have direct replacements; for example, the wizards for editing AndroidManifest.xml. In this case you'll just have to edit it by hand, but if you're reading this then you're probably okay with that.

If there's anything I've missed, please leave a comment.

Further Reading

The Other IDEs page of the Android development documentation will fill in some of the simplifications I have made here and is recommended reading.

This Linux Magazine article is also worth looking through.


Nick Welch <nick@incise.org> · github