Search code examples
cordovacordova-plugins

Plugin not found while migrating cordova project


I am migrating an app from Cordova 2.2.0 to 3.5. I am using a custom plugin for iOS which is responsible for scanning a barcode. I have placed the code in a folder under the Cordova Library project.

I am calling the plugin using the following code:

var RedLaserPlugin = {
scanBarcode: function(successFunction, failFunction) {
  return Cordova.exec(successFunction, failFunction, "RedLaserPlugin",
                      "scanBarcode", []);
}

}

and... on loading the app,

document.addEventListener("deviceready", function () { Cordova.exec(rlp_success, rlp_failure, "RedLaserPlugin", "init", []); }, false);

in config.xml file I have added the dependency of the plugin using...

<feature name="RedLaserPlugin">
    <param name="ios-package" value="RedLaserPlugin" />

But when I run the app its not able to bind the plugin to the xcode project and giving following:

-[CDVCommandQueue executePending] [Line 159] FAILED pluginJSON = ["RedLaserPlugin1615451183","RedLaserPlugin","init",[]]

Tried multiple combinations to make it work but none of them did. Am I missing something?

EDIT: I have created a plugin.xml in folder like below:

<js-module src="www/RedLaserPlugin.js" name="RedLaserPlugin">
<clobbers target="navigator.RedLaserPlugin" />

=3.8.0" />

<!-- config file -->
<config-file target="config.xml" parent="/*">
    <feature name="RedLaserPlugin">
        <param name="ios-package" value="RedLaserPlugin" />
    </feature>
</config-file>

<header-file src="platforms/ios/Production/Classes/MainViewController.h" />
<header-file src="platforms/ios/Production/Classes/MainViewController.m" />
<header-file src="platforms/ios/Production/Classes/MainViewController.xib" />
<header-file src="platforms/ios/Production/Classes/MainViewController.m" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPlugin.h" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPlugin.m" />
<header-file src="platforms/ios/Production/Plugins/RedLaserSDK.h" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPluginFiles/RedLaserOverlayController.h" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPluginFiles/RedLaserOverlayController.m" />
<header-file src="platforms/ios/Production/Plugins/RedLaserPluginFiles/RedLaserOverlayController.xib" />

And tried to install the plugin using the cmd

cordova plugin add RedLaserPlugin.js

But its giving me the error in the terminal like:

TypeError: Cannot read property 'match' of undefined

Solution

  • I think your plugin.xml is not valid.

    Here is a sample plugin.xml template that I have created for my custom plugins:

    <?xml version="1.0" encoding="UTF-8"?>
    <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
        id="your_plugin_id"
        version="your_version">
    
        <name>plugin_name</name>
        <description>description</description>
        <license>Apache 2.0</license>
        <keywords>keyword_of_the_plugin</keywords>
    
        <!-- ios -->
        <platform name="ios">
          <source-file src="Plugin_source_file" />
    
          <framework src="required_framework" />
    
          <config-file target="config.xml" parent="/*/plugins">
              <feature name="feature_name">
                  <param name="ios-package" value="plugin_name"/>
              </feature>
          </config-file>
          <config-file target="config.xml" parent="/*">
            <access origin="*" />
          </config-file>
        </platform>
    
        <!-- android -->
        <platform name="android">
            <!-- android-specific elements -->
        </platform>
    </plugin>
    

    Check the following documentation for instance