1 Install Cordova CLI
The Cordova command-line tool is distributed as an npm package in a ready-to-use format. You do not need to compile it from your source code
To install the Cordova command-line tool, you have to follow these steps:
- Download and install Node.js. On installation you should be able to invoke node and npm on your command line.
- Now we have to install the cordova module using npm utility of Node.js. The cordova module will automatically be downloaded.
- With the command-line tool:
- on OS X and Linux:
Copy
$ sudo npm install -g cordova
- on Windows:
Copy
C:\>npm install -g cordova
- on OS X and Linux:
- To verify if Cordova has installed correct, write cordova in command-line tool and it should print help text.
2 Create the app
To create the app, go to your workspace directory and write on your command tool:
$ cordova create folderName companyDomain AppName
A practical application example would be:
$ cordova create dbcalculator deister.informix.dbcalculator IBMCalculator
This command generates the required directory structure for your cordova app.
- myapp/
- config.xml
- hooks/
- merges/
- android/
- windows/
- ios/
- www/
- platforms/
- android/
- windows/
- ios/
- plugins/
- cordova-plugin-camera/
3 Add platforms
To add any platform that you want to target, first of all, you have to run all commands in the progect's directory, or any subdirectories.
So, to add new platform we write in command-line tool:
$ cordova platform add nameofplatform
Where nameofplatform can be: android, ios, windows, ubuntu, blackberry10...
4 Install pre-requisites for building
To be able to build and run apps, you need to install SDKs for each platform you wish to target.
To check if you meet the requirements, you can write in command-line tool:
$ cordova requirements
This command, check if you satisfy requirements only for building platform that you want to target. If you don't have any error, you can build your app!
5 Build the app
To build your app, only you have to run the following command. This command is to build the project for all platforms
$ cordova build
Otherwise if you just want to build specific platform, you should run:
$ cordova build nameofplatform
Where the nameofplatform is the same as the Add platforms
section.
6 Test the app
Once you build the app, for example in android platform, you can find the apk in: folderName/platforms/android/build/outputs/apk/android-debug.apk
if you added the browser platform you can execute this command to see the application in the browser.
$ cordova run browser