Sunday, June 10, 2012

How To Setup Netbeans For Developing Google Android Apps ( Optional )


Netbeans is deemed more desirable for building web applications. To begin building a web application in Netbeans, it requires one step. This step involves downloading the Netbeans IDE 7.2 application. Its competitor’s process involves 6 steps in comparison.

Netbeans contains a JSP debugger and remote debugger, a Java Enterprise Edition verifier, a choice of JSP, JSF or Struts frameworks, a deployment description editor, a HTTP monitor, multiple database connections, XML editor and validation, debug and monitor SQL commands, and no manual creation or modification of deployment descriptors required.

To develop Google Android Applications for Netbeans, the user must implement the following steps.

1) Install the Integrated Development Environment (IDE). Download the application from the website and install it.

2) Install the Android plug in for Netbeans. The plug in is named nbandroid.

Within the Netbeans Update Center, the user will find the Netbeans plug in.
First go to the Menu bar, find the Tools menu. Within the tools menu, the user will find a list of Netbeans plug ins. Select the Netbeans plug in the user desires. In this particular case, select the Android Plug in. Within the Settings options, select Add. When prompted, enter this URL: http://kenai.com/downloads/nbandroid/updates.xml
The user can begin the installation process, when this step is completed. Once the Android plug is installed, then the user should add the Android Platform to Netbeans.
Within the Menu option, select the Tools option. Once this is completed, enter Java Platforms. Then select the Add Platform button. The Google Android Platform should be in this selection. The next window will prompt the user to enter a new platform name. Enter the user name. Follow the instructions until the process is complete.

Setup Eclipse and the Android SDK (Optional)

Installing The Android SDK

First you will need to download the Android SDK pack .zip archive, once downloaded find a suitable installation location on your machine and extract the zipped files.
Please note: This installation location will be referred to as $SDK_ROOT from now on through this tutorial
Alternatively you can add /tools to your root path which will prevent the need to specify the full path to the tools directory along with enabling you to run Android Debug Bridge (adb) along with other command line tools.
To add /tools:

Linux

  1. Edit the ~/.bash_profile or ~/.bashrc files looking for a line that sets the PATH variable.
  2. Add the full path location to your $SDK_ROOT/tools location for the PATH variable.
  3. If no PATH line exists you can add the line by typing the following:
  4. export PATH=${PATH}:<path to your $SDK_ROOT/tools>

Mac OS X

  1. In the home directory locate the .bash_profile and locating the PATH variable add the location to your $SDK_ROOT/tools folder.

Windows XP / Vista

  1. Right click on the My Computer icon and select the properties tab.
  2. Select the Advanced tab and click the Environment Variables button.
  3. In the new dialog box dowble-click on Path (located under System Variables) and type in the full path location to the tools directory.
The Android SDK also requires a suitable development environment to work in, here’s the installation guides for each of the supported environments.

Android Eclipse Plugin (ADT)

If you choose to use the Eclipse IDE as your Android development environment you will have the opportunity to install and run a plug-in called Android Development Tools. ADT comes with a variety of powerful tools and extensions that will make creating, running and debugging your Android applications much easier and faster.
In order to download and install ADT you will first need to configure an Eclipse remote update, this can achieved via the following steps:
  1. Start Eclipse, then select Help > Software Updates > Find and Install….
  2. In the dialog that appears, select Search for new features to install and press Next.
  3. Press New Remote Site.
  4. In the resulting dialog box, enter a name for the remote site (e.g. Android Plugin) and enter this as its URL: https://dl-ssl.google.com/android/eclipse/.
  5. Press OK.
  6. You should now see the new site added to the search list (and checked).
  7. Press Finish.
  8. In the subsequent Search Results dialog box, select the checkbox for Android Plugin > Eclipse Integration > Android Development Tools and press Next.
  9. Read the license agreement and then select Accept terms of the license agreement, if appropriate.
  10. Press Next.
  11. Press Finish.
  12. The ADT plugin is not signed; you can accept the installation anyway by pressing Install All.
  13. Restart Eclipse.
  14. After restart, update your Eclipse preferences to point to the SDK root directory ($SDK_ROOT):
    Select Window > Preferences… to open the Preferences panel. (Mac OS X: Eclipse > Preferences)
    Select Android from the left panel.
    For the SDK Location in the main panel, press Browse... and find the SDK root directory.
  15. Press Apply, then OK

