With the popularity of Ionic and the hybridization of web/phone apps, any web developer with even a passing interest in producing phone apps should prepare their environment to do so. In this post, I will walk through the steps of creating an Ionic Android app, using Linux.
Ionic can be used to build Android and iOS apps, and I recently developed an app for Android. After spending a considerable amount of time preparing my Ubuntu 14.10 machine for this purpose, I've compiled varied and scattered resources on the topic.
To develop for iOS using Ionic/Cordova, you will need to take additional steps if you are not running OS X, including using OpenSSL to generate a private key for use in signing your app. But I will focus on Android-specific development here.
The first step is to test whether java is installed, so type
If you see a java version number, you can skip ahead to the installation of the android development kit.
sudo apt-get update && sudo apt-get install default-jdk
to install OpenJDK. OpenJDK version 22.214.171.124 is functionally the same as Oracle's distribution, which Oracle engineers claim is based on the open-source version.
Alternately, you can download the JDK directly from Oracle here. Select your OS architecture and flavor (x86 or x64, Windows or OS X, etc.), accept the Oracle Binary Code License Agreement, and download the archive.
Once Java is installed, you will need to install the Android development kit as well. Navigate here and click the 'Download - Installing the SDK' link on the left sidebar. Unzip the file by using the command
tar zxvf android-sdk_r24.1.2-linux.tgz
Now, we have to make sure that we have defined the paths properly. If the archive was unzipped in your home directory, open the ~/.bashrc file and add these lines:
We are almost finished, but we need to install Apache Cordova and Ionic on Ubuntu. We can use Node Package Manager for this, and if this is not installed, open the terminal and enter:
sudo apt-get install nodejs
sudo npm install npm -g
to get the latest version.
Now, to install Cordova and Ionic, enter:
sudo npm install -g cordova
sudo npm install -g ionic
using the -g flag to install globally on your machine.
You can now create a new template and begin working. You can select a starter project at http://ionicframework.com/getting-started/, such as the side menu template, using
ionic start myApp sidemenu
to create a new project that you can use to learn Ionic. Remember to consult AngularJS documentation for information on developing for Ionic.