Search code examples
androidcordovacordova-plugins

Cordova "Console" plugin not working


I added the plugin via

cordova plugin add cordova-plugin-console

The i emulated on adroid the default project created (with device ready event demo)

In the logcat I see

I/chromium( 1330): [INFO:CONSOLE(173)] "Received Event deviceReady", source: file:///android_asset/www/plugins/cordova-plugin-console/www/console-via-logger.js (173)
D/PluginManager( 1330): exec() call to unknown plugin: Console

This is a problem because I've not trace of the line when console.log is invocated and this create some trouble when debugging.

This is my 'compacted' js code

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        var parentElement = document.getElementById("deviceready");
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event deviceReady');
    },

};

app.initialize();

Also, I'd like to know why a freshly new created prject is already giving an error !!

EDIT: I already tried to remove and re-add the plugin, but this has not fixed the problem.


Solution

  • Removing and readding the plugin via cordova plugin doesn't work.

    Simply, install the plugin using npm

    cordova plugin remove cordova-plugin-console
    npm install cordova-plugin-console
    

    After restartred android emulation of my cordova project, everything works.

    Now I've the log row as expected (here splitted into 2 rows just for better readings):

    I/chromium( 1416): [INFO:CONSOLE(36)] "Received Event deviceReady", 
    source: file:///android_asset/www/js/index.js (36)