Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Last active June 3, 2023 02:22
Show Gist options
  • Save lupyuen/35c356ecd88c4ba3f730c5c6f42b7514 to your computer and use it in GitHub Desktop.
Save lupyuen/35c356ecd88c4ba3f730c5c6f42b7514 to your computer and use it in GitHub Desktop.
Install Termux GUI Plugin

Install Termux GUI Plugin

Let's install the Termux GUI Plugin, so we can build Android GUI Apps in C and Python... On Android!

Caution: We're installing Experimental Unsigned APKs, be careful!

Install Termux APK and Termux GUI APK

According to the instructions, we should install Termux APK and Termux GUI APK generated by GitHub Actions...

https://github.com/termux/termux-gui

There is currently no release on f-droid, so the only method to install this plugin is to use the apk from the releases and the Termux apk from Github Actions.

Latest Termux GUI Release is 29 Apr 2023 (version 0.1.6)...

https://github.com/termux/termux-gui/releases/tag/0.1.6

Last build of Termux before 29 Apr 2023 is on 17 Apr 2023...

https://github.com/termux/termux-app/actions/runs/4714582493

So we download and install termux-app_v0.118.0+93eafff-apt-android-7-github-debug_arm64-v8a from...

https://github.com/termux/termux-app/suites/12269415843/artifacts/649696938

(If Termux is already installed, uninstall it first)

Then we download and install Termux GUI APK 0.1.6...

https://github.com/termux/termux-gui/releases/download/0.1.6/app-release.apk

Launch Termux.

Install SSH Server or Dropbear

Optional: Install SSH Server or Dropbear so we can run the commands below over SSH

Install Git

pkg install git

Install C Bindings for Termux GUI

Install Termux GUI C Bindings and Protobuf Library...

pkg install \
  termux-gui-c \
  libprotobuf

Build C Sample for Termux GUI

Check out the Termux GUI Tutorial

We build and run this C sample app: hello_world.c

nano hello_world.c
## Copy and paste contents of `hello_world.c`, save and exit:
## https://github.com/tareksander/termux-gui-c-bindings/blob/main/tutorial/c/hello_world.c

gcc hello_world.c -ltermuxgui
./a.out

And Hello World! pops up as an Android UI yay!

Build Zig Sample for Termux GUI

Follow these steps to install Zig Compiler on Termux...

Let's compile a Zig App for Termux GUI: hello_world.zig

## Download source code
git clone --recursive https://github.com/lupyuen/pinephone-lvgl-zig
cd pinephone-lvgl-zig/termux

## Compile Zig program
zig build-exe \
  --verbose-cimport \
  -isystem "$PREFIX/include" \
  -L "$PREFIX/lib" \
  -ltermuxgui \
  hello_world.zig

## Run Zig program
./hello_world

But our Zig App fails. Is there a problem with the Zig Dynamic Linker?

$ zig build-exe ...
warning: Encountered error: FileNotFound, falling back to default ABI and dynamic linker.

$ ./hello_world

All your codebase are belong to us.
Segmentation fault at address 0x0
???:?:?: 0x0 in ??? (???)
/data/data/com.termux/files/home/zig-linux-aarch64-0.11.0-dev.3333+32e719e07/lib/std/start.zig:609:37: 0x217dc3 in posixCallMainAndExit (hello_world)
            const result = root.main() catch |err| {
                                    ^
/data/data/com.termux/files/home/zig-linux-aarch64-0.11.0-dev.3333+32e719e07/lib/std/start.zig:368:5: 0x217897 in _start (hello_world)
    @call(.never_inline, posixCallMainAndExit, .{});
    ^
Aborted

$ gdb hello_world

Reading symbols from hello_world...
(gdb) r
Starting program: /data/data/com.termux/files/home/pinephone-lvgl-zig/termux/hello_world
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/data/data/com.termux/files/usr/lib/libthread_db.so".
All your codebase are belong to us.

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x0000000000217dfc in hello_world.main () at hello_world.zig:15
#2  0x0000000000217dc4 in start.callMain ()
    at /data/data/com.termux/files/home/zig-linux-aarch64-0.11.0-dev.3333+32e719e07/lib/std/start.zig:609
#3  start.initEventLoopAndCallMain ()
    at /data/data/com.termux/files/home/zig-linux-aarch64-0.11.0-dev.3333+32e719e07/lib/std/start.zig:543
#4  start.callMainWithArgs () at /data/data/com.termux/files/home/zig-linux-aarch64-0.11.0-dev.3333+32e719e07/lib/std/start.zig:493
#5  start.posixCallMainAndExit () at /data/data/com.termux/files/home/zig-linux-aarch64-0.11.0-dev.3333+32e719e07/lib/std/start.zig:456
#6  0x0000000000217898 in _start () at /data/data/com.termux/files/home/zig-linux-aarch64-0.11.0-dev.3333+32e719e07/lib/std/start.zig:368
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)

(More about FileNotFound)

(Fix for FileNotFound)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment