DEV Community

loading...
Cover image for How to Create Android & iOS Mobile App using HTML, CSS & JavaScript

How to Create Android & iOS Mobile App using HTML, CSS & JavaScript

progaurab profile image Gaurab Kumar Originally published at androidabcd.info ・4 min read

Apache Cordova is an open-source mobile development framework. It allows you to use standard web technologies such as HTML5, CSS3, and JavaScript for cross-platform development, avoiding each mobile platform native development language. Applications execute within wrappers targeted to each platform, and rely on standards-compliant API bindings to access each device’s sensors, data, and network status.”

If you want to learn how to develop Android & iOS Mobile apps using HTML, CSS, JS & Apache Cordova then enroll in my course here with 90% discount.

Apache Cordova - Build Hybrid Mobile Apps with HTML CSS & JS

In this blog post, I’ll show you how to Create your first Cordova Project for Android, iOS, Browser, and Desktop using HTML, CSS, and JavaScript.

By Cross-Platform, we mean that the application codebase can be written once using HTML5, CSS3 & JavaScript and it can be run across multiple target mobile platforms such as Android, iOS, Windows, Firefox, Ubuntu mobile.

The web development community has been continually innovating and with the recent development of frameworks such as Angular, IONIC, jQuery and React, the traditional web applications have now almost become indistinguishable from their native platform-specific peers in terms of functionality.

Apache Cordova can be extended with native plug-ins, allowing developers to add more functionalities that can be called from JavaScript, making it communicate directly between the native layer and the HTML5 page. These plugins allow access to the device’s accelerometer, camera, compass, file system, microphone, and more.

However, the use of Web-based technologies leads some Apache Cordova applications to run slower than native applications with similar functionality.

And the most important thing is: Cordova is free and open source. Here’s how to get started with Apache Cordova.

Use Apache Cordova if you are:

  • a mobile developer and want to extend an application across more than one platform, without having to re-implement it with each platform’s language and toolset.
  • a web developer and want to deploy a web app that’s packaged for distribution in various app store portals.
  • a mobile developer interested in mixing native application components with a WebView (special browser window) that can access device-level APIs, or if you want to develop a plugin interface between native and WebView components.

If you would like to watch and learn from video then you must watch on YouTube and also subscribe to the “Instill Learning” YouTube channel for a future tutorial.

Prerequisite

Before creating a new Cordova App, there are few prerequisites and you have to install this software:

*Node.js (npm comes with Node.js) [ https://nodejs.org/en/ ]
*Cordova [after installing node.js, you can install cordova through command line or terminal by using following command “npm install -g cordova“] [ https://cordova.apache.org/#getstarted ]

Step 1: Create a new Cordova App

cordova create DeviceInfo info.androidabcd.deviceinfo DeviceInfoSample

After creating the new app, move to Cordova project folder

cd DeviceInfo

Step 2: Add the Android platform

cordova platform add android@latest

Step 3: Add plugin to get device information

cordova plugin add cordova-plugin-device

By using this plugin you get the following device information:

  • device.cordova
  • device.model
  • device.platform
  • device.uuid
  • device.version
  • device.manufacturer
  • device.isVirtual
  • device.serial

Step 4: Open code in Visual Studio Code Editor

If you haven’t install visual studio code then download and install from here: https://code.visualstudio.com/

You can open the Cordova project from the command line or terminal by typing ” code . ” [code space dot], or you can directly drag & drop the project into visual studio code.

Open code in visual studio code

Step 5: Edit index.html in www folder

Step 6: Edit index.js in www folder

Step 7: Edit index.css in www folder

Step 8: Prepare the Cordova project

After editing the source code in www folder, you must prepare the code, so that it can distribute to all platforms you have added. to prepare the source code type following command in the command line or terminal:

cordova prepare

Step 9: Build Cordova Project

Once you build your Cordova project, you will notice that it will generate APK File and that you can install it manually in any Android device. Or if you want to install the app using the command line then see the next step.

cordova build android

Step 10: Run Cordova App in Android Emulator

You have to run Android Emulator before running this command.

cordova run android

How to run an Emulator

Step 11: Up and Running Cordova App in Emulator

Device Info

Discussion (2)

pic
Editor guide
Collapse
szilardszabo profile image
SS • Edited

You forget to mention that this needs a Java Runtime Environment and the Android Studio installed and properly configured on your system and that is actually the hard part. Cordova actually does not install and set these up for you automatically just start complaining if they are missing when you try to build your project which is very dumb...

Collapse
progaurab profile image
Gaurab Kumar Author

You are right. for beginners that is the important part. will try to add those point as well from next post.