Tips on Android Development Using Emacs

Android using Emacs

For the intrepid Emacs user, here are some tips for doing Android development without Eclipse. I am working on a follow-up post with some general Android SDK tips.

Emacs prerequisites

  1. android-mode
    This mode gives you the following interactive commands:
    • M-x android-start-emulator Start the Android SDK emulator from emacs
    • M-x android-start-ddms Start the Android debugger
    • M-x android-logcat Like syslog for Android
    • M-x android-ant Run any ant task in the current project directory
  2. android.el
    This is a file included in the Android SDK. It duplicates some of the functionality of android-mode, but adds M-x android-jdb, which starts the JDB debugger once you have DDMS running.Load it from {SDK dir}/tools/lib
  3. JDE
    Optional, but it’s great for java code. Required to use beanshell shortcuts like the import statement command below (Generate and insert import statements)
  4. Typical emacs setup cruft
    Here’s what I have in my init file for Android:
    (add-to-list 'load-path "~/emacs/android-mode")
    	    (require 'android-mode)
    	    (setq android-mode-sdk-dir "~/work/android/android")
    	    (add-hook 'gud-mode-hook
                (lambda ()
                (add-to-list 'gud-jdb-classpath "/home/gregj/work/android-sdk-linux_86/platforms/android-7/android.jar")
                ))

Launch the emulator

Although you can start the emulator from within emacs using android-mode: M-x android-start-emulator

I prefer to launch from the shell, since this allows me to exit emacs without having to restart the emulator, e.g.:

emulator -avd starter-21 -partition-size 128 >/dev/null &

Create a project

Instead of using the New Project wizard in Eclipse, use these steps to create an Android project using the shell:

cd {project directory}
	mkdir HelloAndroid
	cd HelloAndroid
	android create project --name HelloAndroid --target android-7 --path . --package home.hoochiepep.HelloAndroid --activity HelloAndroid

Change =–target=, =–package=, and =–activity= parameters as appropriate.

To get a list of valid targets for your SDK, use

android list

Specify the application name

To change the name of the application, edit {project root}/res/values/strings.xml:

<string name="app_name">Hello, Android</string>

Specify a minimum SDK level

The Eclipse New Project wizard includes a Min SDK Version field. To set this without the wizard, add a line to AndroidManifest.xml as a child of manifest:

<uses-sdk android:minSdkVersion="2" />
      

Make an eclipse project ant-ready (do also when moved to a new machine)

Projects you pull from online will have been created using Eclipse, and will not have a build.xml file for ant.

Another common problem is that the file local.properties will be missing. Running an update as shown here will fix both problems:

android update project --path . --target android-7 --subprojects

Generate and insert import statements

You will see references to a handy Eclipse command (invoked by Control-Shift-O) which adds import statements for referenced classes.

The emacs equivalent is found in jde-mode: M-x jde-import-find-and-import (C-c C-v C-z). Make sure the classpath is set correctly prior to starting jde-mode

Use the debugger within Emacs

  • Install the app on the emulator using M-x android-ant-install (the ‘install’ target uses the debug apk)
  • Start ddms. There are no cmdline args, so you might as well use M-x android-start-ddms
  • In the emulator, go to Dev Tools -> Development Settings and select the app as the debug app
  • In the emulator, start the app
  • Look in the ddms window for the app’s debug port (usu. 8700 if the Dev Settings step was done)
  • Start jdb by invoking M-x android-jdb from android.el

    You can also start jdb directly using the following command line params as a guide

    jdb -sourcepath/home/gregj/work/android/projects/NotepadCodeLab/Notepadv3/src -attach localhost:8700

    Set breakpoints in JDB, like so

    stop in com.android.demo.notepad3.NoteEdit.onResume

    If the project directory is set correctly in the jdb command, you will be able to set breakpoints by line using jde-mode’s M-x gud-break (C-x space).

This entry was posted in Android, Development, emacs and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

4 Comments

  1. Risto
    Posted November 13, 2010 at 10:47 am | Permalink

    Thanks, these were great tips!
    Compilation error message refer to missing includes. How should I set the classpath? I’m experienced with C and Emacs but new to Java, and trying the Android GoogleMaps tutorial from the developer site.

    BR, Risto

    The emacs equivalent is found in jde-mode: M-x jde-import-find-and-import (C-c C-v C-z). Make sure the classpath is set correctly prior to starting jde-mode

  2. Posted February 4, 2011 at 10:07 pm | Permalink

    Thanks this saved me a lot of time I think! BTW android-ant-install fails with the message that I have two devices, my phone, and the emulator. How do I tell it which to use?

  3. Posted February 18, 2011 at 2:14 pm | Permalink

    @Justinhj: I resolve it by directly going to the command line. adb has handy parameters: -d for device, -e for emulator.

    So, for example, I use M-x android-ant-compile, but drop to the shell to install: adb -e bin/MyApp-debug.apk

  4. Posted March 13, 2011 at 10:54 pm | Permalink

    Perfect thanks!

One Trackback

  1. [...] also Gregory Grubbs’s site for more tips on Android development without [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*
  • randy moss combine results
  • tea party zombies download
  • search 78search 800 numbers
  • randy moss bio
  • dis systems
  • archos
  • randy moss yahoo stats
  • roses
  • dis quand reviendras-tu
  • xanadu bengals
  • zara phillips and the queen
  • 4pm cspancspan area 51cspan 90.1
  • freida pinto miral
  • search lsu.edu
  • mtv oddities
  • seagate
  • battleship aurora
  • greg olsen university of miami
  • mtv kings of leon
  • chad ochocinco sisterchad ochocinco twitter
  • tolerance
  • search engines cookiessearch engines definition
  • bonus
  • gears
  • hartmann
  • dis 0 0.9
  • vince young yahoo stats
  • radar
  • beers
  • search 2.0
  • homeless
  • dis boards cruise
  • search engines us
  • chad ochocinco johnson
  • bengals qb situation
  • gregg olsen books
  • zara phillips dating
  • vince young uncle rico gif
  • freida pinto green dress
  • bea luna
  • chicago bears media relations
  • framed
  • la ink 2011 season 5
  • deed
  • battleship vittorio veneto
  • di's hallmark
  • meant
  • chicago bears 61
  • vince young depression
  • cspan hosts
  • ratchet
  • new england patriots gillette stadium
  • chicago bears 08 record
  • chicago bears bleacher report
  • battleship yamato wreck
  • chicago bears training camp
  • la ink corey
  • chicago bears 1985
  • search engines watch
  • search engines questions
  • pendant
  • cspan facebook
  • connecticut renaissance faire
  • battleship egg hunt
  • serenity
  • kilo
  • bangles eternal flame mp3bengals forum
  • prairie
  • afternoon
  • greg olsen vikingsgreg olsen wife
  • springhill
  • tea party birthday
  • vince young quiz
  • bea zuberbühler
  • battleship ipad
  • betty
  • search engines of the world
  • bea 0b0 105
  • dis x
  • chicago bears tattoos
  • greg olsen vancouver
  • hp support 530
  • chicago bears expo
  • quran
  • legend
  • search engines 9
  • 60 search engines virus
  • zara phillips baby
  • freida pinto zac posen
  • connecticut education
  • battleship yamato 2010
  • search vim
  • hp support error 1005
  • pads
  • connecticut post
  • mtv executivesmtv fantasy factory
  • connecticut secretary of state
  • search 990 finder
  • rooster
  • homeowners
  • wein
  • chicago bears 96
  • vince young yahoo stats
  • worst
  • c span yesterdayc span zelaya
  • randy moss jail
  • new england patriots 98.5
  • hp support quick test pro
  • zara phillips baby
  • la ink games online
  • chicago bears pictures
  • chad ochocinco bears
  • zara phillips wedding hat
  • chad ochocinco vs skip bayless
  • chad ochocinco and cheryl burke
  • new england patriots jake locker
  • tijuana
  • hp support englandhp support forum
  • bengals arrests
  • c span video contest
  • mtv dougie
  • new england patriots 80
  • tea party zombies download
  • vince young redskins
  • cspan presidents
  • palma
  • bear gryllsbea hive dance studio
  • zara phillips kids
  • battleship galactica
  • randy moss 98 vikings
  • beagle
  • extending
  • hp support id
  • connecticut 5th district
  • vince young football camp
  • search tumblr
  • la ink cast
  • search 32
  • battleship wilmington nc
  • randy moss 07 08 highlights
  • hose
  • dis pater
  • crimper
  • la ink 03x05
  • mandolin
  • hp support 6500a plus
  • battleship bismarck wreck
  • search engines before google
  • cspan washington correspondents dinner 2011
  • reign
  • chad ochocinco quotes video
  • bea goldfishberg
  • dependency
  • spherical
  • coronado
  • randy moss vikings 2011
  • battleship lexington
  • mtv true life
  • vince young endorsementsvince young foundation
  • hiding
  • search and seizure
  • search engines usage statistics 2010
  • connecticut lottery
  • dressing
  • licensed
  • mtv overdrive
  • tea party nj
  • hp support chat
  • hp support greece
  • connecticut juvenile training schoolconnecticut kids
  • hp support error 1005
  • dis lyrics
  • bea 71 series staples
  • odessey
  • bea test
  • mtv 5 cover
  • new england patriots needs
  • la ink 04x01
  • vince young 99 yard video
  • rotation
  • search operatorssearch people
  • battleship hacked
  • bea verdi
  • zara phillips fascinator