home
cordova cheat sheet
Mobile apps with HTML, CSS & JS
print

Cordova : 7.0.0 - Date : July 2017

NPM commands

Uses node to install the cordova program on your computer globally.

npm install -g cordova

Init project

Uses cordova to create your project in a folder called demo with the namespace ca.edumedia.m.griffis

cordova create demo com.sii.fr.mydemo Demo

Add platform to your project

cordova platform add android
cordova platform add ios

Add plugin

cordova plugin add cordova-plugin-device

Build application

cordova build android
cordova build ios

Start application with emulator

cordova emulate android --target=myAdvName

Run application

You can run application on added platform

cordova run android
cordova run ios
cordova run browser

Android commands

  • List availables targets
android list targets
  • List availables virtual devices
android list avds
  • Create virtual devices
android create avd -n bob -t android-19

ADB commands

  • List connected physical device
adb devices
  • Install specific apk
adb install demo.apk
  • Reinstall specific apk
adb install -r demo.apk
  • Remove specific package
adb uninstall name-of-app-package
  • List installed packages
adb shell pm list packages

Emulator commands

Launch android emulator with specific avd target

emulator -avd bob

Config.xml

Standard operation on config.xml


Change version

Change version parameter of ** widget** tag. With android target, you must also update android-versionCode.

Change application name

Simply change name tag's value.

Change package name

Simply change android-packageName parameter value.

Entry point

The entry-point is define by src parameter in the content tag

Whitelist

Whitelist plugin is often require. You must install it from the plugin add command (cordova-plugin-whitelist).

This plugin allow or reject specific URL.

<!-- access to google secured domain -->
<access origin="https://www.google.com" />
<!-- access to google map domain -->
<access origin="http://maps.google.com" />
<!-- access to all google sub-domain -->
<access origin="http://*.google.com" />
<!-- access allow from all -->
<access origin="*" />

Allow application to call specific intent

<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="tel:*"/>
<allow-intent href="sms:*"/>
<allow-intent href="mailto:*"/>
<allow-intent href="geo:*"/>

Generate iOS Resources

You can auto-generate spash and icon multiple size for iOS platform. Install ios-sim :

sudo npm install -g ionic
npm install -g ios-sim

Create a folder named resources with icon.png and spash.png with good aspect ratio.

Start conversion with optionnal proxy :

sudo PROXY=http://proxy.rennes.sii.fr:3128 ionic resources —f

Generated signed android application

Generate your keystore with keytool

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

Put keystore in android-signing folder at root of your cordova project.

In the generated android platform folder of your cordova project, create a release-signing.properties.

storeFile=../../android-signing/<myKeyFile>.keystore
storeType=jks
keyAlias=<aliasKey>

Next the build.gradle must take this file to sign your application with this command :

cordova build android --release

Next find your generated package to ~/platforms/android/build/outputs/apk

Add proxy to android gradle

create gradle.properties in the generated android platform folder :

systemProp.http.proxyHost=proxy.dns.fr
systemProp.http.proxyPort=3128
systemProp.https.proxyHost=proxy.dns.fr
systemProp.https.proxyPort=3128