Load PhoneGap plugin dynamically

147 views
Skip to first unread message

Ahmed RADJDI

unread,
Feb 22, 2012, 4:52:12 AM2/22/12
to phonegap
Hello everyone,

I work on a PhoneGap application for Android and iPhone.
I wonder if it is possible to dynamically load a plugin PhoneGap when
I run a special functionality of my application.

Best regard.

tmaus

unread,
Feb 22, 2012, 5:56:42 AM2/22/12
to phonegap
sure ...

you should be able to register your plugin within js in any possible
function.

But you have to register it nevertheless in Android and Xcode

Ahmed RADJDI

unread,
Feb 22, 2012, 8:13:25 AM2/22/12
to phonegap
This is the background of my question, I want the register in Android
and Xcode is done dynamically.

For example, in Android context, I want that my application include
different jar file for each plugin. When I need some plugin, I load
the corresponding jar file, then I register this plugin in Android and
in js. As soon as I have no need, I unload this plugin.

Aater Suleman

unread,
Feb 23, 2012, 8:11:30 AM2/23/12
to phonegap
Ahmed,

While this is possible, it will require changing the native JAVA code.
Unless you really care about the App's file size, I would compile the
plugins and only manipulate JS on the fly. I once tried the former and
its a pain for several reasons. At the least, it makes upgrading to
newer PhoneGap versions a lot harder (PhoneGap releases a new version
faster than I can upgrade:-).

Aater

Ahmed RADJDI

unread,
Feb 24, 2012, 8:14:39 AM2/24/12
to phonegap
Thank's for reply :)

Actually, I care about application's size, but not only. I also want
to be able to load different PhoneGap versions and different PhoneGap
plugins.

To use a plugin, you need to allow this plugin to be called from
Javascript, and you need to maps the plugin name to the class name
that implement the plugin. This is done by modify "res/xml/
plugins.xml" file.
So my questions are :
- Can we modify with JAVA code "res/xml/plugins.xml" file ?
- Is there are another way to allow plugin to be called from
Javascript, and to maps plugin name to class name that implement the
plugin ?

Ahmed

Aater Suleman

unread,
Feb 25, 2012, 8:49:25 AM2/25/12
to phonegap
Yes, you can modify the XML files in JAVA. I can't think of another
way to call plugins, in fact, please let me know if you find any.

Bryce Curtis

unread,
Feb 27, 2012, 11:52:52 AM2/27/12
to phon...@googlegroups.com
Dynamic loading of plugins is not supported in PhoneGap.  The native plugin code must be contained within the installed application and be listed in the plugins.xml for Android or plist file for iOS.  As for the js plugin code, you can keep it in a separate js file and only load it before calling the plugin method.

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Reply all
Reply to author
Forward
0 new messages