Menu Search Sign up

Cordova

Nodejs & NPM Download and Installation (on Windows)

https://www.e2college.com/subjects/javascript/building_tools.html 

Cordova Download and Installation (on ma<c)

1. Install Cordova

cd <my folder>

sudo npm install -g cordova

This will ensure the latest Cordova modules onto 

/usr/local/lib/node_modules/cordova (with a soft link /usr/loca/bin/cordorva)

2. Update Cordova (if you already have Cordova)

sudo npm update -g cordova

Cordova Download and Installation (on Windows)

1. Install Cordova

cd ./nodejs

npm install cordova

Do not use the -g parameter. This will ensure the latest Cordova modules will be put under your nodejs folder.

2. Update Cordova (if you already have Cordova)

npm update cordova

Do not use the -g parameter. This will ensure the latest Cordova modules will be put under your nodejs folder.

Setting JDK environment (on windows)

First, you will need JDK 1.8 or above

set JAVA_HOME=C:\<your JDK location>\java\jdk1.8.0_111

set PATH=%PATH%;%JAVA_HOME%\bin

Setting android environment (on windows)

set ANDROID_HOME=C:\<your android sdk location>\sdk

set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

Create a new Cordova project

1. On Windows, open a command line window, and navigate to the folder where nodejs is installed. (On Mac, open terminal, and navigate to the folder where you want to put your project folder)

cordova create workshop com.yourname.workshop Workshop

You will see "workshop" folder created under your nodejs folder.

3. Add cordova plugins your project need

cd ./nodejs/workshop (or your project name on mac)

cordova plugin add cordova-plugin-dialogs
cordova plugin add cordova-plugin-device
cordova plugin add cordova-plugin-console

these are the plugins we usually need:

cordova plugin add cordova-plugin-camera
cordova plugin add cordova-plugin-file
cordova plugin add cordova-plugin-file-transfer
cordova plugin add cordova-plugin-whitelist
cordova plugin add cordova-plugin-compat

2. Add ios and android as platforms

cd ./nodejs/workshop

cordova platforms add ios

cordova platforms add android

Where are all your html/css/javascript assets?

All under nodejs/<project name>/www

Build & simulate iOS app

cd <your project>

cordova build ios

cordova emulate ios

Build android apk

cd ./nodejs/workshop

cordova build android

After you run above, the output apk (for debug) will be generated at: ./nodejs/workshop/platforms/android/build/outputs/apk/android-debug.apk

Install android apk to android device for testing

cd .\adt-bundle-windows-x86-20140702\sdk\platform-tools

adb install .\nodejs\workshop\platforms\android\build\outputs\apk\android-debug.apk

Note: you need to plug in your device to your computer's USB before running above.

You also need to have your device USB-debug enabled.

You also need to uninstall any prior installation of your app on the device.

Customizing build configuration

You can customize:

.\nodejs\workshop\config.xml (for example, to add allow-navigation etc)

.\nodejs\satenglish\platforms\android\AndroidManifest.xml (for example, to add permissions requests)

You need to touch your www assets in order for Android to pick up the build configuration changes. 

Add a new Cordova plugin

cordova plugin add cordova-plugin-file-transfer

References & Tutorial

https://ccoenraets.github.io/cordova-tutorial/single-page-app.html (as a first step tutorial)

https://cordova.apache.org/docs/en/latest/  (as reference)

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file-transfer/index.html 

http://cordova.apache.org/docs/en/4.0.0/guide/cli/index.html