Install the Cordova cli tools, if you haven't already.
$ npm install -g cordova
Navigate to your desired working folder.
$ cd /path/to/coding/folder
Create a new application
$ cordova create <appProjectName> <appNameSpace> <appName>
For this example, we'll create a 'HelloWorld' application:
$ cordova create helloWorld com.example.helloworld HelloWorld
First off, navigate to the application's folder.
$ cd <appName>
Add the platforms you wish to build for. The list of supported platforms can be found here.
$ cordova platform add <platformList>
We'll be adding the Android, iOS and browser platform. Use space separation to add multiple platforms at once. The browser
platform will come in handy for in-browser testing.
Using the --save
argument will save platform list to Cordova's config.xml
file.
$ cordova platform add android ios browser --save
An extensive list of options regarding the platform
command can be found in the cordova documentation.
Cordova plugins can give you access to device hardware, OS specific functions and lots more features.
The structure of the plugin
command is the same as the one for platforms
$ cordova plugin add <plugins.value>
We'll be adding the cordova file plugin (for easy device storage access) and the camera plugin, which gives access to the device's camera to make photos and videos.
$ cordova plugin add cordova-plugin-file cordova-plugin-camera --save
Remember: using the
--save
argument writes your settings to theconfig.xml
file. Very useful to easily recreate the project on another machine.
Cordova has an excellent plugin search page set-up for your convenience. You can find it here.
Running the application is pretty straightforward. Simply use the following command.
$ cordova run <platform name>
For our example, we'll be running our test app in the browser.
$ cordova run browser
This open your default browser with your application ready for testing.