Ionic:Hybrid Mobile App Development
上QQ阅读APP看书,第一时间看更新

Setting up Native Mobile development environments

Native Mobile development environments are specific to your operating system and hence there will be separate instructions for installing on Windows/Mac/Linux. The native environment SDKs are heavy so would require fast Internet speed to download. You need to be on a good network to be able to download it.

For iOS

These days iOS Apps are built for iPhone, iPad and iWatch devices. Objective-C is the primary language used to develop iOS Native Apps. Xcode is Apple's IDE (integrated development environment), which includes a graphical user interface and many other features. iOS SDK is required along with Xcode as it provides additional tools, compilers, and frameworks to build iOS Apps for phones, tablets, and smartwear devices (iWatch).

Note

For developing or building iOS Apps, a Macintosh machine is strictly required so if you do not have a Mac, please skip this section. Mac machines should have OS X 10.9.4 or later.

In order to download the latest version of Xcode and iOS SDK (bundled) for free, please follow these steps:

  1. Go to the Apple App Store on your Mac (search for it or open from the dock).
  2. Search for Xcode software to download in the top-right corner search box.
  3. Click on the Free button to download it.

The website link for downloading Xcode is https://developer.apple.com/xcode/.

Xcode will be downloaded and installed in the Applications folder of your Mac machine.

Installing and running simulators for testing

In order to test our iOS apps, we either require a physical device or we can test it on a simulator. By default, the simulators are present in the Xcode. In order to install different iOS simulators for specific OS versions, please go to https://developer.apple.com/ios/download/.

To run the simulator, open Xcode, right click on the Xcode icon in the dock and go to Open Developer Tools | iOS Simulator. It will open an iOS device such as an iPad or iPhone, which can be changed by going to the top menu option Hardware | Device | Specific Device.

For Android

Android Apps are developed using a Java programming language so installing a Java environment is a requirement for it. Please download the latest JDK 7 (JRE would not work) from http://www.oracle.com/technetwork/java/javase/downloads/index.html. It is required to set the PATH and JAVA_HOME variable to refer to Java and javac binaries (we explain later how to do it).

Apache Ant is a Java build system used by Cordova/Ionic and Android SDK. In order to install Ant properly, download the binary from the link http://ant.apache.org/bindownload.cgi and follow these steps:

  1. Move the downloaded file to a new location/folder for Ant.
  2. Unpack the zip file where you want Ant to be installed.
  3. Set the PATH variable and ANT_HOME to this directory.

Android SDK is available in two variants, one is a standalone SDK and the other is bundled with Code Editor Eclipse or indigenous Android Studio. There are separate binaries for Windows, Linux, and Mac OS. It is recommended to download and set up the standalone SDK for developing Hybrid Apps unless you want to try out native Android development too. We will be discussing setting up the standalone Android SDK only.

Download links

The following are some downloading links:

Setting the environment variables

For Cordova command-line tools to work, or the CLI that is based upon them, you need to include the SDK's tools and platform-tools directories in your PATH.

For Windows

The following are the steps to set up Native Mobile development environments on Windows:

  1. Click on the Start menu, right-click on Computer, and then select Properties.
  2. Select Advanced system settings from the column on the left.
  3. Select the Environment Variables | PATH variable and click Edit.
  4. Append the path with a path to the platform tools and tools folder of SDK.

    For example,C:\Development\adt-bundle\sdk\platform-tools;C:\Development\adt-bundle\sdk\tools

For Linux/Mac OS

On a Mac you can use a text editor and on a Linux you can use vi editor to create/modify the ~/.bash_profile file, adding a line such as the following, depending on where the SDK installs:

$ export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools

Add the paths for Java and Ant if needed. This line in ~/.bash_profile exposes these tools in newly opened terminal windows. If your terminal window is already open in OS X, or to avoid a logout/login on Linux, run this to make them available in the current terminal window:

$ source ~/.bash_profile

Managing Android SDK and emulators

Android has a large fragmentation in the OS versions being used and has different SDK packages for various versions. In the SDK tools, there is an SDK manager that helps to manage different SDK API versions. In order to manage SDK Manager, open SDK Manager.exe in Windows, whereas on a Mac/Linux open a terminal and navigate to the /tools directory in the location where the Android SDK is installed, then execute android sdk.

In Android, to test your apps, install it on an actual physical device or create a new emulator/virtual device using the SDK tools. These next steps should be followed:

  1. Open the command prompt in Windows and terminal in Linux/Mac.
  2. Go to the location where Android SDK is installed under the tools folder.
  3. Execute the command $ android avd to open the Virtual Device/Emulator Manager.

Alternative to Android emulators – Genymotion

Android emulators are known to be slow and sloppy. If you want to debug or test your apps on emulators, use the Genymotion emulator as it is faster than the Android emulators. Apart from being fast, it has 20 mobile devices preconfigured to emulate. The Genymotion emulator uses VirtualBox, so install the latest version and then install Genymotion. The link to the Genymotion website is https://www.genymotion.com/.