Updating the ADT Plugin

To update the ADT plugin to the latest version, follow these steps:
  1. Select Help > Software Updates > Find and Install….
  2. Select Search for updates of the currently installed features and press Finish.
  3. If any update for ADT is available, select and install.
Alternatively:
  1. Select Help > Software Updates > Manage Configuration.
  2. Navigate down the tree and select Android Development Tools <version>
  3. Select Scan for Updates under Available Tasks.

How-To Use Eclipse To Develop Android Applications

In order to begin development on your Android applications you will first need to create a new Android project and then configure a launch configuration. Once completed you will have the capability to write, run and debug your Android creations.
The following sections below will provide you with the necessary instructions to get you up and running with Android provided you have installed the ADT plugin (as previously mentioned) in your Eclipse environment.

Creating A New Android Project

The Android Development Tools plugins kindly provides a Wizard for setting up new Projects which will allow us to create new Eclipse projects relatively quickly for either new or existing code.
Select File > New > Project
  1. Select Android > Android Project, and press Next
  2. Select the contents for the project:
  • Select Create new project in workspace to start a project for new code. Enter the project name, the base package name, the name of a single Activity class to create as a stub .java file, and a name to use for your application.
  • Select Create project from existing source to start a project from existing code. Use this option if you want to build and run any of the sample applications included with the SDK. The sample applications are located in the samples/ directory in the SDK. Browse to the directory containing the existing source code and click OK. If the directory contains a valid Android manifest file, the ADT plugin fills in the package, activity, and application names for you.
Press Finish.
Once completed the ADT plugin will go ahead and create the following files and folders as appropriate for the type of project selected:
  • src/ A folder that includes your stub .java Activity file.
  • res/ A folder for your resources.
  • AndroidManifest.xml The manifest for your project.

Creating A Launch Configuration For Eclipse

In order to be able to run and debug your own Eclipse applications you must first create a launch configuration. Simply, a launch config is used to specify which project to launch, which activity to start and the specific emulation options to use.
To create a launch configuration for the application, please see the following steps:
1. Select Run > Open Run Dialog… or Run > Open Debug Dialog… as appropriate.
2. In the project type list on the left, right-click Android Application and select New.
3. Enter a name for your configuration.
4. On the Android tab, browse for the project and Activity to start.
5. On the Emulator tab, set the desired screen and network properties, as well as any other emulator startup options.
6. You can set additional options on the Common tab as desired.
7. Press Apply to save the launch configuration, or press Run or Debug (as appropriate).

Running and Debugging an Eclipse Application

Once both steps 1 and 2 have been completed and your project and launch configs are up and running you will now be able to run or debug your application.
From the Eclipse main menu, select Run > Run or Run > Debug as appropriate. This command will run or debug the most recently selected application.
To set or change the active launch configuration, use the Run configuration manager, which you can access through Run > Open Run Dialog… or Run > Open Debug Dialog….
Running or debugging the application will trigger the following actions:
  • Starts the emulator, if it is not already running.
  • Compile the project, if there have been changes since the last build, and installs the application on the emulator.
  • Run starts the application.
  • Debug starts the application in “Wait for debugger” mode, then opens the Debug perspective and attaches the Eclipse Java debugger to the application.

Developing Android Applications with Other IDEs and Tools

Although it is recommended you use Eclipse with the Android plugin to develop your applications, the SDK also provides tools which will enable you to develop with other IDE’s including intelliJ (alternatively you could just use Eclipse without the plugin).

Creating an Android Project

