
Building a dummy app
After successfully setting up the environment correctly, you must be excited to build your first app. In this section of the chapter, we will use the commands to learn how to create a sample Ionic-based Hybrid App and build it to run on an actual device or emulator:
- We will create the initial project using the Ionic
start
command and name our projectMyFirstApp
. The output will be as illustrated in the following screenshot: - After the successful creation of your project with the default Ionic template, go to your project folder using the command
$ cd MyFirstApp
.Now, as we are in an Ionic
project
folder, we can run Ionic project-specific CLI commands. Any platform can be added to the project to build the specific app:$ ionic platform add android
We will add an Android platform as it will work on all machines, such as Windows, Linux, or Mac. Ionic will download Android-specific default resources such as icons and splash screens, and also add some important plugins by default. A customized keyboard plugin is bundled with the Ionic app.
- In order to test the app and view it in your browser, use the Ionic
serve
command:$ ionic serve
This will open the Ionic app in your default browser.
The latest Chrome version provides a way to emulate various mobile device screen sizes. Open Developer Tools (F12), select Console from the top-right corner, and select Emulation. You can alternatively select the mobile icon from the top-left corner of the window. Please see the following screenshot:
- Now, we can build the Android App and run it on an actual device or emulator:
$ ionic run android
This will fire up the emulator if there is no connected device, then start the build process. It will generate the
.apk
file and then deploy it to the emulator or the connected device that is available.This would be a Eureka moment, seeing your first actual app on the device and playing with it. In the next section we discuss some of the common issues you may have faced during the process and provide solutions for them.