1

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?

4
  • What version of Cordova are you using?
    – MBillau
    Sep 19, 2013 at 18:37
  • 1
    Also, in your directory tree it looks like the file is: /src/com/webXells/ImageResizer/ImageResizerPlugin.java but the value that you have in config.xml is with a lower case 'i': value="com.webXells.imageResizer.ImageResizePlugin - copy/paste error?
    – MBillau
    Sep 19, 2013 at 18:39
  • Okay I got it now. Thanks. It was a typing error. Now another problem appears. Do you have any idea what file:///android_asset/js/cordova.js: Line 982 : processMessage failed: Stack: Error: Error calling method on NPObject. means? I've googled around haven't returned any results yet.
    – emen
    Sep 20, 2013 at 1:13
  • 1
    Hey, you're welcome. I'm not sure what that error message means; I have encountered NPObject errors before and it's always hard to google. I think NPObject is something to do with a native browser event, before when I have seen this it was doing things like sending a keyDown event or something. Maybe you should create a new question and include the offending code.
    – MBillau
    Sep 23, 2013 at 13:22

2 Answers 2

1

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.

1
  • For me changing <feature name="Plugin"> to <gap:feature name="Plugin"> did the trick
    – Demiurg
    Oct 24, 2014 at 15:36
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.