Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cordova not available when running on android with the -l flag #3720

Closed
ionitron-bot bot opened this issue Oct 30, 2018 · 14 comments
Closed

cordova not available when running on android with the -l flag #3720

ionitron-bot bot opened this issue Oct 30, 2018 · 14 comments
Labels
bug project type: angular Ionic Angular 4+ projects

Comments

@ionitron-bot
Copy link

ionitron-bot bot commented Oct 30, 2018

Bug Report

Ionic Info

$ ionic info
√ Gathering environment info - done!

Ionic:

   ionic (Ionic CLI)             : 4.2.1 (C:\Users\Toch\AppData\Roaming\nvm\v10.10.0\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.0.0-beta.13
   @angular-devkit/build-angular : 0.8.6
   @angular-devkit/schematics    : 0.8.6
   @angular/cli                  : 6.2.6
   @ionic/angular-toolkit        : 1.0.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : not available
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 18 other plugins)

System:

   NodeJS : v10.10.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10

Describe the Bug
Whenever I try to run my ionic app with live-reloading enabled on my Android device (ionic cordova run android -l), None of my plugins work, and I get the warning message, Cordova not available. If I run the same command without the -l flag it runs fine, but one can imagine how frustrating development can be without live reloading

Steps to Reproduce
Steps to reproduce the behavior:

  1. create a new ionic app
  2. add the Android platform with some plugins
  3. run the command "ionic cordova run android -l"
  4. try to access any native feature
  5. See error

Expected Behavior
Cordova should be available when running on a real native device

Additional Context
I am using nvm to manage different versions of Node on my machine.

@imhoffd
Copy link
Contributor

imhoffd commented Oct 30, 2018

@Tochukwuibe Your dependencies look right to me. Which error do you see? I assume it's in the DevTools console of the device.

@Tochukwuibe
Copy link

Tochukwuibe commented Oct 30, 2018

@dwieeb yes, i see the warning that says, Cordova not available when I use chrome://inspect. this happens whenever i try to access any native features, I think the build server is either not adding or can't find Cordova js when you run on a native device using the -l flag. there was a similar issue like this in V3, the fix (hack) there was to go into the dist server folder under ionic in node modules and change the path to the Android platform, however, in v4 this doesn't work.

@imhoffd
Copy link
Contributor

imhoffd commented Oct 30, 2018

In v4, we're not in total control of the livereload server (because it's running serve from the Angular CLI), so we can't redirect requests to a given folder. What we do instead is here:

https://github.com/ionic-team/angular-toolkit/blob/7bc2839a79f2debc190d11386e2bb857913e9469/builders/cordova-build/index.ts#L35-L62

This code registers all the Cordova assets from a platform's platform_www folder and then adds cordova.js to index.html. It does all of this during a build (or a serve, for -l, which uses build), as long as you see that it's running ng run app:ionic-cordova-serve instead of the usual ng run app:serve.

@imhoffd
Copy link
Contributor

imhoffd commented Oct 30, 2018

@Tochukwuibe Can you verify that it's running ng run app:ionic-cordova-serve? If it is, check index.html for cordova.js and the related network requests for the Cordova assets.

@Tochukwuibe
Copy link

@dwieeb right after i run the command "ionic cordova run android -l " the cli then runs the command "ng run app:ionic-cordova-serve --host=0.0.0.0 --port=8100 --platform=android" but no cordova.js is not present in index.html

@Tochukwuibe
Copy link

@dwieeb i just tried adding cordova.js manually with a script tag to the head in index.html but the debug console shows a 404 error for cordova.js

@imhoffd
Copy link
Contributor

imhoffd commented Oct 30, 2018

@Tochukwuibe What are the contents of platforms/android/platform_www ?

@Tochukwuibe
Copy link

Tochukwuibe commented Oct 30, 2018

The folder structure is as follows @dwieeb

-cordova-js-src/
-plugins/
-cordova_plugins.js
-cordova.js

@imhoffd
Copy link
Contributor

imhoffd commented Oct 30, 2018

@Tochukwuibe That also looks right. I'm stumped so far. Can I see your angular.json file for the configuration of ionic-cordova-build and ionic-cordova-serve?

@Tochukwuibe
Copy link

@dwieeb here it is

"ionic-cordova-build": {
"builder": "@ionic/angular-toolkit:cordova-build",
"options": {
"browserTarget": "app:build"
},
"configurations": {
"production": {
"browserTarget": "app:build:production"
}
}
},
"ionic-cordova-serve": {
"builder": "@ionic/angular-toolkit:cordova-serve",
"options": {
"cordovaBuildTarget": "app:ionic-cordova-build",
"devServerTarget": "app:serve"
},
"configurations": {
"production": {
"cordovaBuildTarget": "app:ionic-cordova-build:production",
"devServerTarget": "app:serve:production"
}
}
}

@imhoffd
Copy link
Contributor

imhoffd commented Oct 30, 2018

@Tochukwuibe Oh, I'm sorry. I see what's wrong.

@imhoffd imhoffd added the bug label Oct 30, 2018
@ionitron-bot ionitron-bot bot removed the triage label Oct 30, 2018
@imhoffd imhoffd changed the title [V4 beta4.0.0.13] cordova not available when running on android with the -l flag cordova not available when running on android with the -l flag Oct 30, 2018
@Tochukwuibe
Copy link

@dwieeb feel free to share lol

@imhoffd
Copy link
Contributor

imhoffd commented Oct 31, 2018

@Tochukwuibe It was a bug in the @ionic/angular-toolkit package. Please update to the latest version (just released) and let me know if it resolves your issue:

npm i @ionic/angular-toolkit@latest

@Tochukwuibe
Copy link

yes, @dwieeb I can confirm that updating the @ionic/angular-toolkit package fixed the issue for me. Thank you

wand1252 added a commit to wand1252/angular-toolkit-develop that referenced this issue Aug 31, 2022
Using `validateBuilderOptions()` is key--it fills in default values from
the `schema.json` file. In this case, the new `cordovaAssets` option in
the cordova-build Builder defaults to `true`, but if cordova-serve uses
it without validating the options, the default is lost, resulting in
"cordova not available" issues.

fixes ionic-team/ionic-cli#3720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug project type: angular Ionic Angular 4+ projects
Projects
None yet
Development

No branches or pull requests

2 participants