how to install node-sqlite3 on android (termux)?
I install all dependencies, including sqlite3 via npm install.
But when I run the script, I get an error:
Error: Cannot find module '/data/data/com.termux/files/home/myfolder/node_modules/sqlite3/lib/binding/napi-v3-android-arm/node_sqlite3.node
I tried to find a solution on my own, but I couldn't do it (everything is pretty unclear). I hope you help me.
@Moonquit how to do plz
@FxPixels I just used yarn instead of npm (yarn install) and everything was fine
Not for me:
yarn install v1.22.19
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
warning sqlite3 > node-gyp > make-fetch-happen > cacache > @npmcli/[email protected]: This functionality has been moved to @npmcli/fs
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning " > [email protected]" has unmet peer dependency "@types/node@*".
[4/4] Building fresh packages...
error /data/data/com.termux/files/home/TediCross/node_modules/sqlite3: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments:
Directory: /data/data/com.termux/files/home/TediCross/node_modules/sqlite3
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using [email protected]
node-pre-gyp info using [email protected] | android | arm64
node-pre-gyp info check checked for "/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/lib/binding/napi-v6-android-unknown-arm64/node_sqlite3.node" (not found)
node-pre-gyp http GET https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.2/napi-v6-android-unknown-arm64.tar.gz
node-pre-gyp ERR! install response status 404 Not Found on https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.2/napi-v6-android-unknown-arm64.tar.gz
node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v93 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.2/napi-v6-android-unknown-arm64.tar.gz
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | android | arm64
gyp info ok
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | android | arm64
gyp info find Python using Python version 3.11.0 found at "/data/data/com.termux/files/usr/bin/python3"
gyp info spawn /data/data/com.termux/files/usr/bin/python3
gyp info spawn args [
gyp info spawn args '/data/data/com.termux/files/home/TediCross/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/data/data/com.termux/files/home/TediCross/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/data/data/com.termux/files/home/.cache/node-gyp/16.18.1/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/data/data/com.termux/files/home/.cache/node-gyp/16.18.1',
gyp info spawn args '-Dnode_gyp_dir=/data/data/com.termux/files/home/TediCross/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/data/data/com.termux/files/home/.cache/node-gyp/16.18.1/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/data/data/com.termux/files/home/TediCross/node_modules/sqlite3',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info ok
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | android | arm64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/build'
CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
AR(target) Release/obj.target/../node-addon-api/nothing.a
/data/data/com.termux/files/usr/bin/sh: 1: ar: not found
make: *** [../node-addon-api/nothing.target.mk:132: Release/obj.target/../node-addon-api/nothing.a] Error 127
make: Leaving directory '/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/data/data/com.termux/files/home/TediCross/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (node:events:513:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Linux 4.9.309-shift-ab150
gyp ERR! command "/data/data/com.termux/files/usr/bin/node" "/data/data/com.termux/files/home/TediCross/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/lib/binding/napi-v6-android-unknown-arm64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/lib/binding/napi-v6-android-unknown-arm64" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=6" "--node_napi_label=napi-v6"
gyp ERR! cwd /data/data/com.termux/files/home/TediCross/node_modules/sqlite3
gyp ERR! node -v v16.18.1
gyp ERR! node-gyp -v v8.4.1
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/home/TediCross/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/lib/binding/napi-v6-android-unknown-arm64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/lib/binding/napi-v6-android-unknown-arm64 --napi_version=8 --node_abi_napi=napi --napi_build_version=6 --node_napi_label=napi-v6' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/data/data/com.termux/files/home/TediCross/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
node-pre-gyp ERR! stack at ChildProcess.emit (node:events:513:28)
node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1100:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
node-pre-gyp ERR! System Linux 4.9.309-shift-ab150
node-pre-gyp ERR! command "/data/data/com.termux/files/usr/bin/node" "/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /data/data/com.termux/files/home/TediCross/node_modules/sqlite3
node-pre-gyp ERR! node -v v16.18.1
node-pre-gyp ERR! node-pre-gyp -v v1.0.10
node-pre-gyp ERR! not ok
Failed to execute '/data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/home/TediCross/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/lib/binding/napi-v6-android-unknown-arm64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/data/data/com.termux/files/home/TediCross/node_modules/sqlite3/lib/binding/napi-v6-android-unknown-arm64 --napi_version=8 --node_abi_napi=napi --napi_build_version=6 --node_napi_label=napi-v6' (1)
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
It seems like something gets the environment and plugs that into the URL, but there is nothing for Android. How do I figure out what triggers this?
Similar with npm. #1515 has the same issue.
Look at the output:
/data/data/com.termux/files/usr/bin/sh: 1: ar: not found
Try installing the binutils package on Termux that provides that command. With some patience, it compiled well for me:
.../opt/pass-converter $ yarn install
yarn install v1.22.19
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
warning sqlite3 > node-gyp > make-fetch-happen > cacache > @npmcli/[email protected]: This functionality has been moved to @npmcli/fs
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > [email protected]: Use your platform's native performance.now() and performance.timeOrigin.
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 154.52s.
Oh, that looked like a continuation of the previous line, because everything else starts with "gyp info" or "gyp ERR". Thanks, now it works! (Tried with npm again.) IMO that package should just be preinstalled on every Linux system.
well its android, we were not ment to have access to shell/bash
Exit code: 1
Command: prebuild-install || node-gyp rebuild --release
Arguments:
Directory: /data/data/com.termux/files/home/site/node_modules/better-sqlite3
Output:
prebuild-install warn install No prebuilt binaries found (target=19.9.0 runtime=node arch=arm libc= platform=android)
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | android | arm
gyp info find Python using Python version 3.11.3 found at "/data/data/com.termux/files/usr/bin/python3"
gyp info spawn /data/data/com.termux/files/usr/bin/python3
gyp info spawn args [
gyp info spawn args '/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/data/data/com.termux/files/home/site/node_modules/better-sqlite3/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/data/data/com.termux/files/home/.cache/node-gyp/19.9.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/data/data/com.termux/files/home/.cache/node-gyp/19.9.0',
gyp info spawn args '-Dnode_gyp_dir=/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/data/data/com.termux/files/home/.cache/node-gyp/19.9.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/data/data/com.termux/files/home/site/node_modules/better-sqlite3',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/data/data/com.termux/files/home/site/node_modules/better-sqlite3/build'
TOUCH ba23eeee118cd63e16015df367567cb043fed872.intermediate
ACTION deps_sqlite3_gyp_locate_sqlite3_target_copy_builtin_sqlite3 ba23eeee118cd63e16015df367567cb043fed872.intermediate
TOUCH Release/obj.target/deps/locate_sqlite3.stamp
CC(target) Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o
rm -f Release/obj.target/deps/sqlite3.a Release/obj.target/deps/sqlite3.a.ar-file-list; mkdir -p dirname Release/obj.target/deps/sqlite3.a
ar crs Release/obj.target/deps/sqlite3.a @Release/obj.target/deps/sqlite3.a.ar-file-list
make: ar: No such file or directory
make: *** [deps/sqlite3.target.mk:218: Release/obj.target/deps/sqlite3.a] Error 127
rm ba23eeee118cd63e16015df367567cb043fed872.intermediate
make: Leaving directory '/data/data/com.termux/files/home/site/node_modules/better-sqlite3/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23)
gyp ERR! stack at ChildProcess.emit (node:events:513:28)
gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Linux 4.19.127-perf-g7288046673d5
gyp ERR! command "/data/data/com.termux/files/usr/bin/node" "/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--release"
gyp ERR! cwd /data/data/com.termux/files/home/site/node_modules/better-sqlite3
gyp ERR! node -v v19.9.0
gyp ERR! node-gyp -v v9.3.1
gyp ERR! not ok
well its android, we were not ment to have access to shell/bash
I think Termux is running a little Linux system within the app. Using a root shell of Android itself (like via ADB) is quite different.
Look at the output:
/data/data/com.termux/files/usr/bin/sh: 1: ar: not foundTry installing the
binutilspackage on Termux that provides that command. With some patience, it compiled well for me:.../opt/pass-converter $ yarn install yarn install v1.22.19 info No lockfile found. warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. [1/4] Resolving packages... warning sqlite3 > node-gyp > make-fetch-happen > cacache > @npmcli/[email protected]: This functionality has been moved to @npmcli/fs warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > [email protected]: Use your platform's native performance.now() and performance.timeOrigin. [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... success Saved lockfile. Done in 154.52s.
Hey bro Your guide works like harry potter's wand (does magic)...thanks🪄✨ :)
to install sqlite in termux : 1- pkg install clang libsqlite pkg-config 2- pkg install sqlite
``
When I try this again now, it fails, without giving any useful info, as far as I can see. There is just "command failed". Full log: https://pastebin.com/iRWgvkyG
Same
prebuild-install warn install No prebuilt binaries found (target=6 runtime=napi arch=arm64 libc= platform=android)
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | android | arm64
(node:21286) [DEP0060] DeprecationWarning: The util._extend API is deprecated. Please use Object.assign() instead.
gyp: Undefined variable android_ndk_path in binding.gyp while trying to load binding.gyp
hey, did anyone get this issue solved? i've been getting the same android_ndk_path issue when building sqlite3
Yes. I solved it. I don't remember exactly how I did it; it involved a lot of compilation packages and downloading an AndroidNDK, setting gyp to that path.
Fortunately, I made a script... https://github.com/weskerty/MysticTools/blob/main/Utilidades/Lev/Termux2.sh
But it installs a WhatsApp bot. ~You can ignore it and delete it when finished, or review the script and remove the necessary sections.~
Here. Try.
pkg install -y tur-repo x11-repo && \
apt-get update && \
pkg install -y python nano clang make git ffmpeg nodejs-lts pkg-config libxml2 libxslt matplotlib xorgproto rust binutils wget build-essential libvips python-pip glib openjdk-21 file libsqlite sqlite && \
pip install cython wheel setuptools python-dotenv && \
export ANDROID_NDK_HOME=~/android-ndk/android-ndk-r27b && \
export PATH=$ANDROID_NDK_HOME:$PATH && \
mkdir -p ~/.gyp && \
mkdir -p ~/android-ndk && \
curl -fsSL https://github.com/lzhiyong/termux-ndk/releases/download/android-ndk/android-ndk-r27b-aarch64.zip -o ~/android-ndk.zip && \
unzip ~/android-ndk.zip -d ~/android-ndk && \
rm ~/android-ndk.zip && \
curl -fsSL https://raw.githubusercontent.com/weskerty/MysticTools/refs/heads/main/Utilidades/Lev/include.gypi -o ~/.gyp/include.gypi
Many of these packages are unnecessary. But I can't remember which one was relevant, haha.
@weskerty thanks its working 😄