JaneaSystems / nodejs-mobile

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

how to run 'npm install' with android code #155

Open wtchaos opened 5 years ago

wtchaos commented 5 years ago

I Embed the nodejs in my android native project,and deploy the nodejs project on android system, but
I don‘t know how to install the node modules(run command in terminal?),how can I solve it, thanks.

jaimecbernardo commented 5 years ago

Hi @wtchaos ,

Have you looked at the sample that uses a node project folder? https://github.com/janeasystems/nodejs-mobile-samples/tree/1eb9c4c0f1e02b009ca55bc610cc9e8cda403afa/android/native-gradle-node-folder Or in the website? https://code.janeasystems.com/nodejs-mobile/android/node-project-folder#add-a-npm-module-to-the-nodejs-project

The "Resources for Newcomers" is a good place to start: https://github.com/janeasystems/nodejs-mobile/tree/2a0a302aa614ff966176f412756836b68e020ce2#resources-for-newcomers

wtchaos commented 5 years ago

Thanks @jaimecbernardo Yes, I have looked at the sample and the description in the website. It says "by running npm install {module_name} inside nodejs-project". Does it mean execute the command in the windows system, or MacOs, or Linux? But I want to execute "npm install" in the android system.Or am I getting it wrong?

jaimecbernardo commented 5 years ago

Hi @wtchaos , Yes, it's in the development machine that you must run npm install, so that the module is embedded in the APK and accessible at runtime. In the sample README, the instructions are to run the command in a development folder (android/native-gradle-node-folder/app/src/main/assets/nodejs-project/) : https://github.com/janeasystems/nodejs-mobile-samples/tree/1eb9c4c0f1e02b009ca55bc610cc9e8cda403afa/android/native-gradle-node-folder#how-to-run https://github.com/janeasystems/nodejs-mobile-samples/tree/1eb9c4c0f1e02b009ca55bc610cc9e8cda403afa/android/native-gradle-node-folder#add-an-npm-module-to-the-nodejs-project

wtchaos commented 5 years ago

Thanks for your reply @jaimecbernardo But sometimes, library needs compile in the production environment, like sqlite3. Perhaps,could you tell me how can I embed the sqlit3 into the nodejs-mobile?Thanks.

ralphtheninja commented 5 years ago

@wtchaos I'm guessing in the case of sqlite3 it needs to be cross compiled for your target android system.

wtchaos commented 5 years ago

Hi @ralphtheninja It's true that I need to compile it for android. But somebody recommend that compile the node-sqlite3 into Node.js as a core module.

jaimecbernardo commented 5 years ago

Hi @wtchaos , Native modules need to be cross compiled for Android. This is something the nodejs-mobile-cordova and nodejs-mobile-react-native plugins do. There's a sample for each plugin that runs the sqlite3 module sample code: https://github.com/janeasystems/nodejs-mobile-samples/tree/1eb9c4c0f1e02b009ca55bc610cc9e8cda403afa/cordova/UseNativeModules and https://github.com/janeasystems/nodejs-mobile-samples/tree/1eb9c4c0f1e02b009ca55bc610cc9e8cda403afa/react-native/UseNativeModules