2016/07/04

Cordova application skeleton

Create application

Create it using the cordova command. We can get more help with: cordova create -help.

# cordova create <PATH> [ID [NAME [CONFIG]]] [options]
cordova create hello com.example.hello HelloWorld
cd hello

Next, we add platforms. Here I only add iOS and Android but there are a lot more.

cordova platform add ios --save
cordova platform add android --save

Working with git

I am not really into Cordova applications but as any other platforms I tend to have my repositories the smallest possible. There should be a command that downloads all dependencies so all users are able to have the same environment in the end. For such reason I ignore everything in platforms/ and plugins/ directories

My .gitignore:

platforms/
plugins/

The command that will make my environment ready will be:

cordova prepare

It copies files for specified platforms, or all platforms, so that the project is ready to build with each SDK.

So far our file structure will look like this:

.
├── config.xml
├── hooks/
│   └── README.md
├── platforms/
│   ├── android/
│   ├── ios/
│   └── platforms.json
├── plugins/
│   ├── android.json
│   ├── cordova-plugin-whitelist/
│   ├── fetch.json
│   └── ios.json
└── www/
    ├── css/
    ├── img/
    ├── index.html
    └── js/

Running the app

On iOS

Install ios-sim to be able to lunch the simulator. This is a one time task.

npm install -g ios-sim

Build and run

cordova build ios # build Xcode project
cordova emulate ios # launch simulator

Using Xcode

Command cordova build ios creates an Xcode project. This is quite useful specially for debbuging plugins.

 open -a Xcode platforms/ios/HelloWorld.xcodeproj/

On Android

Build and run

cordova build android
cordova run android # Run on connected device
cordova emulate android # Run on simulator

Using Android studio

Command cordova build android, creates an Android Studio project. Again, this is quite useful for debbuging plugins.

open -a "Android Studio" platforms/android/

0 comments :