Bundled with the Android SDK is a program called activityCreatory. activityCreator will generate a number of ‘stub’ files for your chosen project alongside a build file. This can be used to either create an Android project for new code or from existing code.
For Linux and Mac users the Android SDK provides a Python script called activityCreator.py, with Windows users receiving a btach script called activityCreator.bat. The program is used in the same way regardless of operating system.
In order to run activityCreator and create an Android project, follow these steps:
  1. In the command line, change to the tools/ directory of the SDK and create a new directory for your project files. If you are creating a project from existing code, change to the root folder of your application instead.
  2. Run activityCreator. In the command, you must specify a fully-qualified class name as an argument. If you are creating a project for new code, the class represents the name of a stub class that the script will create. If you are creating a project from existing code, you must specify the name of one Activity class in the package. Command options for the script include:
–out <folder> which sets the output directory. By default, the output directory is the current directory. If you created a new directory for your project files, use this option to point to it.
–ide intellij, which generates IntelliJ IDEA project files in the newly created project
Here’s an example:
/android_linux_sdk/tools$ ./activityCreator.py –out myproject your.package.name.ActivityName
package: your.package.name
out_dir: myproject
activity_name: ActivityName
~/android_linux_sdk/tools$
The activityCreator script generates the following files and directories (but will not overwrite existing ones):
  • AndroidManifest.xml The application manifest file, synced to the specified Activity class for the project.
  • build.xml An Ant file that you can use to build/package the application.
  • src/your/package/name/ActivityName.java The Activity class you specified on input.
  • your_activity.iml, your_activity.ipr, your_activity.iws [only with the -ide intelliJ flag] intelliJ project files.
  • res/ A directory to hold resources.
  • src/ The source directory.
  • bin/ The output directory for the build script.
Once complete you will now be able to move your folder wherever you choose for development but you’ll need to bear in mind then you will need to use the adb program in the tools folder in order to send the files to the emulator.

How-To Build An Android Application

Here’s how to use the Ant build.xml file generated by activityCreator to build your application.
  1. If you don’t have it, you can obtain Ant from the Apache Ant home page. Install it and make sure it is on your executable path.
  2. Before calling Ant, you need to declare the JAVA_HOME environment variable to specify the path to where the JDK is installed.Note: When installing JDK on Windows, the default is to install in the “Program Files” directory. This location will cause ant to fail, because of the space. To fix the problem, you can specify the JAVA_HOME variable like this: set JAVA_HOME=c:\Prora~1\Java\. The easiest solution, however, is to install JDK in a non-space directory, for example: c:\java\jdk1.6.0_02.
  3. If you have not done so already, follow the instructions for Creating a New Project above to set up the project.
  4. You can now run the Ant build file by simply typing ant in the same folder as the build.xml file for your project. Each time you change a source file or resource, you should run ant again and it will package up the latest version of the application for you to deploy.

How-To Run An Android Application

In order to run a compiled application you will first need to upload the .apk file to the /data/app/ directory in the emulator using the adb tool:
  1. Start the emulator (run $SDK_HOME/tools/emulator from the command line)
  2. On the emulator, navigate to the home screen (it is best not to have that application running when you reinstall it on the emulator; press the Home key to navigate away from that application).
  3. Run adb install myproject/bin/<appname>.apk to upload the executable. So, for example, to install the Lunar Lander sample, navigate in the command line to $SDK_ROOT/sample/LunarLander and type ../../tools/adb install bin/LunarLander.apk
  4. In the emulator, open the list of available applications, and scroll down to select and start your application.
Please Note: When installing an activity for the first time you may need to restart the emulator engine in order for the activity to show up in the application launcher or before any other application can call. This is usually down to the fact that the package manager normally only examines manifests completely on emulator start-up.

How-To Attach a Debugger to Your Application

The following section details how to display debug information directly onto the screen (for example CPU usage). It also shows you how to hook up your IDE to debug running applications on the emulator.
The Eclipse plugin automatically attaches a debugger but you can configure other IDE’s to wait on a debugging port by doing the following:
Start the Dalvik Debug Monitor Server (DDMS) tool , which acts as a port forwarding service between your IDE and the emulator.
  1. Set optional debugging configurations on your emulator, such as blocking application startup for an activity until a debugger is attached. Note that many of these debugging options can be used without DDMS, such as displaying CPU usage or screen refresh rate on the emulator.
  2. Configure your IDE to attach to port 8700 for debugging. We’ve included information higher up on how to set up Eclipse to debug your project.

