Difference between revisions of "Setting up a Kindle Fire Android Development Environment"

From Techotopia
Jump to: navigation, search
(Installing the ADT Plugin for Eclipse)
Line 236: Line 236:
 
   
 
   
  
[[Image:kindle_fire_android_adt_welcome.jpg|The ADT Plugin for Eclipse Welcome Screen]]
+
[[Image:kindle_fire_android_adt_welcome.png|The ADT Plugin for Eclipse Welcome Screen]]
  
 
Figure 2-4
 
Figure 2-4

Revision as of 20:32, 1 December 2011

Before any work can begin on the development of an Android application for the Kindle Fire the first step is to configure a computer system to act as the development platform. This involves a number of steps consisting of installing the Java Development Kit (JDK), the Eclipse Integrated Development Environment (IDE) and the appropriate Android Software Development Kit (SDK). In addition to these steps, it will also be necessary to install the Eclipse Android Development Tool (ADT) Plug-in.

This chapter will cover the steps necessary to install the requisite components for Kindle Fire Development on Windows, Mac OS X and Linux based systems.


Contents


System Requirements

Kindle Fire application development may be performed on any of the following system types:

  • Windows XP (32-bit)
  • Windows Vista (32-bit or 64-bit)
  • Windows 7 (32-bit or 64-bit)
  • Mac OS X 10.5.8 or later (Intel based systems only)
  • Linux systems with version 2.7 or later of GNU C Library (glibc)

Installing the Java Development Kit (JDK)

Both the Eclipse IDE and Android SDK were developed using the Java programming language. Similarly, Android applications written for the Kindle Fire are also developed using Java. As a result, the Java Development Kit (JDK) is the first component that must be installed.

Kindle Fire development requires the installation of the Java Platform, Standard Edition Development Kit version 5 or later. Java is provided in both development (JDK) and runtime (JRE) packages. For the purposes of Kindle Fire development the JDK installation must be installed.


Windows JDK Installation

For Windows systems the JDK this may be obtained from Oracle Corporation’s website, the URL for which is as follows:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Assuming that a suitable JDK is not already installed on your system, download the latest JDK package that matches the destination computer system (Windows x86 for a 32-bit system or Windows x64 for 64-bit). Once downloaded, launch the installation executable and follow the on screen instructions to complete the installation process.

Mac OS X JDK Installation

The Java SE 6 environment or a more recent version should already be installed on the latest Mac OS X versions. To confirm the version that is installed, open a Terminal window and enter the following command:

java -version

Assuming that Java is currently installed, output similar to the following will appear in the terminal window:

java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11M3527)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

In the event that Java is not installed, issuing the “java” command in the terminal window should initiate the JDK installation process.

Details about any currently installed Java versions may also be obtained via the Java Preferences tool which may be launched from within a Finder window by navigating to Applications -> Utilities -> Java Preferences. An example Java Preference session is illustrated in Figure 2-1:


The Mac OS X Java Preferences dialog

Figure 2-1

Linux JDK Installation

Firstly, if the chosen development system is running the 64-bit version of Ubuntu then it is essential that the 32-bit library support package be installed:

sudo apt-get install ia32-libs

As with Windows based JDK installation, it is possible to install the JDK on Linux by downloading the appropriate package from the Oracle web site, the URL for which is as follows:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Packages are provided by Oracle in RPM format (for installation on Red Hat Linux based systems such as Red Hat Enterprise Linux, Fedora and CentOS) and also as a tar archive for other Linux distributions such as Ubuntu.

On Red Hat based Linux systems, download the .rpm JDK file from the Oracle web site and perform the installation using the rpm command in a terminal window. Assuming, for example, that the downloaded JDK file was named jdk-7u1-linux-x64.rpm, the commands to perform the installation would read as follows

su
rpm –ihv jdk-7u1-linux-x64.rpm

To install using the compressed tar package (tar.gz) perform the following steps:

1. Create the directory into which the JDK is to be installed (for the purposes of this example we will assume /home/demo/java).

2. Download the appropriate tar.gz package from the Oracle web site into the directory.

3. Execute the following command (where <jdk-file> is replaced by the name of the downloaded JDK file):

tar xvfz  <jdk-file>.tar.gz

