gyp: 'Undefined variable android_ndk_path' when building native modules on Android (Termux) without NDK
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- android, nodejs, python
- Área
- build-system, mobile-dev, tooling
Línea de trabajo
Empieza reproduciendo el fallo en Termux y sigue la selección de headers de node-gyp hasta el common.gypi en caché, especialmente la rama OS == "android" y su referencia a android_ndk_path. Compara esa ruta con los headers parcheados de /usr/include/node y la alternativa --nodedir; se considera terminado cuando Android sin un NDK ya no produce el fallo engañoso de variable no definida y el camino compatible elegido tiene cobertura.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
Building any native module with node-gyp on Android (Termux) fails with an unhelpful gyp error, even though a working toolchain (clang) is installed:
gyp: Undefined variable android_ndk_path in binding.gyp while trying to load binding.gyp
Environment: Termux on Android 15 (aarch64), Node v26.4.0, npm 12.0.2, clang 21, no NDK (Android NDK is not practical to install on Termux; the system provides its own bionic toolchain).
Root cause chain
- Termux's python3 reports
sys.platform == "android", so gyp selects theandroidflavor. - node-gyp does not use the headers shipped with the Node package (
/usr/include/node/common.gypi, which Termux's packaging already patches for this exact issue); instead it downloads the official Node headers from nodejs.org into~/.cache/node-gyp/<version>/. - The official
common.gypihas anOS == "android"branch that references<(android_ndk_path)/sources/android/cpufeatures. On a plain Android system with no NDK,android_ndk_pathis undefined and gyp aborts with the message above — it reads as an internal gyp bug rather than a missing-NDK situation.
Expected behavior
- Either node-gyp should prefer locally installed Node headers when present (Termux's
/usr/include/nodeis a valid, already-patched header set), or - on Android without an NDK, emit an actionable error (e.g. "building native modules on Android requires the Android NDK, or use the system toolchain via
--nodedir=/usr/include/node") instead ofUndefined variable android_ndk_path.
Workaround (used successfully)
Patch ~/.cache/node-gyp/26.4.0/include/node/common.gypi: in the OS == "android" branch, replace -I<(android_ndk_path)/sources/android/cpufeatures with the system include dir. After that, node-pty and other native modules compile and link fine against the Termux bionic toolchain.
This affects every Termux user who builds native npm modules (node-pty, sharp, koffi, etc.).
- Lenguaje dominante
- Python
- Estrellas
- 10.7k
- Forks
- 1.9k
- Merge medio
- 1 d 4 h
- PR fusionados (30 d)
- 5
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nodejs/node-gyp
-
dependencies github_actions
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
-
MSYS2
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 10/100
Todos los issues de nodejs/node-gyp
Issues similares
-
bug confirmed issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
open-webui/open-webui#30750 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100