How-To Configure Your IDE To Attach To The Debugging Port

DDMS will automatically assign a specific debugging port for every virtual machine that it detects on the emulator. You must either attach your IDE to that port, or use a default port 8700 to connect to whatever application is currently selected on the list of discovered virtual machines.
Ideally your IDE will attach to the application running on the emulator, showing its threads and allowing you to suspend them, inspect them, or set breakpoints. If you choose to “Wait for debugger” in the Development settings panel, this will cause the application to run when Eclipse connects therefore you will need to set any breakpoints you want before connecting. If you change the application being debugged or the “Wait for debugger” then the system will kill the selected currently running application.
This can be handy if your application is in a bad state, you can simply go to the settings and toggle the checkbox to kill it.

Debugging Android

Google Android has a fairly extensive set of tools to help you debug your programs:
  • DDMS – A graphical program that supports port forwarding (so you can set up breakpoints in your code in your IDE), screen captures on the emulator, thread and stack information, and many other features. You can also run logcat to retrieve your Log messages. See the linked topic for more information.
  • logcat – Dumps a log of system messages. The messages include a stack trace when the emulator throws an error, as well as Log messages. To run logcat, see the linked topic. …
    I/MemoryDealer( 763): MemoryDealer (this=0x54bda0): Creating 2621440 bytes heap at 0x438db000
    I/Logger( 1858): getView() requesting item number 0
    I/Logger( 1858): getView() requesting item number 1
    I/Logger( 1858): getView() requesting item number 2
    D/ActivityManager( 763): Stopping: HistoryRecord{409dbb20 com.google.android.home.AllApps}
  • Android Log- A logging class to print out messages to a log file on the emulator. You can read messages in real time if you run logcat on DDMS (covered next). Add a few logging method calls to your code.
  • To use the Log class, you just call Log.v() (verbose), Log.d() (debug), Log.i() (information), Log.w() (warning) or Log.e (error) depending on the importance you wish to assign the log message.
    Log.i(“MyActivity”, “MyClass.getView() — Requesting item number ” + position) You can use logcat to read these messages
  • Traceview – Android can save a log of method calls and times to a logging file that you can view in a graphical reader called Traceview. See the linked topic for more information.
  • Eclipse plugin – The Eclipse Android plugin incorporates a number of these tools (ADB, DDMS, logcat output, and other functionality). See the linked topic for more information.
  • Debug and Test Device Settings – Android exposes several settings that expose useful information such as CPU usage and frame rate.

Debug and Test Settings on the Device

Android enables you to set a number of options that will make it far easier to test and debug your applications.
To get to the development settings page on the emulator simply go to Dev Tools > Development Settings. This will in turn open up the development settings page with the following options (among others):
  • Debug app Selects the application that will be debugged. You do not need to set this to attach a debugger, but setting this value has two effects:
It will prevent Android from throwing an error if you pause on a breakpoint for a long time while debugging.
It will enable you to select the Wait for Debugger option to pause application startup until your debugger attaches (described next).
  • Wait for debugger Blocks the selected application from loading until a debugger attaches. This way you can set a breakpoint in onCreate(), which is important to debug the startup process of an Activity. When you change this option, any currently running instances of the selected application will be killed. In order to check this box, you must have selected a debug application as described in the previous option. You can do the same thing by adding waitForDebugger() to your code.
  • Immediately destroy activities Tells the system to destroy an activity as soon as it is stopped (as if Android had to reclaim memory). This is very useful for testing the onFreeze(Bundle) / onCreate(android.os.Bundle) code path, which would otherwise be difficult to force. Choosing this option will probably reveal a number of problems in your application due to not saving state.
  • Show screen updates Flashes a momentary pink rectangle on any screen sections that are being redrawn. This is very useful for discovering unnecessary screen drawing.
  • Show CPU usage Displays CPU meters at the top of the screen, showing how much the CPU is being used. The top red bar shows overall CPU usage, and the green bar underneath it shows the CPU time spent in compositing the screen. Note: You cannot turn this feature off once it is on, without restarting the emulator.
  • Show screen FPS Displays the current frame rate. Mostly useful for games to see the overall frame rate they are achieving. Note: You cannot turn this feature off once it is on without restarting the emulator.
  • Show background Displays a background pattern when no activity screens are visible. This typically does not happen, but can happen during debugging.

