Third party Cordova plugins undefined in P10

Third party Cordova plugins undefined in P10

  

Hello,

In our project we have to use several Cordova plugins but currently I'm having trouble with version 10.

Following the instructions in this video http://www.outsystems.com/learn/lesson/801/plugins/ I've added blank module to my application with reference to flashlight plugin and adding SwitchOn action but have an error calling it "undefined is not an object (evaluating 'window.plugins.flashlight.switchOn')"

https://cordova.apache.org/plugins/?q=flash

I've tried with another plugin that I was working with in project on platform version 9 - https://www.npmjs.com/package/cordova-plugin-zeroconf but end up with similar error "undefined is not an object (evaluating 'cordova.plugins.zeroconf.register')"


Am I missing something or there is a bug or missing steps in tutorial to access third-party Cordova plugins?


Thank you.



Hi Mykola,


Everything you did seems right, so I'm a bit puzzled. I screened the video real quick, and noticed that it doesn't refer to the actual generation of the mobile app. Did you generate and install your "PluginsTest" app, or are you testing it on OutSystems Now?

I'm not sure if you are aware, but custom plugins need to be included in the native shell. Although OutSystems Now that's available on the stores includes some plugins, new plugins need to be included in a custom version of the shell you are meant to generate.

Please find a screenshot of where to do it below.



I hope this makes it clear. This page above is clear on how and where to get what you need to generate the application, but please let me know if you have any additional question on how to do it.


Kind Regards,

João Grazina

Hi João ,

That's right - I was using OutsystemsNow app... Thank you for the hint.

However Flashlight plugin is working properly but zeroconf plugin is not..  In list of scripts I see cordova plugin file  with flashlight and other plugins installed and specific file Flashlight.js but for zeroconf none of that. I assume it is not installing correctly but can't get any clue why and how can I fix it.

I will appreciate any tip.

Thank you.

Regards,

Nick


Hi Nick,


From what I saw, you're not using the RegisterService defined in the ZeroConfPlugin eSpace, you're directly using the plugin on a JS Node in OnClickZeroconf. 

However, that should not be a problem... as long as you can check object "cordova.plugins.zeroconf" is present, the plugin should be installed, and then it's just a matter of evolving from there. Can you confirm you have that plugin present? 


Kind Regards,

João Grazina

Hi João,

That's exactly the problem - plugin seems not to be present. I've tried RegisterService on plugin eSpace and directly on JS Node but the object is undefined and looking through resources files on Safari with connected device on cordova plugins file the Zeroconf is not presented. 

However I've tried now to use only one plugin and there is an error while generating the app:
The following errors have occurred:• iOS: An unexpected error has occurred while generating your application. Please try again. If the problem persists, contact OutSystems Support.

I've attached oml files . It there any way to see what error occurs?

Hello Nick

The latest version of the plugin doesn't build in iOS. However, if you use release 1.1.2 should work.


https://github.com/becvert/cordova-plugin-zeroconf#1.1.2


Can you try it? 

Thanks

I've tried set

{
    "plugin":
    {
        "url":"https://github.com/becvert/cordova-plugin-zeroconf#1.1.2"
    }
   
}

that's correct?

and app compiled. But it crashes immediately when launching.

Solution

Hello Nick.

The problem is that they introduced a "breaking change" in the plugin in the last commit and updated the example. The example in the page uses "name" as the third parameter:

zeroconf.register('_http._tcp.', 'local.', 'Becvert\'s iPad', 80, {
    'foo' : 'bar'
}, function success(result){
    var action = result.action; // 'registered'
    var service = result.service;
});

However, in version 1.1.2 (the one I advised you) there was no name available, so, the code

let port = command.argument (at: 2) as! Int

Throws an exception because it's expecting an Integer (port) where the example is passing a string (name).

Wrapping up, the example for 1.1.2 should be something like:

zeroconf.register('_http._tcp.', 'local.', 80, {
    'foo' : 'bar'
}, function success(result){
    var action = result.action; // 'registered'
    var service = result.service;
});

With port as the third parameter.

Can you give it a try?

Thanks

Solution

That's perfect César!  Thanks a lot for the tip - it worked perfectly. I've made only one change - first parameter is domain and second is my service's name... 

zeroconf.register('http._tcp.local.', 'test service name', 80, {...});

That will work for now:) I'm very glad and thank you very much.



Hi César,

I have again same problem but on another environment now...

It is not working on our Development environment (no latest version not previous that worked on personal environment)
I've tried
{
    "plugin":
    {
        "url":"https://github.com/becvert/cordova-plugin-zeroconf"
    }
}

