How to Get Started With Ionic and Android

This guide covers how to run and debug Ionic apps on Android emulators and devices using Capacitor or Cordova.

  1. The first thing we have to do is install Android Studio https://developer.android.com/studio
  2. After that we need to install the Android SDK through Android Studio
  3. In order to configure the command line tools we need to edit the shell scripts

In ~/.bashrc~/.bash_profile, or similar shell startup scripts, make the following modifications:

Set the ANDROID_SDK_ROOT environment variable. This path should be the Android SDK Location used in the previous section. To find the SDK Location in Android Studio, click File > Project Structure. Select SDK Location in the left pane. The path is shown under Android SDK location.

$ export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk

$ # avdmanager, sdkmanager
$ export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
$ # adb, logcat
$ export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
$ # emulator
$ export PATH=$PATH:$ANDROID_SDK_ROOT/emulator

After that, we need to setup the project in Ionic

1. Perform an Ionic Build

$ ionic build

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

//For Capacitor
$ ionic capacitor add android

//For Cordova
$ ionic cordova prepare android

2. Running the Application

//Running With Capacitor
$ ionic capacitor copy android

$ ionic capacitor open android

//Live Reload
ionic capacitor run android -l --external

//Running With Cordova
ionic cordova run android -l