4

I am developing a PhoneGap 3.5.0 app for iOS and Android. I want to write some functionality in native code and so I've been looking at creating a plugin.

I've followed the Plugin Development Guide and all of the code works fine; I can call native functions via the JS api the plugin exposes.

My question is how to continue development from here. Right now I just added the plugin classes manually to the project (I'm developing the plugin for iOS first, so I'm not concerned with android at this point). It looks like what I should be doing is put the plugin code in a separate repo that resembles this example and then add it to the app with the CLI tools.

I did this, and the plugin gets added to the app. However, I don't know how to continue making changes to the plugin, testing them, and also updating the plugin files in the app after they've changed in the plugin repo.

What's the intended/recommended workflow here? Is it to change the plugin files directly in the app from XCode and then copy them to the plugin repo every time?

3
  • 1
    The workflow is poor right now. The best I have come up with is to develop the plugin to completion in your project first, then pull out all of the related items and package the completed plugin. Otherwise, you can continue to remove and add the plugin each time you have a change to test. It can be very exhausting. Jul 9, 2014 at 22:37
  • @DawsonLoudon that's validating what I've found so far. I've been considering adding the plugin as a git submodule and having a hook copy the files from the platform folders to the submodule so that they're always in sync. Also, do you know why when you modify the project-level plugin files and to a cordova build it doesn't copy them to the platform?
    – 0x6A75616E
    Jul 9, 2014 at 22:43
  • 1
    Also, do you know why when you modify the project-level plugin files and to a cordova build it doesn't copy them to the platform? I am not 100% sure, but I believe the only reason for the project level retention of plugin files is for the case that you add another platform to the project. Jul 9, 2014 at 22:59

1 Answer 1

3

I've been doing it more or less in the same way. I usually start a project with cordova create myplugintest, then cordova platform add ios and include one of my other plugins to have a kickstart cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin for example. Then copy the plugin sources to the platform folder by running cordova prepare and see if all compiles correctly by running cordova build.

Then I start hacking away on the js and native code, creating my new plugin. When I'm happy, I create a new repo for the plugin, copy in an older plugin to get a starting point (mainly for the plugin.xml and the folder structure, so I don't make silly mistakes). Then copy in the files from myplugintest.

Then I throw away the myplugintest project and create a new one, this time adding the plugin from the new plugin repo. This serves two purposes: test whether or not the plugin and plugin.xml work as expected in a shiny new project. And also, this is the project I'll use to further expand the plugin when features need to be added. Once I'm happy with a change, I copy the specific change over to the plugin repo. This makes sure the plugin repo always contains working software (beta code is in the test project). It goes without saying you really need a good IDE with VCS integration to not loose track of your changes.

This may all sound a bit cucumbersome, but I personally don't have issues with this workflow.

As a sidenote - the plugin example you used is a good start, but not one with a lot of meat. It doesn't whow you how to return an error to the JS code (to trigger the errorcallback). Also, the plugin.xml has a js-modue tag inside a platform tag. While this may be valid in some cases, most of the time the js code is the same for all platforms, so it makes more sense to pull it up a level.

5
  • Great, this confirms that we're on the same page. I've been looking at your other plugins for sample code - great resource. I was thinking about making the plugin at the cordova project level a git submodule to the plugin repo.. This way I can update the sub and then cordova prepare will copy the files it needs to the platform folders. I hope to eventually automate this and maybe post the scripts somewhere.
    – 0x6A75616E
    Jul 10, 2014 at 21:08
  • Would love to see that. Have fun! Jul 11, 2014 at 5:53
  • Someone should make a script that extracts relevant sources for a plugin and builds the installable plugin folder outside the project. Oct 8, 2014 at 20:11
  • @Eddy What development environment do you use for making plugins? Would it be XCode for iOS and Android Studio for Android? Or do you just use Sublime Text?? Dec 22, 2015 at 18:39
  • @AndroidNoob Indeed those tools. And to make the plugin scaffolding I use VS Code / Sublime Text. Dec 22, 2015 at 19:29

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.