Setup Eclipse and the Android SDK


Android applications, like most mobile phone applications, are developed in a host-target development environment. In other words, you develop your application on a host computer (where resources are abundant), and download it to a target mobile phone for testing and ultimate use. At the time this book is being written, there are no Android phones available, so we will be running, debugging, and testing using the Android emulator that comes with the Android tool set.

To write your own Android mobile phone applications, you'll first need to collect the required tools and set up an appropriate development environment on your PC or Mac. In this chapter we'll collect the tools you need, download them and install them on your computer, and write a sample application that will let you get the feel of writing and running Android applications on an emulator. Linux, Windows, and Macintosh are all supported development environments, and we'll show you how to install the latest set of tools on each. Then we'll show you any configuration you need to do after the tools are installed (setting PATH environment variables and the like), again for each of the three operating systems. And finally we'll write a short little "Hello, Android" application that demonstrates what needs to be done to get a generic application running.
The Android SDK supports several different development environments. For this book we will focus on using Eclipse, because it is the best integrated with the SDK, and, hey, it's free. No matter which operating system you are using, you will need essentially the same set of tools:

  • The Eclipse Integrated Development Environment


  • Sun's Java Development Kit (JDK)


  • The Android Software Developer's Kit (SDK)


  • A special Eclipse plug in: the Android Developer Tool (ADT)

Since you're probably going to develop on only one of these operating systems, skip to the appropriate section that pertains to your selected operating system.

Creating an Android Development Environment
The Android Software Development Kit supports Windows (XP and Vista), Linux (Ubuntu Dapper Drake), and Mac OS X (10.4.8 or later) as host development environments. Installation of the SDK is substantially the same for any of the operating systems, and most of this description applies equally to all of them. Where the procedure differs, we will clearly tell you what to do for each environment.

1. Install Eclipse: The Android SDK requires Eclipse version 3.2 or 3.3 (also known as Europa) or later. If you do not have that version of Eclipse installed yet, you will need to go to http://www.eclipse.org/downloads to get it, and you might as well get version 3.3 since that package includes the required plugins mentioned in the next step. You want the version of the Eclipse IDE labeled "Eclipse IDE for Java Developers," and obviously you want the version for your operating system. Eclipse will ask you to select a mirror site, and will then start the download.
Windows (XP or Vista)
The Eclipse download comes as a big ZIP file that you install by extracting the files to your favorite directory. For this book, we'll assume that you extracted to C:/eclipse. Eclipse is now installed, but it will not show up in your Start menu of applications. You may want to create a Windows shortcut for C:/eclipse/eclipse.exe and place it on your desktop, in your Start menu, or someplace else where you can easily find it.

Linux and Mac OS X


The Eclipse download comes as a big tarball (.gz file) that you install by extracting the files to your favorite directory. For this book, we'll assume that you extracted to /usr/lib/eclipse.

2. Check for Required Plugins: You can skip this step if you just downloaded a current version of Eclipse as we recommended. If you are using a pre-installed version of Eclipse that was already on your PC, you need to make sure you have the Java Development Tool (JDT) and Web Standard Tools (WST) plug-ins installed. You can easily check to see whether they are installed by starting Eclipse and selecting menu options "WIndows -> Preferences..." The list of preferences should include one for "Java" and one for "Web and XML." If they aren't on the list, the easiest thing to do is reinstall Eclipse, as described in the previous step. Installing "Eclipse IDE for Java Developers" will automatically get the needed plugins.

