Use Emacs in GUI mode on Android (using Termux and Termux X11)

There are currently several ways to run emacs on Android:

The problem with the first option is the limitations of TTY in general. Second option does not have direct access to binaries used by termux and thus does not provide many functionalities of emacs which call to external commands e.g. git. There are ways around this problem but it requires repackaging at least one of the termux and emacs apps manually.

This post covers the third case which provides the power of GUI emacs, the most important of which for me is easy zooming in and out (given that displays on phones are much smaller).

Emacs GUI in Android
Emacs GUI in Android

Prepare termux-x11

You need to run the following in termux:

pkg install x11-repo
pkg install termux-x11-nightly

Install X11 android app

Use the apk from releases page of termux-x11 and install it. Version Nightly Release 20240519 was used in this post.

Install emacs

We also need emacs-x package to be installed in termux:

pkg install emacs-x

(optional) install your emacs configs

I use my own emacs config in this post by doing the following in termux (we also need git for this):

cd
mkdir .config
cd .config
pkg install git
git clone https://codeberg.org/haditim/dotemacs emacs

Run emacs

Emacs can be run in termux by termux-x11 :1 -xstartup "emacs" &. The GUI can be then accessed by running the Termux:X11 app.

Resolution / font size

In my case, the best configuration is to leave the resolution at native size, but do the following after launch:

Extras

Software keyboard can be called by tapping back button in Termux:X11 app. I suggest you use Unexpected keyboard app to have all modifier keys available although attaching an external keyboard is probably the easiest option to use emacs.

Vterm

To run vterm from within emacs on Android, the following need to be installed in termux:

pkg install make cmake libtool libvterm perl

Then run M-x vterm and let it install the rest.