In the previous post I did all the groundwork in preparation for installing PhoneGap or Cordova, so now its time to install PhoneGap proper.
When browsing the many tutorials around the web on PhoneGap, a lot of them seemed to use Cordova instead of PhoneGap. Both PhoneGap and Cordova are pretty much the same thing, one site likened the relationship between the two to that of Webkit and Chrome – Cordova is Webkit and PhoneGap Chrome.
Therefore I’m going to install Cordova instead of PhoneGap. This is simply done via the Node.js package manager npm –
sudo npm install -g cordova
npm then goes away and does its stuff, downloading all the components needed for Cordova and of course Cordova itself. We can check Cordova is correctly installed by seeing what version we have –
At the time of writing, this returns 3.4.1-0.1.0.
The next step is try creating a Cordova project. Make sure you’re in the directory where you want the project folder to be created and enter –
cordova create helloworld io.cordova.helloworld HelloWorld
This creates a directory helloworld and places in it a basic Cordova app with an id of io.cordova.helloworld and project name HelloWorld.
Before doing anything else with the project, you need to be in the root of the project directory, so first of all go into the directory –
Now we need to add platforms to the project, the common ones being ios and android. This is simply done with the cordova command –
cordova platform add ios
Of course that adds the ios platform to the project – I don’t have the Android SDK installed at the moment so am just concentrating on ios.
Once a platform has been added, we can build the project for that platform, again using the cordova command –
cordova build ios
All being well you’ll see ** BUILD SUCCEEDED ** after a few seconds. What that command has actually done has created a proper Xcode project which can be loaded into Xcode – this is in the ios directory within the platforms sub-directory in the project directory.
If you load the Xcode project you can actually run the app in the iOS simulator or on a real device.
An alternative to firing up the device SDK and an emulator, a simpler way to quickly test your app is use something called Ripple.