Framework v4 BETA

Android Development

This guide covers how to deploy Ionic apps to Android simulators and devices using Capacitor or Cordova.

To deploy apps to an Android device and debug them, developer mode must be enabled and allow for USB debugging turned on. Check out these instructions to do this on a device.

Project Setup

Before apps can be deployed to Android simulators and devices, the native project must be configured.

  1. Generate the native project, if it does not already exist.

    For Capacitor, run the following:

     $ ionic capacitor add android

    For Cordova, run the following:

     $ ionic cordova prepare android
  2. Set the Package ID.

    For Capacitor, open the capacitor.config.json file and modify the appId property.

    For Cordova, open the config.xml file and modify the id attribute of the root element, <widget>. See the Cordova documentation for more information.

Running with Capacitor

Capacitor uses Android Studio to build and run apps to simulators and devices.

  1. Develop the Ionic app and sync it to the native project.

    With each meaningful change, Ionic apps must be built into web assets before the change can appear on Android simulators and devices. The web assets then must be copied into the native project. Luckily, this process is made easy with a single Ionic CLI command.

     $ ionic capacitor copy android
  2. In Android Studio, select a target simulator or device and click the run button.

Running with Cordova

The Ionic CLI can build, copy, and deploy Ionic apps to Android simulators and devices with a single command. It can also spin up a development server, like the one used in ionic serve, to provide live-reload functionality.

Run the following to start a long-running CLI process that boots up a live-reload server:

$ ionic cordova run android -l

Now, when changes are made to the app's source files, web assets are rebuilt and the changes are reflected on the simulator or device without having to deploy again.

Using Chrome DevTools to debug

Chrome has devtools support for Android simulators and devices. Go to chrome://inspect in Chrome while the simulator is running or a device is connected to the computer and select the app that needs to be debugged.

Viewing Native Logs

Native logs can be found in Android Studio in the Console.