Plugin not found, or is not a CDVPlugin. Check your plugin mapping in config.xml

Aras picture Aras · Feb 15, 2014 · Viewed 25.5k times · Source

I have declared my plugin file for iOS inside plugin.xml like so:

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

  <header-file src="src/ios/CDVOP.h" />
  <source-file src="src/ios/CDVOP.m" />

In the plugin JavaScript file I have this function which I later call from the JavaScript app

showCatPictures: function(interval) {
  exec(null, null, 'CDVOP', 'showCatPictures', [interval]);   
},

I am running the app that uses this plugin from xcode to see the debug output. I get this when I call the showCatPictures function:

OP Cordova Tests[1122:60b] ERROR: Plugin 'CDVOP' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-02-14 16:23:45.233 OP Cordova Tests[1122:60b] -[CDVCommandQueue executePending] [Line 127] FAILED pluginJSON = [
  "INVALID",
  "CDVOP",
  "showCatPictures",
  [
    30
  ]
]

I suspect this may have something to do with all the stuff I imported, so here is CDVOP.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDV.h>
#import <Cordova/CDVViewController.h>

//OP SDK
#import "OpenpeerSDK/HOPStack.h"
#import "OpenpeerSDK/HOPLogger.h"
#import "OpenpeerSDK/HOPMediaEngine.h"
#import "OpenpeerSDK/HOPCache.h"
#import "OpenpeerSDK/HOPAccount.h"
#import "OpenpeerSDK/HOPIdentity.h"

@interface CDVOP : CDVPlugin <UIWebViewDelegate> {
    NSString* callbackId;
    UIImageView* peerImageView;
    UIImageView* selfImageView;
}

@property (nonatomic, copy) NSString* callbackId;
@property (retain, nonatomic) UIImageView *peerImageView;
@property (retain, nonatomic) UIImageView *selfImageView;

- (void) authorizeApp:(CDVInvokedUrlCommand*)command;
- (void) configureApp:(CDVInvokedUrlCommand*)command;
- (void) getAccountState:(CDVInvokedUrlCommand*)command;
- (void) startLoginProcess:(CDVInvokedUrlCommand*)command;
- (void) showCatPictures:(CDVInvokedUrlCommand*)command

@end

and this is the top part of CDVOP.m:

#import "CDVOP.h"

@implementation CDVOP

@synthesize webView, selfImageView, peerImageView, callbackId;

-(CDVPlugin*) initWithWebView:(UIWebView*)theWebView
{
    self = (CDVOP*)[super initWithWebView:theWebView];
    NSLog(@">>> initializing with cordova webView <<<"); // actually this does not get called!
    return self;
}

// stress test UIImageViews using a series of cat pictures
- (void)showCatPictures:(CDVInvokedUrlCommand*)command
{   
    //initialize and configure the image view
    CGRect selfRect = CGRectMake(0, 0, 100.0, 200.0);
    self.selfImageView = [[UIImageView alloc] initWithFrame:selfRect];
    [self.webView.superview addSubview:self.selfImageView];

    // load pictures and start animating
    NSLog(@"displaying cat pictures");
    selfImageView.animationImages = [NSArray arrayWithObjects:
      [UIImage imageNamed:@"1.JPG"], [UIImage imageNamed:@"2.JPG"], [UIImage imageNamed:@"3.JPG"],
      [UIImage imageNamed:@"4.JPG"], [UIImage imageNamed:@"5.JPG"], [UIImage imageNamed:@"6.JPG"],
      [UIImage imageNamed:@"7.JPG"], [UIImage imageNamed:@"8.JPG"], nil];

    selfImageView.animationDuration = 0.3;
    [selfImageView startAnimating];
}

Any ideas why the plugin does not seem to be properly initialized and why cant I call its methods with exec?

Answer

Aras picture Aras · Feb 16, 2014

Here is an small unimportant detail I forgot to mention in the question. This is what the www/config.xml in the sample app using the plugin looked like. Can you spot the issue?

<widget id="org.sample.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>My Cordova Test</name>
    <description>
        A series of tests demonstrating the use of my cordova plugin
    </description>
    <author email="" href="">
        That would be me
    </author>
    <content src="index.html" />
    <access origin="*" />
</widget>

Notice the space in the application name <name>My Cordova Test</name>. This seems to work at first, but it puts spaces in the folder name that will later host your plugin. That is enough to interfere with the plugin installation process. This is what I did to fix the issue:

  • changed the name of the test app to MyCordovaTest
  • cordova platform remove ios
  • cordova plugin remove org.myplugin.cordova
  • cordova platform add ios
  • cordova plugin add ../my-plugin
  • cordova build ios

Now the plugin is installed properly and is initialized as expected. Many thanks to the nice folks in #phonegap IRC room who helped me debug this problem. I hope this helps someone.