Cordova is not available when ran on device


#1

I’m trying to use some native plugins, but I can’t quite test them.

// app.component.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

@Component({
    templateUrl: 'app.html'
})
export class MyApp {
    rootPage:any = 'LoginPage';
    
    //pushOpts: PushOptions;
    //pushObj: PushObject;
    
    constructor(private translate: TranslateService, private push: Push, platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
        platform.ready().then(() => {
            // Okay, so the platform is ready and our plugins are available.
            // Here you can do any higher level native things you might need.
            statusBar.styleDefault();
            splashScreen.hide();
        });
    }
    
}

When I run ionic cordova run android -l -c --device I get the followings:

[13:39:15] console.warn: Native: tried calling StatusBar.styleDefault, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator
[13:39:15] console.warn: Native: tried calling SplashScreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

And on the app:

Uncaught (in promise): cordova_not_available

What’s wrong? Specifying --device should make cordova available, right?


#2

No need to use the --device flag to get Cordova Available. Could you post the outcome of your ionic info and ionic cordova plugin list?


#3

I know it should works without the --device but I thought I’d really force it just to be sure.

Here is the infos and plugin list:

cli packages: (C:\Users\Pierre\AppData\Roaming\npm\node_modules)
@ionic/cli-utils : 1.19.1
ionic (Ionic CLI) : 3.19.1

global packages:
cordova (Cordova CLI) : 8.0.0

local packages:
@ionic/app-scripts : 3.1.8
Cordova Platforms : android 7.0.0
Ionic Framework : ionic-angular 3.9.2

System:
Android SDK Tools : 26.1.1
Node : v8.9.4
npm : 5.6.0
OS : Windows 10

> cordova plugin ls
cordova-plugin-camera 4.0.2 "Camera"
cordova-plugin-device 2.0.1 "Device"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-ionic 4.0.0 "IonicCordova"
cordova-plugin-ionic-keyboard 2.0.5 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.3 "Whitelist"
phonegap-plugin-push 2.2.2 “PushPlugin”


#4

Have you tried it without passing any flags to it? It could be something to do with live reload. Just a thought, eliminate everything extra and just try to run it with ionic cordova run android. Does that work?


#5

alright i can confirm as of this date, this happens to me as well, while my setup was fresh install. This is defo a bug which needs rather a quick fix. anyway, just run

ionic cordova plugin add cordova-plugin-statusbar

it should output something like this

> cordova plugin add cordova-plugin-statusbar --save
Installing "cordova-plugin-statusbar" for android

Android Studio project detected

Adding cordova-plugin-statusbar to package.json

Saved plugin info for "cordova-plugin-statusbar" to config.xml


and Volla! that’s it. you won’t receive cordova error anymore. You can test by connecting you phone and by running ionic cordova run android -l -c