简体   繁体   中英

PhoneGap - exec() call to unknown plugin

I've been trying to use Phonegap Image Resizer plugin in my project, but I couldn't make it work.

The error log returns: D/PluginManager(13992): exec() call to unknown plugin: com.webXells.imageResizer

I've moved all the necessary things into my project folder. Here's the structure:

/assets
 /js
  cordova.js
  imageresize.js
 /www
  index.html
  upload.html
/src
 /com
  /webXells
   /ImageResizer
     ImageResizerPlugin.java

I've also include the plugin into config.xml in /res/xml :

<feature name="imageResizer">
  <param name="android-package" value="com.webXells.imageResizer.ImageResizePlugin"/>
</feature> 

In upload.html I've included the plugin like so:

<script type="text/javascript" charset="utf-8" src="../js/imageresize.js"></script>

And this is how I call a method to use it:

    function onPhotoDataSuccess(imageData) {
      window.imageResizer.resizeImage(
        function(data) { 
          var smallImage = document.getElementById('smallImage');
          smallImage.style.display = 'block';
          image.src = "data:image/jpeg;base64," + imageData; 
          //image.src = imageData; 
        },
        function (error) {
          console.log("Error : \r\n" + error);
        },
        imageData,
        0.5,
        0.5,
        {
          imageDataType:ImageResizer.IMAGE_DATA_TYPE_BASE64,
          resizeType:ImageResizer.RESIZE_TYPE_FACTOR,
          format:'jpg'
        }
      );
}

So, inside the imageresize.js the method that I wanna use looks like this. You can refer to the above link if necessary:

ImageResizer.prototype.resizeImage = function(success, fail, imageData, width,
        height, options) {
    if (!options) {
        options = {}
    }
    var params = {
        data : imageData,
        width : width,
        height : height,
        format : options.format,
        imageDataType : options.imageType,
        resizeType : options.resizeType,
        quality : options.quality ? options.quality : 70
    };

    return cordova.exec(success,fail,"com.webXells.imageResizer","resizeImage",[params]);
}

In the above code, I noticed that com.webXells.imageResizer didn't called as reported in the logcat. What confuses me is the fact that I have included it in config.xml and moved the java file in src folder. Why can't it be called even though I have done all the stuff that is necessary?

Some researches I made, says to declare the plugin in plugin.xml , but I don't have the file inside res/xml . So, I put it in config.xml instead. Other recommend to use <gap:plugin name="com.phonegap.plugins.example" /> but Eclipse found error to this.

So, how do I get around this? Have I called the method in HTML correctly? Or there is something I missed?

As of cordova 3.5.0-0.2.6, the res/xml/config.xml is overwritten upon build. try adding the feature tag to the config.xml in your app root dir. worked for me.

Are you adding the the plugin using CLI like "corodova add plugin xyz" or manually adding the plugin to eclipse project ? If u are adding the plugin manually then when run "cordova run android/ios" the config.xml in res folder is overridden so the above error. I found an hack/solution for this as i was using revmob plugin which is not CLI based we have to add the plugin maually.In ur project/plugins folder there is android.json u have to add feature tag in that so config.xml get rewrited while running the app through CLI

HERE IS THE SAMPLE

"config_munge": {
 "res/xml/config.xml": {
        "/*": {
            "<feature name=\"Device\"><param name=\"android-package\" value=\"org.apache.cordova.device.Device\" /></feature>": 1,
            "<feature name=\"RevMobPlugin\"><param name=\"android-package\" value=\"com.revmob.cordova.RevMobPlugin\" /></feature>": 0
        }
    }
},

JUST TRY

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