3. Install JDK: The Android SDK requires JDK version 5 or version 6. If you already have one of those installed, skip to the next step. In particular, Mac OS X comes with the JDK version 5 already installed, and many Linux distributions include a JDK. If the JDK is not installed, go to http://java.sun.com/javase/downloads and you'll see a list of Java products to download. The one you want is JDK 6 Update n for your operating system, where n is 6 at the time this is written.

Windows (XP and Vista)
Select the distribution for "Windows Offline Installation, Multi-language."
Read, review, and accept Sun's license for the JDK. (The license has become very permissive, but if you have a problem with it, alternative free JDKs exist.)
Once the download is complete, a dialog box will ask you whether you want to run the downloaded executable. When you select "Run," the Windows Installer will start up and lead you through a dialog to install the JDK on your PC.

Linux
Select the distribution for "Linux self-extracting file."
Read, review, and accept Sun's license for the JDK. (The license has become very permissive, but if you have a problem with it, alternative free JDKs exist.)
You will need to download the self-extracting binary to the place you want to install the JDK on your filesystem. If that place is a system wide directory (such as /usr/local), you will need root access. After the file is downloaded, make it executable (chmod +x jdk-6version-linux-i586.bin) , and execute it. It will self-extract to create a tree of directories.

Mac OS X
Mac OS X comes with JDK Version 5 already loaded.

