Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

gyp: 'Undefined variable android_ndk_path' when building native modules on Android (Termux) without NDK

未关闭
#3,355 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
android, nodejs, python

调研方向

首先在 Termux 上重现该故障,并将 node-gyp 的头文件选择过程追踪到缓存的 common.gypi,尤其关注 OS == "android" 分支及其对 android_ndk_path 的引用。将该路径与已打补丁的 /usr/include/node 头文件以及 --nodedir 变通方案进行比较;完成标准是:没有 NDK 的 Android 不再产生误导性的未定义变量故障,并且所选择的受支持路径已有覆盖。

由索引模型根据 Issue 内容生成。

描述

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
  1. Termux's python3 reports sys.platform == "android", so gyp selects the android flavor.
  2. 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>/.
  3. The official common.gypi has an OS == "android" branch that references <(android_ndk_path)/sources/android/cpufeatures. On a plain Android system with no NDK, android_ndk_path is 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/node is 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 of Undefined 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.).

主要语言
Python
星标
10.7k
派生
1.9k
平均合并
1 天 4 小时
30 天内合并 PR
5

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nodejs/node-gyp 的其他 Issue

查看 nodejs/node-gyp 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。