Comments (5)
No, unfortunately native packages aren't automatically rebuilt for mobile platforms. If a native package isn't built for mobile platforms, you have to do it by yourself.
I haven't tried yet, but maybe you can make use of the "override" field in your package.json. See https://docs.npmjs.com/cli/v9/configuring-npm/package-json?v=true#overrides and npm/cli#4909
You could try overriding your dependency's sodium-native
package with the sodium-native-nodejs-mobile
package, which should work on android and ios.
You might try something like this for a npm module:
"overrides": {
"your_dependency": {
"sodium-native": "npm:sodium-native-nodejs-mobile@version"
}
}
or for a module not hosted on npm:
"overrides": {
"your_dependency": {
"sodium-native": "github:staltz/sodium-native-nodejs-mobile"
}
}
Let me know if it works so I can add a note to the readme.
from capacitor-nodejs.
I've been using this hacky shell script (in combination with ncc) until i containerize it properly to build and bundle for android. I'm sure i'll need a different approach for ios though, whenever i happen to need it.
export PATH=$PATH:$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/
toolchain_target_arch=aarch64
node_target_arch=arm64
android_api_level=$ANDROID_API_LEVEL
export CC=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/${toolchain_target_arch}-linux-android${android_api_level}-clang
export CXX=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/${toolchain_target_arch}-linux-android${android_api_level}-clang++
export LINK=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/${toolchain_target_arch}-linux-android${android_api_level}-clang++
export AR=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
export npm_config_verbose=1
export npm_config_nodedir=${ANDROID_LIBNODE_PATH}
export npm_config_arch=${node_target_arch}
export node_config_plaform=android
export node_config_format=make-android
mv node_modules ../node_modules.bak
# --from-from-source is used by node-pre-gyp
npm install --build-from-source
# Remove executable permissions from native node modules
find node_modules -iname '*.node' -exec chmod -x '{}' \;
buildroot=$(pwd)/ncc
target=arm64-android
buildpath="${buildroot}/${target}"
if [ ! -d "${buildpath}" ]; then
mkdir -p "${buildpath}"
fi
ncc build --source-map -d --asset-builds --target es2022 -o ${buildpath} src/offline.ts
rm -rf node_modules
mv ../node_modules.bak node_modules
EDIT: i notice it shouldn't actually be ANDROID_LIBNODE_PATH
, but rather just LIBNODE_PATH
from capacitor-nodejs.
Thanks for sharing your script @jrobeson.
Maybe we could provide an automatic rebuild of native dependencies for mobile platforms in the future. But honestly I don't see such a feature soon, as I haven't worked with native modules yet and have other priorities at the moment.
from capacitor-nodejs.
the cordova plugin did a lot of work to compile/recompile deps, but i wouldn't wanna handle it the context of the android build myself. It'd be done better as part of your node application's own build steps. It might be nice to find a way to plug it into vite or webpack though as part of your ionic or pure capacitor setup though.
from capacitor-nodejs.
Until I find time to look into it, the prebuild-for-nodejs-mobile tool could be used to compile native node.js modules for mobile devices.
from capacitor-nodejs.
Related Issues (20)
- Separate example projects in a new repo HOT 2
- npm install failed HOT 2
- Cannot find module 'bridge' on Android HOT 1
- Upgrade to CapacitorJS v5
- Rewrite the Bridge package in TypeScript
- Start the node.js runtime as child process on ElectronJS
- Did you rebase the main branch? HOT 1
- How does one use the new builtin bridge package from the node project? HOT 6
- Add a method to stop nodejs HOT 1
- How to use manual mode start? HOT 4
- iOS support? HOT 13
- How do I use this plugin in Quasar's capacitor. HOT 3
- Any way of debugging the nodejs code? HOT 5
- How to build for Android with node.js native node modules HOT 2
- Could not run on device only in debug mode HOT 5
- node.js upgrade HOT 10
- Add TypeScript Declaration File for Bridge Package HOT 1
- Example Project HOT 8
- Allow manual startup of the node.js runtime and pass environment variables HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from capacitor-nodejs.