and 
I've tried
{
    "plugin":
    {
        "url":"https://github.com/becvert/cordova-plugin-zeroconf#1.1.2"
    }
}


Environment Version 10.0.105.0

Are there more details from the error and how to resolve this issue?


Thank you

Hello Nick.

What's the behavior you're getting? Do you have an error when building the application or the plugin isn't there?

Thanks

Hello César,

Thanks for quick reaction :)

I can't build iOS native app:

The following errors have occurred:
• iOS: An unexpected error has occurred while installing the Cordova plugins. Please try again. If the problem persists, contact OutSystems Support.


Android is building and working on both versions.

Hello Nick.

Sorry for the late reply. Can you retry and see if it builds? 

Thanks

Hi César,

It is still same error. Also I've tried to compile again on personal environment and it is not working now showing same error message... That is weird... Are there constant changes on the script that generates apps or it is tied to platform version? 

Might it be related that versions of Platform are different - on my personal its 10.0.200.2 and on dev  is 10.0.105.0?




Hello Nick.

Can you try the latest version? #1.2.1?

Thanks

Hi César,

It did work. 

Thank you very much.

Mykola (Nick) Tkachenko wrote:

Hi João ,

That's right - I was using OutsystemsNow app... Thank you for the hint.

However Flashlight plugin is working properly but zeroconf plugin is not..  In list of scripts I see cordova plugin file  with flashlight and other plugins installed and specific file Flashlight.js but for zeroconf none of that. I assume it is not installing correctly but can't get any clue why and how can I fix it.

I will appreciate any tip.

Thank you.

Regards,

Nick


Hi Mykola..

What you did to make this work? How can i generate app(ios,apk) by using my personal env?


thanks,

Rocky

Hi Rocky, 

You can't generate apps on personal environment.

Hello Nick.

You can generate mobile apps using a personal environment. 

Hello Guys,

I am trying to use OpenALPR plugin [Automatic License Plate Recognition]. 

 Code Snippet

{
    "plugin": {
        "url": "https://github.com/iMicknl/cordova-plugin-openalpr.git"
    }
}

 based on above discussion I understand that I can't test this with outsystem now so i'm trying to build android application but its ending up with the error saying :

   " Error fetching cordova plugin: https://github.com/iMicknl/cordova-plugin-openalpr.git " 

I have tried by putting version name in URL but still its same.

Can you please help me to understand if I am missing anything also I will appreciate your help regarding possible ways to debug my code once I successfully built it 

Thanks

pankaj - wrote:

Hello Guys,

I am trying to use OpenALPR plugin [Automatic License Plate Recognition]. 

 Code Snippet

{
    "plugin": {
        "url": "https://github.com/iMicknl/cordova-plugin-openalpr.git"
    }
}

 based on above discussion I understand that I can't test this with outsystem now so i'm trying to build android application but its ending up with the error saying :

   " Error fetching cordova plugin: https://github.com/iMicknl/cordova-plugin-openalpr.git

I have tried by putting version name in URL but still its same.

Can you please help me to understand if I am missing anything also I will appreciate your help regarding possible ways to debug my code once I successfully built it 

Thanks


Hi Pankaj, did you manage to solve your issue?


I'm also trying to use openalpr. I don't get any errors during compilation, but when I try to call openALPR in my app, I get a "cannot read property 'openALPR' of undefinied". Even in the "CheckOpenALPR" action:


$parameters.isAvailable =  !!cordova.plugins.OpenALPR;


Thanks in advance!

Hi João,

I don't have my SS handy, so I don't have a sample plugin that has a similar implementation for the CheckPlugin function, but it is possible that you need to check for window.cordova as well.

And remember you always have to test on a mobile device using a native app installed after you published the version with the plugin (otherwise the application binary will not include the plugin native implementation)

Jorge Martins wrote:

Hi João,

I don't have my SS handy, so I don't have a sample plugin that has a similar implementation for the CheckPlugin function, but it is possible that you need to check for window.cordova as well.

And remember you always have to test on a mobile device using a native app installed after you published the version with the plugin (otherwise the application binary will not include the plugin native implementation)

Hi Jorge,

the "CheckAvailability" of the plugin is just a best practice to make sure that the plugin is correctly installed. It's just an action with JS node to see if the object is available:


If everything is correctly defined/installed, this should return true. But That's not my case. I've tried different cordova plugins and they worked like a charm.

Regarding Extensibility Configurations this is what I have (just like any other plugin):


The plugin is an independent module inserted in my mobile app applicaion:

And finally, yes. I'm testing in mobile devices. Both Android and iOS. I have no problems during compilation. I generate the ipa and apk files. And they are correctly installed in the devices. Everything works in the app. Except the openALPR. 


