This specification describes gvx-android.aar, its Java launcher (dev.gfire.gvx.Gvx), its sample service (android/sample), and the capability probe (tools/androidprobe). Android executes gvx on android/arm64 (and android/amd64 in CI emulators) using Linux systrap.
Unprivileged Android apps (untrusted_app) cannot open /dev/kvm, lack /etc/resolv.conf, and cannot execute binaries downloaded into writable app directories under SELinux W^X. Copying standard Linux CLI installers onto Android fails at execve or DNS resolution.
scripts/android/build-sdk.sh compiles cmd/rungvx into jni/arm64-v8a/librungvx.so inside gvx-android.aar, so PackageManager extracts it into the executable apk_data_file library directory. The Java wrapper passes app-private storage directories and active --host-dns resolvers before Sentry self-lockdown begins.
The sections below document library packaging, DNS injection, systrap adaptations, emulator verification, and Android-specific limits.
Android packaging spans three layers: NDK compilation into a native library, Java launching with DNS injection, and kernel-level systrap adaptations.
scripts/android/build-sdk.sh cross-compiles cmd/rungvx with the Android NDK (GOOS=android, CGO_ENABLED=1, GOARM64=v8.0, PIE mode) and builds two artifacts:
gvx-android.aar(minSdkVersion 31): BundlesAndroidManifest.xml(INTERNET,ACCESS_NETWORK_STATE),classes.jar(dev.gfire.gvx.Gvx), andjni/arm64-v8a/librungvx.so.gvx-sample.apk: Debug-signed foreground-service demo (RunService) aligned withzipalign -P 16. Settingandroid:extractNativeLibs="true"extractslibrungvx.sointo the executableApplicationInfo.nativeLibraryDir.
Gvx.start(Context ctx, List<String> args) builds a ProcessBuilder targeting <nativeLibraryDir>/librungvx.so:
- App-private storage env: Sets
HOMEtoctx.getFilesDir()and setsXDG_CACHE_HOMEandTMPDIRtoctx.getCacheDir(). Named volumes default toctx.getFilesDir()/.local/share/gvx/volumes, and named control sockets resolve underTMPDIR/gvx-runbecause Android lacks/tmp. SetXDG_DATA_HOMEorGVX_VOLUME_DIRtoctx.getNoBackupFilesDir()to exclude large volumes from Android Auto Backup. - Active DNS injection: For
runandpull, readsLinkProperties.getDnsServers(), skips link-local IPv6 addresses, and prepends--host-dns <ip>. - Process streaming: Returns
java.lang.Processso callers consume stdout, stderr, and exit codes whilelibrungvx.soapplies host lockdown.
android/sample/.../RunService.java executes commands sequentially inside an Android 14+ FOREGROUND_SERVICE_TYPE_SPECIAL_USE foreground service to prevent background throttling.
Inside librungvx.so, four runtime adaptations accommodate Android kernel and SELinux policies:
- Executable stub memory: Allocates stub memory with
memfd_create(MFD_EXEC)and probesvm.mmap_min_addr(0x8000) viaMAP_FIXED_NOREPLACE. - 16 KiB page support: Enables
platform/systrap/subblock_xplat.goon 16 KiB ARM64 kernels, preserving 4 KiB guest pages over 16 KiB host mappings. - Process budget clamping: Caps
idleStubLimitandmaxSysmsgThreadsat2per stub so sandboxes stay below Android's 32-child ceiling. - Zygote seccomp compatibility:
pkg/hostlockdowndetectsPR_GET_SECCOMP == 2, skips Landlock calls trapped withSIGSYS, and relies on SELinux and mount namespaces.
.github/workflows/android.yml executes scripts/android/emulator-smoke.sh on an x86-64 Android 16 KVM emulator. It runs tools/androidprobe, unit tests for systrap, hostfs, and ext4lite, offline e2e/, and gvx-sample.apk via adb shell am start-foreground-service. Physical ARM64 hosts verify arm64 emulator behavior manually because hosted runners lack nested ARM64 virtualization.
Consult ../compatibility.md and ../cli.md for host-wide limits and adb overrides; Android-specific invariants follow:
- 32 phantom-process ceiling: Android 12+ terminates child processes when total app children exceed 32. Keep concurrent guest processes below 10 or disable child restrictions.
- Background CPU throttling: Android kills background app child processes consuming sustained CPU; run long workloads from a foreground service.
- SELinux hard-link restriction:
linkatfails withEACCESon app-data files underhostfs; useext4litevolumes (-v data:/data) for hard links. - Landlock unavailable under Zygote:
Status.UnboundFileOpenBlockedstays false when attaching host bind mounts on Android (ext4lite-only runs keep it true).
This table maps the Android runtime, sample app, build scripts, and kernel probe files.
| Files | Role |
|---|---|
android/library/src/dev/gfire/gvx/Gvx.java |
Java launcher locating librungvx.so, setting app storage vars, and injecting --host-dns. |
android/sample/AndroidManifest.xml, android/sample/src/dev/gfire/gvx/sample/RunService.java |
Sample specialUse foreground service invoking Gvx.start and logging to files/run.log. |
scripts/android/build-sdk.sh, scripts/android/lib.sh, scripts/android/emulator-smoke.sh |
NDK build scripts for gvx-android.aar and gvx-sample.apk, plus CI smoke runner. |
tools/androidprobe/ |
Standalone Android kernel page-size, memfd, seccomp, and systrap probe tool. |
pkg/gvx/enginefault_android.go, pkg/sentry/platform/systrap/subblock_xplat.go, pkg/sentry/platform/systrap/hostpage_xplat.go |
Android diagnostic messages, 16 KiB sub-block paging, and 2-stub idle pool cap. |