JaneaSystems / nodejs-mobile

Full-fledged Node.js on Android and iOS
https://code.janeasystems.com/nodejs-mobile
Other
2.58k stars 182 forks source link

Cannot find module node_sqlite3.node #171

Open ansoncsh opened 5 years ago

ansoncsh commented 5 years ago

Hi,

I am trying to build a nodejs application in an Android native app. I want to use sqlite3 module in the app. However I have got the following error.

E NODEJS-MOBILE: Error: Cannot find module '/data/data/com.yourorg.sample/files/nodejs-project/node_modules/sqlite3/lib/binding/node-v57-android-arm64/node_sqlite3.node'

I guess it is because I run npm install on my Mac and so it builds the node_sqlite3.node based on my Mac's version. nodejs-project/node_modules/sqlite3/lib/binding/node-v64-darwin-x64/node_sqlite3.node

How can I build the module based on different device versions? Or is there any suggestion to support sqlite from both Android native app and nodejs application?

Note: cordova can work fine but not for Android native.

Thank you!

jaimecbernardo commented 5 years ago

Hi @ansoncsh ,

sqlite3 is a native module, which means it has to be compiled for the OS/architectures it'll run on. The plugins have code for compiling native modules on their Gradle file and adding them to the APK assets: https://github.com/janeasystems/nodejs-mobile-cordova/blob/4a79e96b8f313296fb050ecc413f053d1ac7f5c8/src/android/build.gradle

You'd have to do something similar for your native application. There are yet no samples to use native modules outside the plugins.

Txiaozhe commented 4 years ago

how build for ios?

paulordyl commented 2 years ago

@ansoncsh ansoncsh Did you solve this?

ansoncsh commented 2 years ago

@ansoncsh ansoncsh Did you solve this?

I try to remember as it was long time ago 😅

As I remember, we finally built the app by using React Native. A bridge is developed for communication between nodejs and React Native app. Such that nodejs application could send data to React Native app.

i.e.

I guess Native App can do it similarly