简体   繁体   中英

Can't add a Cordova plugin to my PhoneGap project

I'm new to Phonegap (using CLI to start the project and manage it, and desktop to serve, both running on Windows8),

This is what I've done so far:

phonegap plugin add cordovarduino

Fetching plugin "cordovarduino" via npm

Plugin "fr.drangies.cordova.serial" already installed on android. Making it top-
level.

Plugin "fr.drangies.cordova.serial" already installed on browser.

On the project;

serialMonitor: function(){
        app.debug("Initializing Serial Monitor");
        try {
            //cordova.require("serial.js");
            serial.requestPermission({
                    driver: 'FtdiSerialDriver' // or any other
                },
                function success(){app.debug("Granted access");},
                function error()  {app.debug("Denied access");}
            );

        }catch(err) {
            app.debug("Error: "+ err.message);          
        }


    }

In platform/android/res/xml/config.xml:

<feature name="Serial">
    <param name="android-package" value="fr.drangies.cordova.serial.Serial" />
</feature>

But in platform/browser/res/xml/config.xml, there wasn't added, so I added it manually, as

<param name="android-package" value="fr.drangies.cordova.serial.Serial" />

and then replaced as

<param name="browser-package" value="fr.drangies.cordova.serial.Serial" />

Also included cordova.js and called serialMonitor() on ondeviceready event.

But I'm still getting :

serial is not defined

Maybe is not a bug!, any help please?

Alright, after struggling against PhoneGap CLI with issues related to Build Tools version, and some other stuff, I've managed to build and deploy on Android the .apk, once there, and ONLY WHEN OTG CABLE WAS PLUGGED AND ARDUINO DETECTED BY ANDROID (info for cordovarduino users), permissions where asked and eureka! "Granted access" was prompt, therefore serial object was found.

Conclussion:

Yes, some plugins are ment ONLY to work (became callable) on some platforms , and PhoneGap Developer App is, correct me if I'm wrong, a browser platform.

So running the compiled apk directly on that platform will allow some plugins to be callable in runtime, otherwise not.

Sorry if this was obvious to many people, but it was my first day on PhoneGap.

Live long and prosper.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM