JaneaSystems / nodejs-mobile

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

Cordova Plugin: nodejs-mobile-cordova plugin install fails for Cordova version 8.0 #48

Open algorist-mechanism opened 6 years ago

algorist-mechanism commented 6 years ago

Steps to repeat:

 cordova create MyApp
 cd MyApp
 cordova platform add android
 cordova plugin add nodejs-mobile-cordova --verbose

Expected behavior: cordova plugin add nodejs-mobile-cordova --verboseshould install successfully. See log below for failed install.


cordova plugin add nodejs-mobile-cordova --verbose
No scripts found for hook "before_plugin_add".
No version specified for nodejs-mobile-cordova, retrieving version from config.xml
No version for nodejs-mobile-cordova saved in config.xml or package.json
Attempting to use npm info for nodejs-mobile-cordova to choose a compatible release
Running command: npm view nodejs-mobile-cordova --json
Command finished with error code 0: npm view,nodejs-mobile-cordova,--json
Running command: /home/user/CordovaApp/platforms/android/cordova/version 
Command finished with error code 0: /home/user/CordovaApp/platforms/android/cordova/version 
Ignoring invalid version in nodejs-mobile-cordova cordovaDependencies: >=0.1.0 (must be a single version <= latest or an upper bound)
Ignoring nodejs-mobile-cordova cordovaDependencies entry because it did not contain any valid plugin version entries
Calling plugman.fetch on plugin "nodejs-mobile-cordova"
saving
Running command: npm install nodejs-mobile-cordova --production --save
Command finished with error code 0: npm install,nodejs-mobile-cordova,--production,--save
Copying plugin "/home/user/CordovaApp/node_modules/nodejs-mobile-cordova" => "/home/user/CordovaApp/plugins/nodejs-mobile-cordova"
Calling plugman.install on plugin "/home/user/CordovaApp/plugins/nodejs-mobile-cordova" for platform "android
Installing "nodejs-mobile-cordova" for android
Running command: /home/user/CordovaApp/platforms/android/cordova/version 
Command finished with error code 0: /home/user/CordovaApp/platforms/android/cordova/version 
Finding scripts for "before_plugin_install" hook from plugin nodejs-mobile-cordova on android platform only.
Executing script found in plugin nodejs-mobile-cordova for hook "before_plugin_install": plugins/nodejs-mobile-cordova/install/hooks/android/before-plugin-install.js
Resolving module name for q => q
Install start for "nodejs-mobile-cordova" on android.
PlatformApi successfully found for platform android
Android Studio project detected
Beginning processing of action stack for android project...
Installing Android library: src/android/build.gradle
Error during processing of action! Attempting to revert...
Failed to install 'nodejs-mobile-cordova': Error: Uh oh!
ENOENT: no such file or directory, open '/home/user/CordovaApp/platforms/android/AndroidManifest.xml'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.readFileSync (fs.js:551:33)
    at Object.parseElementtreeSync (/home/user/CordovaApp/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27)
    at new AndroidManifest (/home/user/CordovaApp/platforms/android/cordova/lib/AndroidManifest.js:29:20)
    at AndroidProject.getPackageName (/home/user/CordovaApp/platforms/android/cordova/lib/AndroidProject.js:99:12)
    at AndroidProject.getCustomSubprojectRelativeDir (/home/user/CordovaApp/platforms/android/cordova/lib/AndroidProject.js:105:28)
    at install (/home/user/CordovaApp/platforms/android/cordova/lib/pluginHandlers.js:106:46)
    at ActionStack.process (/home/user/CordovaApp/platforms/android/cordova/node_modules/cordova-common/src/ActionStack.js:56:25)
    at PluginManager.doOperation (/home/user/CordovaApp/platforms/android/cordova/node_modules/cordova-common/src/PluginManager.js:114:20)
    at PluginManager.addPlugin (/home/user/CordovaApp/platforms/android/cordova/node_modules/cordova-common/src/PluginManager.js:144:17)
(node:13195) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Uh oh!
ENOENT: no such file or directory, open '/home/user/CordovaApp/platforms/android/AndroidManifest.xml'
jaimecbernardo commented 6 years ago

Hi, @algorist-mechanism . Thank you for the issue and for your contribution.

