As part of Emacs 30 Emacs will run natively on Android. I had already used Emacs in terminal on Termux but a native graphical app seemed better and I decided to try it. It took me a bit of time to understand the explanations and get it to work. The following are my notes on how I did it. Maybe it’s useful for someone else as well.
You can cross-compile emacs for Android yourself but it’s easier to use precompiled apps. Jianwei Hu provides binaries Android ports for GNU Emacs download SourceForge.net. F-Droid also has a version but it’s not current and I couldn’t get it to work.
Jianwei provides two options:
- a pure Emacs app
- a version combined with a specific version of Termux.
I recommend the latter since this allows you to use commandline tools such as grep, git
and so on in Emacs. From the SourceForge page
the directory
termuxcontains copies of the installation packages built with their “shared user ID’’ set tocom.termuxand a version of the Termux terminal emulator signed with Emacs’s signing keys. Together, those packages enable Emacs to make use of the Termux package repositories.
Install Termux first
Since I had already installed Termux I had to replace the official version with the one Jianwei provides. This turned out to be less difficult than I initially thought.
Create a backup both of Termux and of the data you store within.
This is also described in the Backing up Termux - Termux Wiki page.
For Termux itself I used the termux-backup script and ran termux-backup /sdcard/backup.tar.xz.
For the user data I followed the advice, ran tar -zcf /sdcard/termux-backup-home.tar.gz -C /data/data/com.termux/files ./home.
Remove the existing Termux copy and install the new version from Jianwei.
Restore the backups.
First I ensured that storage permission is present by running termux-setup-storage. Then I
ran termux-restore /sdcard/backup.tar.xz to restore the Termux state and finally tar -zxf /sdcard/termux-backup.tar.gz -C /data/data/com.termux/files --recursive-unlink --preserve-permissions
Restart Termux.
All data and binaries were in place as needed. As this stage it can’t hurt to run pkg upgrade to have the latest packages available. If you haven’t done so or start out new I
strongly suggest installing at least git.
Install the Emacs app
I used the Emacs version from the Termux directory. It includes different versions not only for the different architectures but also different Emacs versions
- Emacs-30.0.90
- Emacs-30.0.93 (the prerelease package)
- Emacs-31.0.50 (the development version)
I recommend the prerelase package for now. Since I run a fairly recent Android version I chose the emacs-30.0.93-29-arm64-v8a.apk file.
In case you haven’t done so for side loading you need to allow installations from the browser you use to download. Android complains if you didn’t. At least my devices include a security check form Google that the apk doesn’t appear malicious and afterwards the installation succeeded.
Install a keyboard app
The standard keyboard apps don’t include keys like Control or Meta. I recommend the Unexpected-Keyboard that is available both on Google Play and F-Droid.
Configure Emacs
As described on the SourceForge site the following code in early-init.el makes any
binaries installed in Termux available to Emacs:
(setenv "PATH" (format "%s:%s" "/data/data/com.termux/files/usr/bin"
(getenv "PATH")))
(push "/data/data/com.termux/files/usr/bin" exec-path)I also added
(setq touch-screen-display-keyboard t)so that the on screen keyboard is always visible.
Access to file on the Android device
Since I want to work with files on my phone or tablet outside the Emacs directory I had to grant permissions to Emacs. Jianwei describes the different options
The first is the app data directory, which also serves as the app’s Unix home directory, and is only accessible to Emacs itself.
The second is the external storage directory (located at /sdcard), which Emacs must explicitly request permission to access. This directory is what shows up as the ``internal storage’’ in your file manager app.
Prior to Android 11, granting Emacs rights to access this directory can be performed from the Permissions menu in the App Info settings panel, by enabling the option labeled Storage; after Android 11, the path to the setting has changed, and must instead be granted from the Special App Access menu in Settings.
Contrary to several descriptions being circulated online, it is not necessary to install the Termux variant for access to external storage. That being said, either application will gain any permissions granted to the other (of which the right to access external storage is one) as a consequence of their shared user ID.
The third is storage provided by other applications (Nextcloud, for example) through the Storage Access Framework – this storage is extremely slow (thanks in part to Google’s botched implementation of document provider IPC), and is located within subdirectories of /content/storage. Before any of these directories become available, you must run `M-x android-request-directory-access’, and select the directory you want from the file selection panel displayed.
I granted access to external storage and all was well.
I use Syncthing to sync data between Android and my laptop. I added symlinks to those folders for easier access.
Since then I use Emacs happily on my tablet and even on my phone.