Today at PhoneGap Day version 3.0 was released. This is a pretty significant release in terms of the underlying architecture and there are some things you should know.
First – let’s start with a few links you should read:
Second – there is a new command line tool you will use (or can use I should say, the cordova-cli still works), phonegap. The installation for this is rather trivial if you’ve got npm already installed:
sudo npm install -g phonegap
This may seem obvious, but phonegap cli is different from cordova cli. Be sure to use the built-in help and sniff around a bit so you see how it does things compared to cordova. This shouldn’t take more than a few minutes and you will probably trip up a few times. Thank you, muscle memory.
One of the coolest aspects of the new command line though is that it fully supports PhoneGap Build. What this means is that you can use the command line to build via your terminal with and without the SDKs. Or heck, even if you do have the SDKs and want to use PhoneGap Build, the new PhoneGap cli makes this trivial.
Another useful feature is that if you run phongap as is, you get a quick checklist of what SDKs/platforms you can use locally:
OK – READ THIS CAREFULLY
This is the number one thing that I think will trip people up. One of the new things in PhoneGap 3 is a revised plugin architecture. All of the previously core features, like the Camera for example, are plugin based.
When I realized this, my first question was whether a virgin project would include support for the core stuff and expect developers to strip things out (if they cared) or if you would need to implicitly add in support for what you want to use.
Turns out – you need to add in what you want to use. What does that mean practically? As an example, if you try to use navigator.camera.getPicture it will fail with the “out of the box” project made at the command line.
To fix this you can add in the plugin of course. This takes two seconds and can be done via the CLI. This may not be very clear via the docs. First, the command line docs do talk about the core features as plugins and give you the commands to use… but for cordova, not phonegap.
So as an example, this is the cordova way to add the plugin: cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git
And this is how you would do it via phonegap: phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git
The net result is that when you start your PhoneGap project, you will want to think ahead of time about the features you need – the previously “just there” features – and add them via the CLI. (As an FYI, it is super easy to remove these plugins too. So if you added the Camera and realize you don’t need it, you can quickly remove it.)
For a full list of these plugins, see below. I copied this directly from the link above, so it may change, so please see the link for the most up-to-date version.
Basic device information:
Network and battery status:
Accelerometer, compass, and geolocation:
Camera, media capture, and media playback:
Access files on device or network:
Notifications via dialog box or vibration:
p.s. I’ve not no idea what the debug console is. Going to research.