Android with Emacs on Ubuntu
This tutorial assumes that the following tutorial has been successfully completed:
Install Java if not currently available.
~$ sudo apt-get install openjdk-6-jdk
Install Ant if not currently available.
~$ sudo apt-get install ant
Download the Android linux release from http://developer.android.com/sdk/index.html to the Desktop and unzip.
~$ cd ~/Desktop ~$ unzip android-sdk-linux_x86-1.1_r1.zip -d ~/opt ### Rename new directory ~$ mv ~/opt/android-sdk-linux_x86-1.1_r1 ~/opt/android
If you are on a 64-bit system, install the ia32-libs if not present.
~$ sudo apt-get install ia32-libs
Add Android Tools to System Path
~/.bashrc file to include the Android tools in the system path.
~$ emacs ~/.bashrc ### Add the following to the bottom of .bashrc PATH=$PATH:~/opt/android/tools ### Save the file C-x C-s ### Exit emacs C-x C-c
Test Android Emulator
In a new terminal window, test the installation by launching the Android emulator.
~$ source ~/.bashrc ~$ android ~$ emulator
Since this is the first launch of the emulator, a dialog box concerning sending statistics about usage of the SDK to Google is presented.
After that decision is made, the Android emulator is available.
Close the emulator.
Install android-mode for emacs.
~$ cd ~/opt ~$ git clone git://github.com/remvee/android-mode.git
Add these specifics to the
;; android-mode (add-to-list 'load-path "~/opt/android-mode") (require 'android-mode) (defcustom android-mode-sdk-dir "~/opt/android")
Launch emacs and test android-mode.
~$ emacs ### Launch the emulator M-x android-start-emulator
After starting, the Android emulator will be locked.
After clicking the menu button, the emulator is unlocked.
Create Android Project
Create a test project.
~$ mkdir ~/projects ~$ cd ~/projects ~$ activitycreator --out TestProject us.riddell.TestProject
activitycreator command creates the
~/projects/TestProject directory containing a basic Android project.
Deploy TestProject Application
Open emacs and start the emulator (as described above.) Next, open a file within the project and deploy to the running emulator.
### Open the project layout file C-x C-f ~/projects/TestProject/res/layout/main.xml
Now, install the project.
Output of the ant script:
-*- mode: compilation; default-directory: "~/projects/TestProject/" -*- Compilation started at Fri Mar 20 18:24:38 ant install Buildfile: build.xml dirs: [echo] Creating output directories if needed... [mkdir] Created dir: /home/tim/projects/TestProject/bin/classes resource-src: [echo] Generating R.java / Manifest.java from the resources... aidl: [echo] Compiling aidl files into Java classes... compile: [javac] Compiling 2 source files to /home/tim/projects/TestProject/bin/classes dex: [echo] Converting compiled files and external libraries into bin/classes.dex... package-res: package-res-no-assets: [echo] Packaging resources... debug: [echo] Packaging bin/TestProject-debug.apk, and signing it with a debug key... [exec] Using keystore: /home/tim/.android/debug.keystore install: [echo] Installing bin/TestProject-debug.apk onto default emulator... [exec] * daemon not running. starting it now * [exec] * daemon started successfully * [exec] 85 KB/s (4363 bytes in 0.049s) [exec] pkg: /data/local/tmp/TestProject-debug.apk [exec] Success BUILD SUCCESSFUL Total time: 8 seconds Compilation finished at Fri Mar 20 18:24:47
Execute TestProject Application
Back in the emulator, click on the grey up arrow above the
MENU button to launch the application menu.
Click on TestProject to launch the application.
Modify and Reinstall Application
With the open
main.xml file, modify the application message and reinstall.
### Change the Hello World string to your liking ### Save the file C-x C-s ### Reinstall M-x android-ant-reinstall
Back in the emulator, click on the TestProject application again to view the new changes.
Basic Emulator Controls
Some basic keyboard controls for the emulator. These are notated as emacs commands although the emulator is active when using these commands.
### Toggle orientation F11 (C-F11 for many laptops) ### Toggle full screen mode M-<enter> ### Home Home ### Menu (left softkey) F2 or PgUp ### Star (right softkey) S-F2 or PgDn ### Back ESC ### Call F3 ### Hangup F4 ### Search F5 ### Power F7
Here is the search screen in landscape mode: