Building for native devices

So far, everything we have done in Ionic has been tested in emulators or remote services. Now that we have an app that uses real phone features, it is time we finally went all the way and built the ultimate end-product—a mobile app.

Building and deploying Ionic apps on physical devices is remarkably easy thanks to the Ionic CLI. We will demonstrate how to do so in the following section.

Android

From the root of your project folder, run the following:

ionic platform add android

This will add all the files that are necessary to deploy your app on an Android device.

Next, we have two options for the running of our app—an actual Android emulator or a physical device.

Emulator

To run the app in the emulator, first build the project by running the following:

ionic build android

Finally, start the emulator and deploy the app by running the following:

ionic run

A physical device

Running an app on a physical device is just as simple as running the app on the emulator. First, connect an Android device that can accept APK installations over USB (see Chapter 1, Setting Up Your Workspace, for instructions on setting this up). Once this is done, run the following:

ionic build android

Finally, run the following to install and run the APK on your connected device:

ionic run

Once the app is deployed, it will start automatically on your device.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.218.69