Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova/PhoneGap Plugin Development Workflow for Android

I am developing a set of Cordova plugins. The initial implementation will be Android only, so for now I am interested in being able to use ADT in Eclipse for plugin development. I've read over the documentation and have been able to get the first plugin completed, but the workflow is a bit of a pain. I couldn't find any docs or tools in Cordova that specifically support plugin development workflow. I wonder if I am making it harder than it needs to be? Here is what I am doing.

The plugin is set up according to the cordova plugin spec. I started by setting up the directory structure and editing the files in Sublime, so I have something like:

  • $PLUGIN_ROOT
    • src
      • android
        • Plugin.java
    • www
      • plugin.js
    • plugin.xml

I set all of that up with boilerplate and an initial implementation. Then to start testing, I created a cordova project, added the android platform, added my plugin and built:

cordova create testProject
cd testProject
cordova platform add android
cordova plugin add $PLUGIN_ROOT
cordova build
cordova run

After doing all that, I import testProject/platforms/android into ADT and start editing Plugin.java and plugin.js, as well as assets/www to add a test harness.

Now, after getting everything working the way I want it to, I have to manually copy all of the changed files (plus any files I've added) back into the appropriate place under $PLUGIN_ROOT. I also want to preserve my test harness, probably in $PLUGIN_ROOT/test. This isn't too bad the first time, but after several iterations it's all getting a little unwieldy. It also seems very error-prone to do it manually, but I can't really use a merge tool to do it for me, because the directory structure is different. I could write a script, but then I'll be adding more maintenance overhead. That being said, I'm currently planning on writing scripts to do this for each of the plugins that I am going to write.

Is there a better way? I'd really like to hear how the cordova plugin developers manage this. Thanks.

like image 735
ajh158 Avatar asked Nov 15 '13 20:11

ajh158


1 Answers

You need an automated build tool like grunt that monitors your plugin folder (e.g. $PLUGIN_ROOT) and runs the appropriate cordova commands whenever a file belonging to the plugin changes.

like image 118
Vlad Stirbu Avatar answered Sep 19 '22 09:09

Vlad Stirbu