While developing a mobile app, chances are you will eventually hit a point where you need to test things out on an actual device. Here’s a quick primer on how to get your Ionic app up and running on an android smartphone.
Note: this guide is intended for developers on OS X and it is assumed that you already have a stable/working Ionic app
Step 1: Install the Java Development Kit (JDK) if you don’t have it already
Go to Oracle’s download page and install the latest version of the JDK.
Afterward, I recommend you verify your version of Java here.
Step 2: Install the Android SDK
Download the latest (zipped) SDK package here.
Unzip the package and move the extracted folder to your desired location (I have a “Workspace” directory for things like this).
Step 2.5: Make sure Ionic can access your android development tools
If you try to build your ionic app for android now, it may give you an error saying “ANDROID_HOME” / android
are not defined… To fix this, add the freshly downloaded SDK to your environment by adding these lines to the “.bashrc” file located in your home directory (/Users/[your_name]
):
export ANDROID_HOME="</path/to/android-sdk-macosx>"
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Note: You should replace the text in angle brackets with the path to your copy of the SDK
Step 3: Install the relevant Android SDK packages
Download and install the packages specifed on this page, as well as the “SDK Platform” package for Android version 21.
Step 4: Install Apache Ant
Use homebrew to install Apache Ant with the following command:
$ brew install ant
Step 5: Build your project
Navigate to the root directory of your project:
$ cd </path/to/ionic/project>
Build it for android:
$ ionic build android
Plug in your device (making sure debugging is enabled on the device) and run your app on it by entering the following command to your OS X terminal:
$ ionic run android
Note: After you plug your device in, make sure you authorize your computer to debug the device (you should see a popup on the device)
Step 6: Profit!
That’s it! You can now debug your app on physical devices.