I think I'm doing everything as expected. I've used other plugins with the same method, and they worked really well. But for some reason, I'm not able to make this one work.


Any clue?


Thanks!

Hi João,

I wasn't clear...

João Carvalho wrote:

Jorge Martins wrote:

Hi João,

I don't have my SS handy, so I don't have a sample plugin that has a similar implementation for the CheckPlugin function, but it is possible that you need to check for window.cordova as well.

And remember you always have to test on a mobile device using a native app installed after you published the version with the plugin (otherwise the application binary will not include the plugin native implementation)

Hi Jorge,

the "CheckAvailability" of the plugin is just a best practice to make sure that the plugin is correctly installed. It's just an action with JS node to see if the object is available:


If everything is correctly defined/installed, this should return true. But That's not my case. I've tried different cordova plugins and they worked like a charm.

The implementation of the CheckAvailability (for each of the plugins) will be different, as you need to check whether certain attributes are defined. Some will add an attribute to cordova.plugins, others to navigator, others to other places... In this case, since the OpenALPR plugin is adding an attribute (OpenALPR) to cordova.plugins and cordova is only available when you have cordova running, you may need to also test whether the global variable cordova is defined (it's safer to check for window.cordova, as that is guaranteed to be the global scope, whereas cordova by itself could be a local variable).

So your Javascript would look like:

$parameters.isAvailable =  !!(window.cordova && cordova.plugins.OpenALPR);

I'm explaining this all from the top of my head as I don't have SS open right now, but hope I'm being clear enough. Can you try this approach? it would at least not fail on browsers.

For your woes with the plugin while running on a mobile device itself, you may need to debug if from your device connected to a desktop browser.

Hi João Carvalho,

After giving try for cordova plugin, I managed to solve this by creating .Net extension where I had used openalpr libraries.

Thanks!

pankaj - wrote:

Hi João Carvalho,

After giving try for cordova plugin, I managed to solve this by creating .Net extension where I had used openalpr libraries.

Thanks!

Hi Pankaj, 

Thank you for your answer.

We also have that option available. But we wold like to use openALPR nativelly, to avoid the need to send the image files to the server.


Regards!


Jorge Martins wrote:

Hi João,

I wasn't clear...

João Carvalho wrote:

Jorge Martins wrote:

Hi João,

I don't have my SS handy, so I don't have a sample plugin that has a similar implementation for the CheckPlugin function, but it is possible that you need to check for window.cordova as well.

And remember you always have to test on a mobile device using a native app installed after you published the version with the plugin (otherwise the application binary will not include the plugin native implementation)

Hi Jorge,

the "CheckAvailability" of the plugin is just a best practice to make sure that the plugin is correctly installed. It's just an action with JS node to see if the object is available:


If everything is correctly defined/installed, this should return true. But That's not my case. I've tried different cordova plugins and they worked like a charm.

The implementation of the CheckAvailability (for each of the plugins) will be different, as you need to check whether certain attributes are defined. Some will add an attribute to cordova.plugins, others to navigator, others to other places... In this case, since the OpenALPR plugin is adding an attribute (OpenALPR) to cordova.plugins and cordova is only available when you have cordova running, you may need to also test whether the global variable cordova is defined (it's safer to check for window.cordova, as that is guaranteed to be the global scope, whereas cordova by itself could be a local variable).

So your Javascript would look like:

$parameters.isAvailable =  !!(window.cordova && cordova.plugins.OpenALPR);

I'm explaining this all from the top of my head as I don't have SS open right now, but hope I'm being clear enough. Can you try this approach? it would at least not fail on browsers.

For your woes with the plugin while running on a mobile device itself, you may need to debug if from your device connected to a desktop browser.

Hi Jorge,


First thing first, thank you for the time you're spending trying to help me! 

I've done what you suggested step by step.


So by checking only the window.cordova, as expected,I get a valid answer from the "check" action (true).

$parameters.isAvailable =  !!(window.cordova);


If I combine both objects, I get the same "cannot read property 'openALPR' of undefinied" error... 

$parameters.isAvailable =  !!(window.cordova && window.plugins.OpenALPR);


Hello João.


Your plugin doesn't seem to be included in the app. I tried using the plugin and I got compilation errors. For the plugin to work, you need to "fork" it to a git repository of your own and remove this line from plugin.xml:

<source-file src="src/android/lib/armeabi-v7a" target-dir="libs"/>

By removing this line, the plugin should work.

Keep in mind that after this you should create a new version of the plugin and use that in Service Studio. Example:

https://github.com/YOUR_REPOSITORY/cordova-plugin-openalpr.git#2.0.2

Thanks