Install Gulp
Run “npm install –v gulp” command to install the libraries for Gulp. Gulp is used to build JavaScript code and libraries, which are used by Ionic to build the project.
After successful installation, run “gulp –v” command to check the version of the installed Gulp.
Create a Demo App
After installation of all the required libraries, now we learn how to create an Application in Ionic and built for Android and iOS platform.
First, change your directory, where you want to create your project and run the “ionic start newAPP tabs”. This command creates an Ionic Application with tabs template. Ionic provides some pre-generated templates like tabs, menu, and blank.
This command downloads the template packages for tabs Application.
You can check that the following files or directories are added in myApp folder.
Now, we run this project in the Web Browser, so change your directory to myApp and run the “ionic serve” command.
Now, the screen, shown below will open in the Web Browser. This Application’s template is tab-based. In this app, we can see three tabs- Status, chat, and Account tabs, where three tabs contains content, shown below.
Status Tab
Chats Tab
Account Tab
Build Application for Android and IOS platform
So far our Application “myAPP” is just a Web Application. Now, we build and add support files for the Android and IOS platforms. First of all, press “q” to quit. Enter the “ionic platform add android” command for an Android platform. These commands add the Android support files for our Application.
You can use “ionic platform add IOS” to add the support files for IOS. I only have an Android device so, I only built and run this Application for an Android.
After installing all the required files, let’s check our “myApp” directory. You will find the “platform” folder is added into the app and this folder contains all the files to run our application on an Android device.
Build the Application
For it, we use the “ionic build android” command.
This builds a process, which will generate an “apk” file for our Application. Now, we have “apk” file, so let’s run this “apk” file and test the application in an Android device or emulator.
Now, run the “ionic emulate android” command. This command launches your Application in an Android emulator if you have SDK. Let’s check our Application Android emulator.
Our application is running on an Android emulator, which is a virtual device. Now, we try to launch this application on a real device.
First of all connect your device, using the USB cable and enable the “USB debugging” mode in your Android device.
Now, run the “ionic run android” command. The command launches this Application into your device. I am sharing my device’s screen image, which is running this Application.
One of the major advantages of ionic is that you can access your device’s screen on your Browser on a remote basis. Now, I will tell you, how we can access the device’s screen on our Browser.
First, run the “ionic run android” command. Afterward, right-click on the Browser Window and select ”inspect element” option. Afterward “inspect element” option, go to “More Tools” and click on “Remote device” option.
Now, a screen will open, where you can see your device name. If your device name is not visible, it means your device is not connected properly.
If your device is connected properly, then you can see your device’s URL and click on “inspect option”.
When you click on the “inspect” option, the screen shown below will open.
On this screen, you will get an image of the screen, which currently opens in your device.
Here, you can inspect and edit elements just like a Website and the change will be reflected.
Ionic provides live testing, which means whenever we change any code in either project file or in a Web Browser, the effect will be reflected immediately on your Browser screen and also on your mobile device.
I replaced the “Welcome to Ionic” with “Hello Pankaj” and you can see that this change is immediately reflected on my Browser and device screen also.
Structure of the project
After all installation and environment set up, now we will check out the structure of our project and get the use of each file and directory present in our project.
When you open your project, you see the files and directories, mentioned below.
Hooks
It is used for Cordova commands customization and for building the automated processes during the build process.
Node_modules
We installed all the dependency, using the “npm”. This folder contains files for Cordova, Gulp, Bower, which we installed, using “npm”.
Platform
This directory contains Android and IOS project files.
Plugins
It contains Cordova plugins wherever you installed any Cordova plugin, which is installed here.
Res
This directory contains the folder for different sizes of images and orientation for an Android and IOS.
Resource
This folder contains icons and splashes for Android and IOS.
SCSS
Ionic core is built with SCSS, so the folder contains SCSS files for Ionic.
WWW
This folder is the most important part of any Cordova project. This is the folder, where we work. All the project related HTML, CSS and JavaScript files are present in this folder.
Elavarasan RPosted Mar 13, 2020, 4:17 AM
great, nice article useful to me..
Muthu KumarPosted Mar 6, 2019, 4:29 AM
Very Nice Article. Deep Explanation is Awesome..
Shubham JainPosted Nov 22, 2017, 2:19 AM
Thanks for sharing this with us:)
Saravanan VPosted Sep 8, 2017, 9:50 AM
Neatly presented.. useful article for beginners...
Srinivasan K KPosted Nov 9, 2016, 12:04 AM
This post is a really quick start guide for everyone who wants to start an ionic app. Hats of Pankaj...
Kiran MaramPosted Nov 4, 2016, 2:51 PM
Good one , it's very useful for starters