4. Remove the downloaded tar.gz file.

5. Add the path to the bin directory of the JDK installation to your $PATH variable. For example, assuming that the JDK ultimately installed into /home/demo/java/jdk1.7.0_01 the following would need to be added to your $PATH environment variable:

/home/demo/java/jdk1.7.0_01/bin

This can typically be achieved by adding a command to the .bashrc in your home directory (specifics may differ depending on the particular Linux distribution in use). For example, change directory to your home directory, edit the .bashrc file contained therein and add the following line at the end of the file (modifying the path to match the location of the JDK on your system):

export PATH=/home/demo/java/jdk1.7.0_01/bin:$PATH

Having saved the change, future terminal sessions will include the JDK in the $PATH environment variable.

Installing the Eclipse IDE

With the Java Development Kit installed the next step is to download and install the Eclipse IDE. Eclipse may be download from

http://www.eclipse.org/downloads/. 

Eclipse is available in a number of different versions and configurations. For the purposes of Android based Kindle Fire development any one of the following editions may be installed (though the examples in the remainder of this book are based on the Eclipse IDE for Java Developers edition):

  • Eclipse IDE for Java Developers
  • Eclipse Classic (versions 3.5.1 and higher)
  • Eclipse IDE for Java EE Developers

Eclipse is provided in the form of a compressed archive file. Once the package for the appropriate system has been downloaded, it should be unpacked into a suitable directory. For most purposes a sub-directory of the user’s home directory is an ideal location.

On Windows, right click on the downloaded file, select Extract All… from the menu and specify a suitable destination folder before clicking on the Extract button.

On Mac OS X and Linux systems, open a terminal window, change directory to the location where Eclipse is to be installed and execute the following command:

tar xvfz /<path to package>/<package name>.tar.gz

For example, assuming a package file named eclipse-java-macosx-cocoa-x86-64.tar.gz has been downloaded to /Users/demo/Downloads, the following command would be needed to install Eclipse:

tar xvfz /Users/demo/Downloads/eclipse-java-macosx-cocoa-x86-64.tar.gz

Note that Eclipse will be installed into a sub-directory named eclipse. Assuming, therefore, that the above command was executed in /Users/demo Eclipse will be unpacked into /Users/demo/eclipse.

Launching Eclipse

Once the Eclipse IDE has been downloaded and unpacked it may be launched from the directory into which it was installed.

  • On Windows, navigate to the installation directory and double click on the eclipse executable. For easier future access, right click on the eclipse executable and select Pin to Taskbar from the resulting menu.
  • On Linux, open a terminal window, change directory to the Eclipse installation directory and execute the following command:
./eclipse
  • On Mac OS X use the Finder to navigate to the directory into which Eclipse was unpacked and double click on the eclipse executable. For easier access to the tool, simply drag the eclipse icon from the Finder window and drop it onto the dock.

Having verified that the Eclipse IDE is installed correctly, exit from the tool in preparation for installing the Android SDK.

Installing the Android SDK Starter Package

The Android SDK Starter Package contains a basic subset of the tools required to develop and compile Android based applications and may be downloaded for Windows, Mac OS X and Linux from http://developer.android.com/sdk/index.html.

In the case of Windows simply download and run the .exe installer executable to perform the Android SDK Starter Package installation. By default the installer will place the sdk in the following path:

C:\Program Files (x86)\Android\android-sdk

If you choose to specify and alternative installation location be sure to make a note of the path for future reference.

For Mac OS X download the zip file, open a terminal window, change directory to a suitable installation location and execute the following command:

unzip /<path to android sdk file>/<android sdk file>.zip

For Linux, open a terminal window, change directory to the desired location and execute the following command:

tar xvfz /<path to android sdk file>/<android sdk file>.tgz

On Mac OS X and Linux the SDK will unpack into a sub-directory of the current working directory named android-sdk-<platform> where <platform> is either macosx or linux.

In the case of Mac OS X and Linux installation, it will be necessary to add the path to tools and platform-tools directories of the SDK installation to the $PATH environment variable. On Linux this will involve once again editing the .bashrc file. Assuming that the starter package was installed into /home/demo/android-sdk-linux, the export line in the .bashrc file would now read as follows:

