Update: running Emacs in Android L (Lollipop)

Update from Dustin DeWeese: “A working Emacs 25 package is available in Termux: https://termux.com
$ apt install emacs”
— this is probably a better solution than the outdated distro below.

Emacs logo. In February 2014, I posted instructions for installing Gnu Emacs in older versions of Android. These instructions no longer work in Android L (Lollipop), because of a new requirement that all executables be compiled with a position-independent (PIE) flag. I have managed to create a new binary from Michał Zieliński’s admittedly now out-of-date patched Emacs version, and have made it available on GitHub.

Installation instructions

Since TerminalIDE also fails to run under Lollipop (lacking PIE), the instructions for installation are now somewhat different.

  1. Install some kind of a terminal emulator (JuiceSSH currently crashes, but others seem to work) in your Android. If you’re not rooted, then you must choose a terminal emulator that has its own home directory under /data/, where you can make a file executable and run it (you cannot normally make a file executable under /sdcard/).
  2. Create a new directory /sdcard/emacs/ to hold your non-executable files, such as eLISP files (you may choose a different location, but you’ll need to set some extra environment variables so that Emacs can find your files; that’s outside the scope of this posting).
  3. ₣rom my GitHub repo, download emacs.bin, copy it somewhere not on your /sdcard/ (your terminal emulator’s “home” directory if not rooted, or somewhere like /data/local/bin/ if rooted) and make it executable:
    chmod 755 emacs.bin
  4. From my GitHub repo, download etc.tlzma, terminfo.tlzma, and lisp.tlzma, and unpack them all into your /sdcard/emacs/ directory — you may need BusyBox installed to get the unlzma and tar utilities required for unpacking, e.g.
    unlzma -c lisp.tlzma | tar xvf -
  5. Somewhere on your executable path (perhaps /system/xbin/), create a new shell script called “emacs” containing a command like this:
    HOME=/sdcard TERMINFO=/sdcard/emacs/terminfo /data/local/bin/emacs.bin "$*"

    If your chosen terminal emulator already has TERMINFO installed, then don’t set it in the script. You may choose any home directory you want, but it must be writeable (Emacs will want to create a $HOME/.emacs.d/ directory to save settings).

  6. Make the new script executable (and make sure it’s on your execution $PATH):
    chmod 755 emacs

Known issues

  • If your terminal type is unrecognised, you might need to add additional terminal types to emacs/terminfo; conversely, if your terminal emulator is already using a TERMINFO database somewhere, then don’t set the TERMINFO environment variable in your shell script.
  • Crashes in a local shell under JuiceSSH — don’t know why yet (use a different terminal emulator). Update: only when the font is too large — seems related to screen width.
  • Dates on *.elc files are earlier than dates on *.el files after running Michał’s build scripts; you should probably fix that with something like this:
    find /sdcard/emacs/lisp -name '*.elc' -print0 | xargs -0 touch
  • Starts with the message “WARNING: linker: /data/local/bin/emacs.bin has text relocations. This is wasting memory and prevents security hardening. Please fix.” — this seems to be a common problem in Android L, and I have not yet found the right combination of GCC flags to fix it.

Help wanted

Any volunteers to package all this up neatly, perhaps with some terminal emulator, for distribution in the Google Play Store?

About David Megginson

Scholar, tech guy, Canuck, open-source/data/information zealot, urban pedestrian, language geek, tea drinker, pater familias, red tory, amateur musician, private pilot.
This entry was posted in General. Bookmark the permalink.

12 Responses to Update: running Emacs in Android L (Lollipop)

  1. Pingback: How to install a usable Emacs in Android (Feb 2014) | Quoderat

  2. cst2bicycle says:

    Hi, I get this error, after the gcc warning. Please help. Thanks a lot for what you’ve been doing. Using Termux, though it has a default Emacs package, cannot use org-mode.

    emacs: Terminal type xterm-256color is not defined. If that is not the actual type of terminal you have,
    use the Bourne shell command `TERM=… export TERM’ (C-shell:
    `setenv TERM …’) to specify the correct type. It may be necessary
    to do `unset TERMINFO’ (C-shell: `unsetenv TERMINFO’) as well.

    • cst says:

      This is after not setting TERMINFO since there is a terminfo/ for Termux. Also tried to copy-paste files from terminfo folders to the one in /sdcard/emacs directory and then set the variable. Doesn’t work. Thanks. 🙂

  3. Elchanan says:

    Hi, Seems to be working for me on my Nexus 6. I will detail later which Terminal emaulater APP and and host tools (Win7 machine) I used in order to extract the binaries.

    Thanks a lot.

    • Elchanan says:

      Some more specific informative notes regarding my specific positive feedback:
      My setup:
      – Nexus 6 with Android 5.1.1, none rooted
      – My host PC running Win7
      I followed the instructions depicted above with the following notes:
      Step 1: Installed “Terminal Emulator” (none rooted)

      Step 3: The home directory of the “Terminal Emulator” is /data/data/jackpal.androidterm/app_HOME.
      Using the file explorer on my Win7 host, I copied the emacs.bin file mentioned in this step to a directory I created on Nexis 6 under “Internal Storage” directory as it is seen automatically by the Win7 regular file explorer.
      The same “Internal Storage” directory is detected as “/sdcard/” from the terminal emulator, so I could copy the emacs.bin to the terminal emulator home directory.
      For example if the emacs.bin was copied to the directory “kkk” then from the terminal I would do:
      cd /data/data/jackpal.androidterm/app_HOME (or simply “cd ~”)
      cp /sdcard/kkk/emacs.bin .

      Step 4: Since I did not have busy box installed on my Nexus 6 (for some reason the installation failed), I extracted the
      mentioned files with “7-Zip” (free insallation for Win7, the x64 version, http://www.7-zip.org/download.html) on my host machine, and
      then moved the extracted directories (etc,terminfo and lisp) to a “emacs” directory created on Nexus 6 under Nexus 6 “Internal Storage” directory as it is seen automatically by the Win7 regular file explorer. The same “Internal Storage” directory is detected as “/sdcard/” from the terminal emulator

      Step 5: I created the script on my Win7 host and then moved it to the Terminal APP home directory as described in my comment above for step 4.

      Step 6: What worked for me after “chmod”ing the script as described in this step, was the command line:
      $ source emacs
      I failed to run it as is (that is, running the command line “./emacs” from the terminal home directory). When running “./emacs” I get the following error prompt:
      /system/bin/sh: ./emacs: No such file or directory

  4. Ano says:

    Thank you very much; your article has allowed me to use Emacs on my Nexus 10.

  5. Rune says:

    Any news on a working emacs in the google play store?

  6. Arnaud B says:

    So many thanks M.Megginson for that last comment : I had emacs and org-mode running on my Galaxy note 8 tablet (lollipop cm12) in no time thanks to you ! A dream come true ! Runs prettty fast, only glitches are the khackers keyboard alt /esc but I’m confindent it’s no big deal and already pretty usable.

  7. Dustin DeWeese says:

    A working Emacs 25 package is available in Termux: https://termux.com
    $ apt install emacs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s