JaneaSystems / nodejs-mobile-samples

Repository for demo applications that use Node.js on Mobile
MIT License
168 stars 111 forks source link

npm install error on ''Cordova: Use Native Modules' #11

Open SamiNodejs opened 5 years ago

SamiNodejs commented 5 years ago

Hi, Please how to install a new npm module using the version ''Cordova: Use Native Modules''. It works on ''Native Gradle Sample using a Node Project folder '' but with ''Cordova: Use Native Modules'' I get the error message ''Unsupported opperating system for nodejs-mobile native builds: Windows 7''. thank you for you help.

jaimecbernardo commented 5 years ago

Hi @SamiNodejs , That's because native module cross building is not supported on Windows. Here's a disclaimer in the sample: https://github.com/janeasystems/nodejs-mobile-samples/tree/1eb9c4c0f1e02b009ca55bc610cc9e8cda403afa/cordova/UseNativeModules#cordova-use-native-modules-sample

Disclaimer: Building native modules is only available on macOS and Linux at the time of writing this sample.

The same information can be found in the plugin's README.md : https://github.com/janeasystems/nodejs-mobile-cordova/tree/be459ac4702a825a9254be03fc9448a5487436db#native-modules

SamiNodejs commented 5 years ago

Thank you very much for taking the time to answer. Sorry, inadvertently, I didn't read that disclaimer. After installing Nodejs modules in Linux could we import the project to Android studio in windows? I’ve tried to build the project ‘’Cordova Use Native Modules Sample’’ on ubuntu (18.04) but I still receive the error message below. Sorry for newbie question, is this related to Cordova version? How could we install the old version of Cordova (ver7.)? I tried to uninstall Cordova 8 using: sudo npm uninstall -g cordova , but I still receive : cordova –version -> 8.1.2 (cordova-lib@8.1.1) ! How should we install sqlite3 and sha3 modules in order to build cordova examples?

This is part of the received message when building ’’Cordova Use Native Modules Sample’’ using Android studio: Cause: error=2, No such file or directory org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':BuildNpmModulesarmeabi-v7a'. at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:145) at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:115) at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78) ... 3 more Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'npm' at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27) at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36) at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:67) ... 4 more Caused by: java.io.IOException: Cannot run program "npm" (in directory "/home/sami/cordovatest2/nodejs-mobile-samples/cordova/UseNativeModules/platforms/android/build/nodejs-native-assets-temp-build/nodejs-native-assets-armeabi-v7a/nodejs-project"): error=2, No such file or directory at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25) ... 6 more Caused by: java.io.IOException: error=2, No such file or directory

jaimecbernardo commented 5 years ago

Hi,

After installing Nodejs modules in Linux could we import the project to Android studio in windows?

The native-assets folders created for the final APK could manually be added to the application assets and be picked up at runtime. This could work. Give it a try and let us know if it works.

Sorry for newbie question, is this related to Cordova version? How could we install the old version of Cordova (ver7.)?

Starting from the sample instructions, it will install the cordova-android 6.4.0, which is the cordova-android for cordova 7.0, so it should be fine. cordova platforms add cordova-android@6.4.0 would be the way to use the proper platform version for newer cordova versions.

Could not start 'npm' Cannot run program "npm" Caused by: java.io.IOException: error=2, No such file or directory

It looks like npm is not accessible through the command line on your development machine. That's why you are getting that error. 'node' and 'npm' are requisites for building native modules, since the process essentially calls npm rebuild with the right environment.