For the moment, we plan to keep this plugin compatible with cordova 7 . It seems that making it compatible with cordova 8 would break cordova 7 compatiblity.

We'll leave this issue open for linking to your PR that brings compatibility with cordova 8: https://github.com/janeasystems/nodejs-mobile-cordova/pull/4

algorist-mechanism commented 6 years ago

@jaimecbernardo This is only applicable for a fresh install of cordova 8.0.0 using the android platform. You won't see this problem if you are upgrading from an earlier version or using just ios.

Here's a workaround for those using a fresh install of cordova 8.0.0. TLDR; Use cordova-android version 6.4. (or whatever the most current 6.x before 7.0 is)

cordova create MyApp
cd MyApp
cordova platform add android@6
cordova plugin add nodejs-mobile-cordova

Longer version: Note: cordova means the package installed with npm install cordova. The versions of interest are cordova 8.0.0 and 7.1.0. cordova-android is the package installed with cordova platform add android. The versions of interest are 7.0.0 (default for cordova 8.0) and 6.x (default for cordova 7.1.0).

cordova 8.0.0 pins the default android platform as cordova-android 7.0.0. Here's how we know, from running the following after a fresh install.

cordova platform ls
Installed platforms:

Available platforms: 
  android ~7.0.0
  browser ~5.0.1
  ios ~4.5.4
  osx ~4.0.1
  windows ~5.0.0
  www ^3.12.0

cordova-android 7.0.0 uses and creates the new Android Studio directory structure as a default. That new structure breaks the nodejs-mobile-cordova plugin since files aren't where they expect them to be.
https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/Api.js#L82-L93 for those curious to what some of the changes are.

We want to use the "legacy" Eclipse directory structure. cordova-android 6.4.0 creates and uses it. So instead of using the default cordova-android that cordova 8 uses, we instead use

cordova platform add android@6

and can successfully proceed with

cordova plugin add nodejs-mobile-cordova

The good news, once you have the Eclipse directory structure in use, cordova won't switch you to the new Android Studio directory structure. It only does that for new installations.

jaimecbernardo commented 6 years ago

Hi @algorist-mechanism , Thank you for the workaround!

lastmjs commented 6 years ago

I'm using the workaround, I'm using Cordova 8.0.0, and I have the Android NDK installed. Is the nodejs variable supposed to be a global variable accessible through the window object? I'm not seeing it.

jaimecbernardo commented 6 years ago

Hi @lastmjs , No not through the window object. Sample code would be a place to start: https://github.com/janeasystems/nodejs-mobile-cordova#usage

humanely commented 5 years ago

I am seeing this problem with ios. I am not using android. Here is my stack: Installed platforms: ios 4.5.5 Available platforms: browser ~5.0.1 osx ~4.0.1 windows ~6.0.0

The following build commands failed: Ld /Users/mc/Library/Developer/Xcode/DerivedData/hdapp2-afrozyqeoetarqbiqdxpuqmwuxru/Build/Intermediates.noindex/ArchiveIntermediates/hdapp2/IntermediateBuildFilesPath/hdapp2.build/Debug-iphoneos/hdapp2.build/Objects-normal/armv7/hdapp2 normal armv7 (1 failure)

Any resolution please?

jaimecbernardo commented 5 years ago

Hi @jollysean,

This shouldnt' be a problem if the instructions to set the Deployment Target to 11.0 have been followed, since 11.0 wouldn't support armv7 CPUs. Is this helpful?

code-ishwar commented 5 years ago

Any solution on this?

jaimecbernardo commented 5 years ago

Hi @tim-coin , Have you tried the workaround suggested in an earlier comment? https://github.com/janeasystems/nodejs-mobile/issues/48#issuecomment-366858320

code-ishwar commented 5 years ago

Hi @jaimecbernardo

We need the new structure of cordova 8 in our app.

jaimecbernardo commented 5 years ago

Hi @tim-coin , unfortunately, Cordova 8 structure is not supported yet, since we want to support Cordova 7 still and there are some incompatibilities. If you get it working, please consider leaving some comments on what you've changed for other users who might need it.

nebi19 commented 5 years ago

i have the same problem i try all the above solution but not worked