To target the Android platform, some additional environment setup is required. Android apps can be created on Windows, macOS, and Linux.
Cordova is not compatible with the latest version of Java. You must install JDK8 to build Android apps with Cordova.
Once installed, open Android Studio. The IDE should detect that the Android SDK needs to be installed. In the SDK Components Setup screen, finish installing the SDK. Keep note of the Android SDK Location.
By default, the latest stable SDK Platform is installed, which includes a collection of packages required to target that version of Android.
📝 Note: To install system images and other minor SDK platform packages, you may need to ensure Show Package Details is checked at the bottom of the SDK Manager.
For future reference, the Android SDK can be managed with Android Studio in the Configure » SDK Manager menu of the Android Studio welcome screen or Tools » SDK Manager inside Android projects.
The Android SDK ships with useful command-line tools. Before they can be used, some environment variables must be set. The following instructions are for macOS and Linux. For Windows, check the documentation on setting and persisting environment variables in terminal sessions.
~/.bash_profile, or similar shell startup scripts, make the following modifications:
ANDROID_SDK_ROOTenvironment variable. This path should be the Android SDK Location used in the previous section.
$ export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
Add the Android SDK command-line directories to
PATH. Each directory corresponds to the category of command-line tool.
# 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
$ANDROID_SDK_ROOT/build-toolsmust also be added to
Android Virtual Devices (AVDs) are blueprints that the Android emulator uses to run the Android OS. The following documentation is a quick way to get the Android emulator set up. For more detailed instructions and information, see the Android documentation.
AVDs are managed with the AVD Manager. In the Android Studio welcome screen, click Configure » AVD Manager. The AVD Manager can also be opened inside Android projects in the Tools » AVD Manager menu.
Click Create Virtual Device and select a suitable device definition. If unsure, choose Pixel 2. Then, select a suitable system image. If unsure, choose Pie (API 28) with Google Play services. See Android version history for information on Android versions.
Once the AVD is created, launch the AVD into the Android emulator. Keeping the emulator running is the best way to ensure detection while developing Ionic apps for Android.
Actual Android hardware can also be used for Ionic app development. But first, the device must be set up for development. The following documentation is a quick way to set up Android devices for development. For more detailed instructions and information, see the Android documentation.
- Enable USB debugging on the device. Open Settings, navigate to Developer options, and enable USB debugging. The Developer options menu may need to be enabled first. See the Android documentation for instructions.
- Ensure the device has permission to connect to the computer. For macOS, no additional setup is required. For Windows, install the OEM USB drivers.
Verify the connection works by connecting the device to the computer with a USB cable and using the following command:
$ adb devices
The device should be listed. See the full
adb documentation for troubleshooting and detailed information.