export PATH=/home/demo/java/jdk1.7.0_01/bin:/home/demo/android-sdk-linux/tools:
/home/demo/android-sdk-linux/platform-tools:$PATH

A number of techniques may be employed to modify the $PATH environment variable on Mac OS X. Arguably the cleanest method is to add a new file in the /etc/paths.d directory containing the paths to be added to $PATH. Assuming, once again, an installation location of /Users/demo/android-sdk-macosx, the path may configured by creating a new file named android-sdk in the /etc/paths.d directory containing the following lines:

/Users/demo/android-sdk-macosx/tools 
/Users/demo/android-sdk-macosx/platform-tools

Note that since this is a system directory it will be necessary to use the sudo command when creating the file. For example:

sudo vi /etc/paths.d/android-sdk

Installing the Android SDK

Now that the Android SDK starter package has been installed it is now possible to install the actual Android SDK. This task is performed using the Android SDK Manager tool which will have been installed as part of the Android SDK Starter Package. To invoke this tool on Windows, open the Windows start menu and navigate to Applications -> Android SDK Tools. Right click on the SDK Manager entry in this menu and select the option to Run as administrator.

On Linux and Mac OS X, on the other hand, simply open a terminal window and execute the android command.

Once loaded, the manager tool will provide a list of available Android SDK versions. By default, the manager will list the latest version of the SDK as being selected for installation. There is no problem with installing the latest SDK but we will also need to install the Android 2.3.3 (API 10) version of the SDK. Select this option from the list as illustrated in Figure 2-2:


The Android SDK Manager

Figure 2-2


Click on the install button and in the resulting dialog review and accept the license terms before proceeding. Once the installation is complete, exit the Android SDK Manager tool in preparation for installing the ADT Plugin for Eclipse.

Installing the ADT Plugin for Eclipse

The ADT Plugin for Eclipse adds a range of Android specific features to what is otherwise a general purpose Java edition of the Eclipse environment. To install this plugin, launch Eclipse and select the Help –> Install New Software… menu option. In the resulting window click on the Add… button to display the Add Repository dialog. Enter “ADT Plugin” into the Name field and the following URL into the Location field:

https://dl-ssl.google.com/android/eclipse/

Click on the OK button and wait while Eclipse connects to the Android repository. Once the information has been download a new item will be listed entitled Developer Tools as illustrated in Figure 2 3:


Installing the Android ADT Plugin in preparation for Kindle Fire Development

Figure 2-3


Select the checkbox next to the Developer Tools entry and click on the Next > button. After requirements and dependencies have been calculated by the installer a more detailed list of the packages to be installed will appear. Once again click on the Next > button to proceed. On the subsequent licensing page select the option to accept the terms of the agreements (assuming that you do, indeed, agree) and click on Finish to complete the installation. During the download and installation process you may be prompted to confirm that you wish to install unsigned content. In the event that this happens simply click on the option to proceed with the installation.

When the ADT Plugin installation is complete a dialog will appear providing the option to restart Eclipse in order to complete the installation. Click on Restart Now and wait for the tool to exit and re-launch.

Upon restarting the Welcome to Android Development dialog will appear as illustrated in Figure 2-4. This dialog provides the opportunity to specify the location of the Android SDK that is to be used for development.


The ADT Plugin for Eclipse Welcome Screen

Figure 2-4


Select the Use Existing SDKs option and then click on the Browse button to locate the Android SDKs on the system. For Linux and Mac OS X this will be either the android-sdk-linux or android-sdk-macosx directories created previously. For Windows this will either be C:\Program Files (x86)\Android\android-sdk or the alternative location specified with the Android SDK Starter Package was previously installed. Having selected the SDK directory click on Next >, decide whether or not to send usage statistic to Google and then click Finish.

At this point the Eclipse environment is ready to begin the development of Android applications for the Kindle Fire.

Summary

Prior to beginning the development of Android based application for the Kindle Fire the first step is to set up a suitable development environment. This consists of the Java Development Kit (JDK), Android SDK, Eclipse IDE and the Android ADT Plugin for Eclipse. In this chapter we have covered the steps necessary to install these packages on Windows, Mac OS X and Linux.