4. Install Android SDK: This is where you'd start if you already have the right versions of Eclipse and the JDK loaded. The Android SDK is distributed through Google's code site, http://code.google.com/android/download.html. You will need to read, review and accept the terms of the license to proceed. When you get to the list of downloads, you will see a table of distributions. Select the one for your operating system (XP and Vista use the same distribution). The package (file) names include the release number. For example, as this is written, the latest version of the SDK is 1.0_r1, so the file you would download for Windows is named android-sdk-windows-1.0_r1.zip.
The file you download is another archive file, as with Eclipse: a ZIP file on Windows, a tar-zipped file for Linux and MacOS X. Do the same thing as for Eclipse: extract the archive file to a directory where you want to install Android, and make a note of the directory name (you'll need it in Step 7). The extraction will create a directory tree containing a bunch of sub-directories, including one called tools.

5. Update Environment Variables: To make it easier to launch the Android tools, add the tools directory to your path.
Under Windows XP, click on Start, then right-click on My Computer. In the pop-up menu, click on Properties. In the resulting System Properties dialog box, select the Advanced tab. Near the bottom of the Advanced tab is a button, "Environment Variables," that takes you to an Environment Variables dialog. User environment variables are listed in the top half of the box, System environment variables in the bottom half. Scroll down the list of System environment variables until you find "Path," select it, and click the "Edit" button. Now you will be in an Edit System Variable dialog that allows you to change the environment variable "Path." Add the full path of the tools directory to the end of the existing Path variable and click "OK." You should now see the new version of the variable in the displayed list. Click "OK" and then "OK" again to exit the dialog boxes.
On Windows Vista, click on the Microsoft "flag" in the lower left of the desktop, then right-click on Computer. At the top of the resulting display, just below the menu bar, click on "System Properties." In the column on the left of the resulting box, click on "Advanced system settings." Vista will warn you with a dialog box that says "Windows needs your permission to continue";- click "Continue." Near the bottom of the "System Properties" is a button labeled "Environment Variables" that takes you to an Environment Variables dialog. User environment variables are listed in the top half of the box, System environment variables in the bottom half. Scroll down the list of System environment variables until you find "Path," select it, and click the "Edit" button. Now you will be in an Edit System Variable dialog that allows you to change the environment variable "Path". Add the full path of the tools directory to the end of the existing Path variable, and click "OK." You should now see the new version of the variable in the displayed list. Click "OK" and then "OK" again to exit the dialog boxes.
On Linux, the PATH environment variable can be defined in your ~/.bashrc ~/.bash_profile file. If you have either of those files, use a text editor such as gedit, vi, or Emacs to open the file and look for a line that exports the PATH variable. If you find such a line, edit it to add the full path of the tools directory to the path. If there is no such line, you can add a line like this:
export PATH=${PATH}:your_sdk_dir/tools
where you put the full path in place of
your_sdk_dir.

On MacOS X, look for a file named .bash_profile in your home directory (note the initial dot in the filename). If there is one, use an editor to open the file and look for a line that exports the PATH variable. If you find such a line, edit it to add the full path of the tools directory to the path. If there is no such line, you can add a line like this:
export PATH=${PATH}:your_sdk_dir/tools
where you put the full path in place of
your_sdk_dir


6. Install the Android Plugin (ADT): Throughout this book, we will make use of the Android Development Tool plugin that Google supplies for use in building Android applications. The plugin is installed in much the same way as any other Eclipse plugin:
Start Eclipse, if it's not already running.
From the menu bar, select "Help -> Software Updates -> Find and Install..."

  • In the Install/Update dialog, select "Search for new features to install" and click on "Next."


  • In the Install dialog, click on "New Remote Site." A "New Update Site" dialog pops up. Enter a name for the plugin ("Android Plugin" will do), and the URL for updates: https://dl-ssl.google.com/android/eclipse. Click "OK."


  • The new site should now appear in the list of sites on the Install dialog. Click "Finish."


  • In the Search Results dialog, select the checkbox for "Android Plugin -> Developer Tools" and click "Next."


  • The license agreement for the plugin appears. Read it, and if you agree, select "Accept terms of the license agreement" and click "Next." Click "Finish."


  • You will get a warning that the plugin is not signed. Choose to install it anyway by clicking "Install All."


  • Restart Eclipse.


  • After Eclipse restarts, you need to tell it where the SDK is located. From the menu bar, select "Window -> Preferences." In the Preferences dialog, select "Android" in the left hand column.


  • Use the "Browse" button to navigate to the place you installed the Android SDK, and click on "Apply," then on "OK."

Congratulations--you have installed a complete Android development environment without spending a penny. As you'll see in this and subsequent chapters, the environment includes a very sophisticated set of tools to make Android programming easier, including:
An Integrated Development Environment based on Eclipse, arguably the premier IDE for Java development. Eclipse itself brings many valuable development features. Google and OHA have taken advantage of Eclipse's extensibility to provide features customized for Android, including debugging capabilities that are tuned to the needs of mobile application developers like you.
A Java development environment and Dalvik virtual machine that build on Sun's JDK foundation to provide a very sophisticated programming environment for your applications.
A complete mobile phone emulator that allows you to test your applications without having to download them to a target mobile phone. The emulator includes features for testing your application under different mobile phone communication conditions (fading, dropped connections, etc.).
Test tools, such as TraceView, which allow you to tune your application to take best advantage of the limited resources available on a mobile phone.

System Requirements


In order to first use the Android SDK code and tools for development you will of course need a suitable environment develop from.
Currently the following operating systems are supported:
  • Windows XP or Vista
  • Mac OS X 10.4.8 or later (x86 only)
  • Linux (tested on Linux Ubuntu Dapper Drake)
You will also need to install a suitable development environment such as:

Application Framework


Developers have full access to the same framework APIs used by the core applications. The application architecture is designed to simplify the reuse of components; any application can publish its capabilities and any other application may then make use of those capabilities (subject to security constraints enforced by the framework). This same mechanism allows components to be replaced by the user.
Underlying all applications is a set of services and systems, including:
  • A rich and extensible set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser
  • Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data
  • A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files
  • A Notification Manager that enables all applications to display custom alerts in the status bar
  • An Activity Manager that manages the life cycle of applications and provides a common navigation back-stack

Libraries


Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. Some of the core libraries are listed below:
  • System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices
  • Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG
  • Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications
  • LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view
  • SGL - the underlying 2D graphics engine
  • 3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer
  • FreeType - bitmap and vector font rendering
  • SQLite - a powerful and lightweight relational database engine available to all applications

Android Runtime


The Android runtime environment consists of a set of core libraries and virtual machine. The core libraries provide most of the functionality available in the core libraries of the Java programming language.
On conventional computing devices software runs directly on the operating system kernel but an Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a mobile device can run multiple instances of it in an efficient manner. Dalvik is not your typical JVM though it’s very similar. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool.
The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.