Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#3,355 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
android, nodejs, python

調査の方向性

まず Termux で失敗を再現し、node-gyp のヘッダー選択をキャッシュされた common.gypi まで追跡します。特に OS == "android" ブランチと、そこから参照される android_ndk_path に注目してください。そのパスを、パッチが適用された /usr/include/node のヘッダーおよび --nodedir の回避策と比較します。Android で NDK がない場合に、未定義変数による誤解を招く失敗が発生しなくなり、選択したサポート対象のパスがテストでカバーされれば完了です。

索引モデルが 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時間
マージ済み PR(30日)
5

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nodejs/node-gyp のほかの issue

nodejs/node-gyp の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。