ninja-android-bionic-patch.md 1.85 KB

Compiling Ninja from Source on Android Bionic

Problem

The ninja build tool is required for meson-based projects (like frida Python extension), but:

  1. Termux apt repo does not include a ninja package
  2. PyPI ninja wheels are compiled for glibc Linux, not Android Bionic libc — they fail with "required file not found" at runtime
  3. Compiling ninja from source hits Android Bionic compatibility issues

Solution

1. Download Source

curl -L -o ninja-src.tar.gz \
  "https://github.com/ninja-build/ninja/archive/refs/tags/v1.12.1.tar.gz"
tar -xzf ninja-src.tar.gz
cd ninja-1.12.1

2. Patch Android Bionic Compatibility

Bionic libc lacks struct sysinfo and SI_LOAD_SHIFT used in src/util.cc for load average calculation.

Patch src/util.cc around line 895:

Replace:

#elif defined(__UCLIBC__) || (defined(__BIONIC__) && __ANDROID_API__ < 29)
double GetLoadAverage() {
  struct sysinfo si;
  if (sysinfo(&si) != 0)
    return -0.0f;
  return 1.0 / (1 << SI_LOAD_SHIFT) * si.loads[0];
}

With:

#elif defined(__BIONIC__)
#include <sys/system_properties.h>
double GetLoadAverage() {
  return -0.0f;
}

This skips load average reporting on Android (not needed for build functionality).

3. Compile

python3 configure.py --bootstrap

4. Install

cp ninja /data/data/com.termux/files/usr/bin/ninja
ninja --version
# Output: 1.12.1

Pitfalls

  1. Do NOT use PyPI ninja wheel on Android — manylinux tag does not mean Bionic compatible
  2. The sysinfo error is a red herring — it's not about missing headers, it's about Bionic not implementing this Linux-specific feature
  3. Patch must be applied before bootstrap — the error appears during compilation, not configuration
  • frida-devkit-termux-compilation.md — Full frida devkit compilation flow that requires ninja