Experimental workaround for an OpenJDK 21 crash on Google Play Termux running Android 17 (ARM64).
Some OpenJDK 21 tools (javac, jimage) aborted with an Android ProtoLogNative JNI registration error. The investigation traced a transitive dependency through libandroid-shmem.so to Android framework libraries.
In upstream termux/libandroid-shmem, change the ashmem helper implementation:
- Replace
ASharedMemory_create(name, size)withmemfd_create(name, MFD_CLOEXEC)followed byftruncate(fd, size)(close fd and preserve errno on failure). - Replace
ASharedMemory_getSize(fd)withfstat(fd, &st), checkingst.st_size > INT32_MAXand settingerrno = EOVERFLOW. - Add
#include <sys/stat.h>. - Build without a direct dependency on
libandroid.so.
- Android 17, ARM64, Google Play Termux
- OpenJDK 21.0.11:
java -version,javac -version,jimage --help,jlink --version javac Hello.javaandjava Hellocompleted successfully- Gradle 9.6.0
--version - Offline Gradle Java project: BUILD SUCCESSFUL (6 seconds)
Tests were performed using an isolated LD_LIBRARY_PATH override, without replacing the installed library.
Experimental, not a universal fix. Cross-process System V shared-memory semantics, API-level compatibility, and regression tests remain incomplete. Passing the above tests does not establish that the replacement is fully compatible with all users of libandroid-shmem.
Apply the changes to the upstream source, then run:
clang -D_GNU_SOURCE -fPIC -shared -std=c11 -Wall -Wextra \
-Wl,--version-script=exports.txt \
shmem.c -o libandroid-shmem-test.so -llog
readelf -d libandroid-shmem-test.so | grep NEEDEDDo not replace the system/Termux-installed shared library until compatibility has been reviewed.
Derived from termux/libandroid-shmem. Original copyright and license terms are retained in LICENSE. This repository documents an experimental modification and test evidence; it is not an official Termux release.