If you are new to mobile development or you want to develop mobile applications faster and easier way, then this is the best approach. By making hybrid applications, you can compile them in any platform and after compiling you will get installable file for their respective platform. Another advantage of hybrid applications is that you have to code once for multiple platforms. So, let's dive into the hybrid applications development using phonegap/cordova.
You will need the following installations in order to start development:
- Install NodeJS from https://nodejs.org/en/download/
- Install Git from https://git-scm.com/downloads
- npm will automatically be installed with NodeJS
Install Phonegap + Cordova by opening command prompt (type cmd in Run and hit enter) and type in the following command. It will install the latest version of phonegap and cordova.
- npm install -g phonegap@latest
- npm install -g cordova@latest
- Install Phonegap Developer App for mobile from platform respective store. (You have to install this app on your mobile phone for testing purpose)
- Let's start creating your first mobile Application:
- cordova create myApp
- Goto myApp folder through command prompt
- cd myApp
- Serve your app by typing the following command in the command prompt.
- phonegap serve
192.168.1.2:3000, on which the phonegap is listening
- Now Open the app (Phonegap Developer App) that you installed on your mobile phone and type in the IP Address and port through which phonegap is listening and tap the Connect button.
Now you will be looking into the application you built on your mobile.
That's it! You just created your first mobile application. Now we will be looking into the files one by one and their functionality they perform.
You will see the folders (hooks,platforms,plugins,res,www) and files (config.xml,package.json) in the app root folder i.e. myApp.
For now, just ignore the folders other than 'www' and files other than 'config.xml'. These are files and folders that you will be looking at first.
Let's dive into 'www' folder:
In this folder, you will be looking at folders (css,js,img) and file 'index.html'. This (index.html) is your main file that you will be working on and their corresponding css,js,images in their respective folders.
The file present at the app root folder i.e. config.xml contains different configuration options like App Name, App Description, App version, App author, plugins included in the app, app platforms etc. For more information about the file, just look at Apache Cordova docs.
Now the question is how to make device oriented files like .apk for android, .ipa for iOS etc? Well, there are two methods for that.
- Build through command line (which requires their respective compilers)
- Generate apk,ipa etc files from phonegap build.
There are two main things that I want to mention: