« Back to home

Development Environment for Android

I'm finding that I have less and less time to write for this blog and the time between posts is getting longer and longer. This is a real shame as I enjoy writing the posts and spending the time needed to research and format them helps me organise my thoughts which improves the overall quality of my projects. Each post is essentially a small planning session for me.

One time slot that has yet to be filled is my daily commute to and from work, about 2 hours every day. I usually spend this time catching up on my RSS feeds (or, more often unfortunately, playing Candy Crush Saga in a mindless commuter daze). I can certainly make more productive use of this time and devoting it to work on the blog seems like a good idea.

This blog is pretty much a static site with all the content generated on my home PC using my own modified version of the Nikola static site generator, a custom template and some helper scripts. All the raw content is stored in a private Git repository so all I really need to be able to modify or generate content is a text editor and a Git client.

I'm not keen on carrying a laptop (or even a netbook) around solely for that purpose (the weight is annoying and the space required to use a laptop can be difficult to find on commuter train). One thing I do regularly carry around already is a 10.1" Android tablet (in my case it's an older Motorola Xoom). If I could get what I need to use up and running on this I would be happy (and you should see a far more regular posting schedule).

Although it's possible to install a full version of Linux on an Android device this seems like overkill for the tasks that I want to do. It also requires that the device be rooted which is something I'd prefer to avoid (not that I have anything against rooting, it's just that I already have enough to do without adding something else to fiddle around with).

Luckily there is a much simpler way to do this - the TerminalIDE application provides you with a very nice command line interface to most common development tools (gcc, java, nano, vim, tmux and git amongst others), doesn't require the device to be rooted and runs as a standard Android application.

The rest of this post runs through the process of installing and configuring TerminalIDE and it's related tools so you can access your Git repositories, do local edits and push changes back. I'm mostly using it for raw posts for the site (which are stored in plain text files using Markdown as a formatting language) but you can use it for anything you like by adding the appropriate editors and/or viewers to your tablet.

Setting up Terminal IDE

Essentially I followed this guide with only a few minor changes. I've included a bit of extra detail here that was either assumed or glossed over in the original.

Which Keyboard?

You really need a physical keyboard to make the best use of the environment, I use a tablet case with an integrated Bluetooth keyboard that seems to work reasonably well (the keys are the soft rubber 'chiclet' style and I'm reduced to 'hunt and peck' typing but it's good enough).

Any on screen keyboard is going to take up too much screen real estate on any but the largest of tablets. The built in Android keyboard just isn't going to cut it at all (it is missing too many of the 'special' keys like Fn, Alt and some symbols to allow you to do any real work). If you are determine to use an on screen keyboard you should install the Hackers Keyboard input method, it simulates a full keyboard with all extended keys.

Installing TerminalIDE

If you are planning on using the Hackers Keyboard you should install it first. Once installation is complete you will need to go to Settings, select Language & input and enable it for use. See the screenshot to the right for details.

Installing TerminalIDE is a multistage process. First you install the application itself through the Play Store just like any other app. If you have data limits on your mobile connection you may want to do this over WiFi, the application is large (over 20Mb).

The next step is to launch the application and select Install System. This will create the actual environment for you. If a new system bundle has been released since the last application update you will have the option to download it here (another 20Mb or so).

If you want to use an onscreen keyboard you can select which one you prefer now. Tap Keyboard and select your preferred one. If you are using a hardware keyboard you don't need to do anything, it will be picked up automatically.

I tend to set the font size a bit higher than the default 12pt, the smaller text can be difficult to read, especially in a moving vehicle. You can change this (and a range of other settings) by tapping the Options button.

Now you are ready to go, tap the Terminal IDE button and you'll get a familiar Linux console. There are actually four consoles and you can switch between them by swiping your finger across the screen. This makes it easier to keep working while a background task is ongoing (like a 'git clone' for example).


Because TerminalIDE runs as a user (each application on Android gets it's own user and group ID) the environment is not exactly the same as a standard Linux console and there are some restrictions and limitations.

One of the biggest differences is in the file system layout. As a standard user the application can't place the binary files in the usual /bin or /usr/bin directories you would expect on a normal Linux system. The application has it's own directory at /data/data/com.spartacusrex.spartacuside/files and everything lives in sub-directories under that. This directory becomes your home directory as well (and the HOME environment variable is set up to point to it accordingly). It is also defined by the IDESYSTEM environment variable so you can use that in shell scripts to refer to it rather than typing the full path every time.

In the standard installation there are 5 sub-directories created for you:

     $> ls -l         drwx------    5 10075    10075         4096 Aug 16 04:17 local         drwx------    2 10075    10075         4096 Aug 16 04:17 projects         lrwxrwxrwx    1 10075    10075           11 Aug 16 04:17 sdcard -> /mnt/sdcard         drwxr-x---    8 10075    10075         4096 Aug 16 04:17 system         drwx------    2 10075    10075         4096 Aug 16 04:17 tmp

The system directory which contains all the binaries supplied by TerminalIDE. If you do an update the files in this directory will be replaced with the newer versions so it is best not to modify anything under this directory. The system directory mimics the layout of a standard Linux root directory and has the bin, etc, lib and other directories you would expect:

     $> ls - system         -rw-r-----    1 10075    10075           25 Feb 26  2013 README.txt         -rw-r--r--    1 10075    10075     21790432 Feb 27  2013 android-gcc-4.4.0.tar.gz         -rw-r-----    1 10075    10075         2153 Feb 26  2013 bashrc         drwxr-x---    4 10075    10075         4096 Sep  2 06:31 bin         drwxr-x---    2 10075    10075         4096 Aug 16 04:17 classes         drwxr-x---    8 10075    10075         4096 Aug 16 04:17 etc         -rw-r-----    1 10075    10075          111 Nov 14  2011 inputrc         drwxr-x---    2 10075    10075         4096 Nov 14  2011 lib         -rw-r-----    1 10075    10075         3009 Nov 24  2011 mc.ini         -rw-r--r--    1 10075    10075         8679 Dec 17  2011 nanorc         drwxr-xr-x    3 10075    10075         4096 Aug 16 04:17 share         drwxr-x---    7 10075    10075         4096 Aug 16 04:17 src         -rw-r-----    1 10075    10075          605 Dec  1  2011 tmux.conf         -rw-r-----    1 10075    10075         2803 Feb 28  2013 vimrc

The local directory is the equivalent of the usr directory on a Linux system. It contains local configuration files, executables and libraries. TerminalIDE will not override this directory on an updated so any customisations you make should be placed here.

     $> ls -l local         drwx------    2 10075    10075         4096 Sep  2 06:49 bin         drwx------    2 10075    10075         4096 Aug 16 04:17 include         drwx------    2 10075    10075         4096 Aug 16 04:17 lib

The sdcard directory is simply a soft link to the /sdcard directory on your device. This is the 'common' directory in Android, because applications cannot share any files in their own directories anything that you need to access from another application (source files to edit for example) needs to be placed somewhere in this directory which is accessable to all applications.

Rather than use sdcard directly I created a directory in sdcard for my development work and created my own soft link to it. This made it a bit easier to access from scripts and allows me to move the physical location of the files later without breaking anything. These are the steps I used:

     $> mkdir /mnt/sdcard/Sandbox         $> ln -s /mnt/sdcard/Sandbox ~/Sandbox

This allows me to keep all my repositories in a location where I can access them from any other application while remaining easy to access in the shell environment.

Configuring SSH

TerminalIDE uses dropbear to provide SSH services (client and server). When it is first installed there is no private key configured so you should probably set one up:

     $> mkdir ~/.ssh         $> dropbearkey -t rsa -f ~/.ssh/id_rsa

You can then save the public key to a file at any time by using the following command:

     $> dropbearkey -y -f ~/.ssh/id_rsa > ~/sdcard/mykey.pub

This can then be distributed to systems that need it. GitHub for example requires you to upload your SSH public key to your profile.

Configuring GIT

Git will try to use the ssh command directly and by default will not pick up the right private key file to use. We need to create a helper script for git to use that will pass this information along. As with all custom scripts that you want to keep between updates this should be placed in the ${IDESYSTEM}/local/bin directory. Simply type the following command:

     vi ${IDESYSTEM}/local/bin/git-ssh

And add the following text to the file and save it:

``` #!/data/data/com.spartacusrex.spartacuside/files/system/bin/bash exec ssh -i ~/.ssh/id_rsa "$@"

Now change the permissions so it is executable:

     chmod 0755 ${IDESYSTEM}/local/bin/git-ssh

The next step is to let git know that it should use this command instead of the normal ssh and to set your personal information (the name and email address to use for commits for example). These can be set globally in your ~/.bashrc file. Simply open the file for editing:

     vi ~/.bashrc

Add these lines towards the bottom of the file and save it. Obviously you should change your name and email address appropriately.

     export GIT_SSH=~/local/bin/ssh-git         export GIT_AUTHOR_NAME="My Name"         export GIT_AUTHOR_EMAIL="myname@myemail"         export GIT_COMMITER_NAME=$GIT_AUTHOR_NAME         export GIT_COMMITER_EMAIL=$GIT_AUTHOR_EMAIL

After this you will need to restart the terminals - simply choose Shutdown from the main application menu and start the application again. From now on you should be able to use git as normal with GitHub or any other repository you have access to.

When you first clone a repository you should probably do it over a WiFi connection, they can be very large (the repository for this site is over 100Mb). After that push and pull operations to keep in sync with your remote repository should be relatively small.

Which Editor?

Both vi and nano are included in the TerminalIDE distribution but if you prefer a more graphical editor you might want to look at something like DroidEdit. This is the editor I use (vi is fine for small editing jobs but for a larger page or multiple files I prefer something a bit more user friendly) and it works very well on Android. It has syntax highlighting support for several languages and is very nice to use on 7" or higher screens.

Next Steps

If you want to add additional command line tools to the TerminalIDE environment the full source is available so you can build a custom version if you like. I haven't tried this yet and I don't expect it to be a trivial task - one thing I would really like to add is support for Python (I use a lot of Python scripts for project management tasks and it would be nice to use them on the tablet as well).

Support for additional (non-text) file formats should be as easy as finding the appropriate editor or viewer for them. If you work a lot with 3D files you might want to install an STL viewer and a DXF/DWG viewer to allow you to at least review updates made to model designs.

Overall this is a very neat setup for developing on the go and doesn't require a permanent network connection like a remote desktop type solution would. A lot of this post was actually written in the environment - and quite a few future posts will begin their life there as well.