Are you ready to take up the mobile challenge? Is your computer switched on, mouse and keyboard plugged in, and screen illuminating your desk? Then let’s not wait a minute more!
In this first chapter, we are going to do the following:
Download and install the necessary tools to develop applications using Android
Set up a development environment
Connect and prepare an Android device for development
What differentiates mankind from animals is the use of tools. Android developers, this authentic species you are about to belong to, are no different!
To develop applications on Android, we can use any of the following three platforms:
Windows 7, Vista, Mac OS X, and Linux systems are supported in both 32 and 64-bit versions, but Windows XP in 32-bit mode only. Only Mac OS X computers of version 10.5.8 or later and based on Intel architectures are supported (not PowerPC processors). Ubuntu is supported only from version 8.04 (Hardy Heron).
Right, this is a good start but unless you are able to read and write binary language like English, having an OS is not enough. We also need software dedicated to Android development:
Android, and more specifically Android NDK compilation system is heavily based on Linux. So we also need to set up some utilities by default, and we need to install one environment that supports them: Cygwin (until NDK R7). This topic is covered in detail later in the chapter. Finally, a good old command-line Shell to manipulate all these utilities is essential: we will use Bash (the default on Cygwin, Ubuntu, and Mac OS X).
Now that we know what tools are necessary to work with Android, let’s start with the installation and setup process.
To work with the Android NDK, we need to set up a Cygwin Linux-like environment for Windows:
Tip
Since NDK R7, Cygwin installation is not required anymore (steps 1 to 9). The Android NDK provides additional native Windows binaries (for example, ndk-build.cmd).
Download setup.exe and execute it.
Select Install from Internet.
Follow the wizard screens.
Select a download site from where Cygwin packages are going to be downloaded. Consider using a server in your country:

When proposed, include Devel/make and Shells/bash packages:

Follow the installation wizard until the end. This may take some time depending on your Internet connection.
After installation, launch Cygwin. Your profile files get created on first launch.
Enter the following command to check if Cygwin works:
$ make –version
To run Eclipse and allow compilation of Android Java code to bytecode, a Java Development Kit is required. On Windows, the obvious choice is the Oracle Sun JDK:
Go to the Oracle website and download the latest Java Development Kit: http://www.oracle.com/technetwork/java/javase/downloads/index.html.
Launch the downloaded program and follow the installation wizard. At the end of the installation, a browser is opened asking for JDK registration. This step is absolutely not compulsory and can be ignored.
To make sure the newly installed JDK is used, let’s define its location in environment variables. Open the Windows Control panel and go to the System panel (or right-click on Computer item in the Windows Start menu and select Properties). Then go to Advanced system settings. The System Properties window appears. Finally, select Advanced tab and click on the Environment Variables button.
In the Environment Variables window, inside the System variables list, insert the
JAVA_HOMEvariable with JDK installation directory as value and validate. Then editPATH(orPath) and insert the%JAVA_HOME%\bindirectory before any other directory and separate it with a semicolon. Validate and close the window.Open a command-line window and key in
java –versionto check the installation. The result should be similar to the following screenshot. Check carefully to make sure that the version number corresponds to the version of the newly installed JDK:$ java –version
To compile projects from the command line, the Android SDK supports Ant—a Java-based build automation utility. Let’s install it:
Go to http://ant.apache.org/bindownload.cgi and download Ant binaries, packed within a ZIP archive.
Unzip Ant in the directory of your choice (for example
,C:\Ant).Go back to the Environment Variables window, as in step 12, and create the
ANT_HOMEvariable with theAntdirectory as the value. Append the%ANT_HOME%\bindirectory toPATH:
From a classic Windows terminal, check the Ant version to make sure it is properly working:

We have prepared Windows with the necessary underlying utilities to host Android development tools: Cygwin and Java Development Kit.
Cygwin is an open source software collection that allows the Windows platform to emulate a Unix-like environment. It aims at natively integrating software based on POSIX standard (such as Unix, Linux, and so on) into Windows. It can be considered as an intermediate layer between applications originated from Unix/Linux (but natively recompiled on Windows) and the Windows OS itself.
We have also deployed a Java Development Kit in version 1.6 and checked if it is properly working from the command line. Because Android SDK uses generics, the JDK in version 1.5 is the least required when developing with Android. JDK is simple to install on Windows but it is important to make sure a previous installation, such as JRE (Java Runtime Environment, which aims at executing applications but not developing them) is not interfering. This is why we have defined JAVA_HOME and PATH environment variables to ensure proper JDK is used.
Finally, we have installed Ant utility that we are going to use in the next chapter to build projects manually. Ant is not required for Android development but is a very good solution to set up a continuous integration chain.
Tip
Where is Java’s home?
Defining the JAVA_HOME environment variable is not required. However, JAVA_HOME is a popular convention among Java applications, Ant being one of them. It first looks for the java command in JAVA_HOME (if defined) before looking in PATH. If you install an up-to-date JDK in another location later on, do not forget to update JAVA_HOME.
Open your Web browser and go to http://developer.android.com/sdk. This web page lists all available SDKs, one for each platform.
Download Android SDK for Windows, packaged as an Exe installer.
Then, go to http://developer.android.com/sdk/ndk and download the Android NDK (not SDK!) for Windows, packaged as a ZIP archive this time.
Execute Android SDK installer. Select an appropriate installation location (for example,
C:\Android\android-sdk), knowing that Android SDK and NDK together can take more than 3 GB of disk space (currently!) with all official API versions installed. As a precaution, avoid leaving any space in the target installation path.Follow the installation wizard until the end. Check the Start SDK Manager:

The Android SDK and AVD Manager is launched. The Package installation window appears automatically.
Check the Accept All option and click on Install to start the installation of Android components:

After a few minutes, all packages get downloaded and a message asking to restart ADB service (the Android Debug Bridge) appears. Validate by clicking on Yes.
Now, unzip Android NDK archive into its final location (for example,
C:\Android\android-ndk). Again, avoid leaving any space in the installation path (or some problems could be encountered with Make).To easily access Android utilities from the command line, let’s define the environment variables:
Open the Environment Variables system window, as we did in the previous part. Inside the System variables list, insert the
ANDROID_SDKandANDROID_NDKvariables with the corresponding directories as values.Append
%ANDROID_SDK%\tools,%ANDROID_SDK%\platform-toolsand%ANDROID_NDK%, all separated by a semicolon, to yourPATH.All the Windows environment variables should be imported automatically by Cygwin when launched. Let’s verify this by opening a Cygwin terminal and checking whether NDK is available:
$ ndk-build –-version
Now, check the Ant version to make sure it is properly working on Cygwin:
$ ant -version
The first time Cygwin should emit a surprising warning: paths are in MS-DOS style and not POSIX. Indeed, Cygwin paths are emulated and should look similar to
/cygdrive/<Drive letter>/<Path to your directory with forward slashes>. For example, if Ant is installed inc:\ant, then the path should be indicated as/cygdrive/c/ant.Let’s fix this. Go to your Cygwin directory. There, you should find a directory named
home/<your user name>containing a.bash_profile. Open it in edition.At the end of the script, translate the Windows environment variables into Cygwin variables with the
cygpathutility.PATHdoes not need to be translated as this essential variable is processed automatically by Cygwin. Make sure to use the prime character (`) (to execute a command inside another), which has a different meaning than the apostrophe (‘) (to define a variable) with Bash. An example.bash_profileis provided with this book:export ANT_HOME=`cygpath –u "$ANT_HOME"` export JAVA_HOME=`cygpath –u "$JAVA_HOME"` export ANDROID_SDK=`cygpath –u "$ANDROID_SDK"` export ANDROID_NDK=`cygpath –u "$ANDROID_NDK"`
Reopen a Cygwin window and check the Ant version again. No warning is issued this time:
$ ant -version
We have downloaded and deployed both Android SDK and NDK and made them available through command line using environment variables.
We have also launched the Android SDK and AVD manager, which aims at managing SDK components installation, updates, and emulation features. This way, new SDK API releases as well as third-party components (for example, Samsung Galaxy Tablet emulator, and so on) are made available to your development environment without having to reinstall the Android SDK.
If you have trouble connecting at step 7, then you may be located behind a proxy. In this case, Android SDK and AVD manager provide a Settings section where you can specify your proxy settings.
At step 16, we have converted the Windows paths defined inside the environment variables into Cygwin paths. This path form, which may look odd at first, is used by Cygwin to emulate Windows paths as if they were Unix paths. Cygdrive is similar to a mount or media directory on Unix and contains every Windows drive as a plugged file system.
Tip
Cygwin paths
The rule to remember while using paths with Cygwin is that they must contain forward slashes only and the drive letter is replaced by /cygdrive/[Drive Letter]. But beware, file names in Windows and Cygwin are case-sensitive, contrary to real Unix systems.
Like any Unix system, Cygwin has a root directory named slash (/). But since there is no real root directory in Windows, Cygwin emulates it in its own installation directory. In a Cygwin command line, enter the following command to see its content:
$ ls /

These files are the ones located in your Cygwin directory (except /proc, which is an in-memory directory). This explains why we updated .bash_profile in the home directory itself, which is located inside the Cygwin directory.
Utilities packaged with Cygwin usually expect Cygwin-style paths, although Windows-style paths work most of the time. Thus, although we could have avoided the conversion in .bash_profile (at the price of a warning), the natural way to work with Cygwin and avoid future troubles is to use Cygwin paths. However, Windows utilities generally do not support Cygwin paths (for example, java.exe), in which case, an inverse path conversion is required when calling them. To perform conversion, cygpath utility provides the following options:
-u: To convert Windows paths to Unix paths
-w: To convert Unix paths to Windows paths
-p: To convert a list of paths (separated by ; on Windows and : on Unix)
Still at step 17, you may have some difficulties when editing .bash_profile: some weird square characters may appear and the entire text is on one very long line! This is because it is encoded using Unix encoding. So use a Unix compatible file editor (such as Eclipse, PSPad, or Notepad++) when editing Cygwin files. If you already got into trouble, you can use either your editor End-Of-Line conversion feature (Notepad++ and PSPad provide one) or apply command-line dos2unix utility (provided with Cygwin) on the incriminated file.
Tip
Char return on Cygwin
Unix files use a simple line-feed character (better known as \n) to indicate an end of line whereas Windows uses a carriage return (CR or \r) plus a line feed. MacOS, on the other hand, uses a carriage return only. Windows newline markers can cause lots of trouble in Cygwin Shell scripts, which should be kept in Unix format.
Apple computers and Mac OS X have a reputation for being simple and easy to use. And honestly, this adage is rather true when it comes to Android development. Indeed, Mac OS X is based on Unix, well adapted to run the NDK toolchain, and a recent JDK is already installed by default. Mac OS X comes with almost anything we need with the exception of Developer Tools, which need to be installed separately. These Developer Tools include XCode IDE, many Mac development utilities, and also some Unix utilities, such as Make and Ant.
All developer tools are included in XCode installation package (version 4, at the time this book was written). There exist four solutions to get this package, and they are as follows:
If you have Mac OS X installation media, open it and look for the XCode installation package
XCode is also provided on the AppStore for free (but this has changed recently and may change in the future too)
XCode can also be downloaded from the Apple website with a paying program subscription at the address http://developer.apple.com/xcode/
Older version 3, compatible with Android development tools, is available for free as a disc image from the same page with a free Apple Developer account
Using the most appropriate solution for your case, let’s install XCode:
Find your XCode installation package and run it. Select the UNIX Development option when the customization screen appears. Finish installation. We are done!
To develop with Android NDK, we need the Make build tool for native code. Open a terminal prompt and ensure Make correctly works:
$ make --version
To run Eclipse and allow compilation of Android Java code to bytecode, Java Development Kit is required. Let’s check if the default Mac OS X JDK works fine:
$ java –version
To compile projects from the command line, the Android SDK supports Ant,a Java-based build automation utility. Still in a terminal, ensure Ant is correctly installed:
$ ant –version
We have prepared our Mac OS X to host Android development tools. And as usual with Apple, that was rather easy!
We have checked if Java Development Kit in version 1.6 is properly working from the command line. Because Android SDK uses generics, a JDK in version 1.5 is the least required for Android development.
We have installed Developer Tools, which include Make—to run the NDK compiler—and Ant—that we are going to use in the next chapter to build projects manually. Ant is not required for Android development but is a very good solution to set up a continuous integration chain.
Open your web browser and go to http://developer.android.com/sdk. This web page lists all available SDKs, one for each platform.
Download Android SDK for Mac OS X, which is packaged as a ZIP archive.
Then, go to http://developer.android.com/sdk/ndk and download the Android NDK (not SDK!) for Mac OS X, packaged as a Tar/BZ2 archive this time.
Uncompress the downloaded archives separately into the directory of your choice (for example,
/Developer/AndroidSDKand/Developer/AndroidNDK).Let’s declare these two directories as environment variables. From now on, we will refer to these directories as $ANDROID_SDK and $ANDROID_NDK throughout this book. Assuming you use the default Bash command-line shell, create or edit your .profile file (be careful, this is a hidden file!) in your home directory and add the following variables:
export ANDROID_SDK="<path to your Android SDK directory>" export ANDROID_NDK="<path to your Android NDK directory>" export PATH="$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK"
Save the file and log out from your current session.
Log in again and open a terminal. Enter the following command:
$ android
The Android SDK and AVD Manager window shows up.
Go to the Installed packages section and click on Update All:

A package selection dialog appears. Select Accept All and then Install.
After few minutes, all packages get downloaded and a message asking to restart ADB service (the Android Debug Bridge) appears. Validate by clicking on Yes.
You can now close the application.
We have downloaded and deployed both Android SDK and NDK and made them available through the command line using environment variables.
Tip
Mac OS X and environment variables
Mac OS X is tricky when it comes to environment variables. They can be easily declared in a .profile for applications launched from a terminal, as we just did. They can also be declared using an environment.plist file for GUI applications, which are not launched from Spotlight. A more powerful way to configure them is to define or update /etc/launchd.conf system file (see http://developer.apple.com/).
We have also launched the Android SDK and AVD manager, which aims at managing the installation, updates, and emulation features of the SDK components. This way, new SDK API releases as well as third-party components (for example, Samsung Galaxy Tablet emulator, and so on) are made available to your development environment without having to reinstall the Android SDK.
If you have trouble connecting at step 9, then you may be located behind a proxy. In this case, Android SDK and AVD manager provide a Settings section where you can specify your proxy settings.
To work with Android NDK, we need to check and install some system packages and utilities:
First, Glibc (the GNU C standard library, in version 2.7 or later) must be installed. It is usually shipped with Linux systems by default. Check its version using the following command:
$ ldd -–version
We also need the Make build tool for native code. Installation can be performed using the following command:
$ sudo apt-get install build-essentialAlternatively, Make can be installed through Ubuntu Software Center. Look for build-essential in the dedicated search box and install the packages found:

Package
build-essentialcontains a minimal set of tools for compilation and packaging on Linux Systems. It also includes GCC (the GNU C Compiler), which is not required for standard Android development as Android NDK already packages its own version.To ensure that Make is correctly installed, type the following command. If correctly installed, the version will be displayed:
$ make --version
Tip
Special note for 64-bit Linux owner
We also need 32-bit libraries installed to avoid compatibility problems. This can be done using the following command (to execute in a command-line prompt) or again the Ubuntu Software Center:
sudo apt-get install ia32-libs
To run Eclipse and allow compilation of Android Java code to bytecode, Java Development Kit is required. We need to download and install Oracle Sun Java Development Kit. On Ubuntu, this can be performed from the Synaptic Package Manager:
Open Ubuntu System/Administration menu and select Synaptic Package Manager (or open your Linux package manager if you use another Linux distros).
Go to the Edit | Software Sources menu.

In the Software Sources dialog, open the Other Software tab.
Check the Canonical Partners line and close the dialog:

Package cache synchronizes automatically with the Internet, and after a few seconds or minutes some new software is made available in the Canonical Partners section.
Find Sun Java™ Development Kit (JDK) 6 (or later) and click on Install. You are also advised to install Lucida TrueType fonts (from the Sun JRE), the Java(TM) Plug-in packages.
Accept the license (after reading it carefully of course!). Be careful as it may open in the background.
When installation is finished, close Ubuntu Software Center.
Although Sun JDK is now installed, it is not yet available. Open JDK is still used by default. Let’s activate Sun JRE through the command line. First, check available JDK:
$ update-java-alternatives –l
Then, activate the Sun JRE using the identifier returned previously:
$ sudo update-java-alternatives –s java-6-sunOpen a terminal and check that installation is OK by typing:
$ java –version
The Android SDK supports Ant, a Java-based build automation utility, to compile projects from the command line. Let’s install it.
Install Ant with the following command or with the Ubuntu Software Center:
$ sudo apt-get install antCheck whether Ant is properly working:
$ ant --version
We have prepared our Linux operating system with the necessary utilities to host Android development tools.
We have installed a Java Development Kit in version 1.6 and checked if it is properly working from the command line. Because Android SDK uses generics, the JDK in version 1.5 is the least required for Android development.
You may wonder why we bothered with the installation of Sun JDK while Open JDK is already ready to use. The reason is simply that Open JDK is not officially supported by Android SDK. If you want to avoid any possible interaction with Open JDK, think about removing it entirely from your system. Go to the Provided by Ubuntu section in the Ubuntu Software Center and click on Remove for each OpenJDK line. For more information, look for the official Ubuntu documentation: http://help.ubuntu.com/community/Java.
Finally, we have installed Ant utility that we are going to use in the next chapter to build projects manually. Ant is not required for Android development but is a very good solution to set up a continuous integration chain.
Open your web browser and go to http://developer.android.com/sdk. This web page lists all available SDKs, one for each platform.
Download Android SDK for Linux, which is packaged as a Tar/GZ archive.
Then, go to http://developer.android.com/sdk/ndk and download the Android NDK (not SDK!) for Linux, packaged as a Tar/BZ2 archive this time.
Uncompress the downloaded archives separately into the directories of your choice (for example,
~/AndroidSDKand~/AnroidNDK). On Ubuntu, you can use Archive Manager (right-click on the archive file and Extract Here).Let’s declare these two directories as environment variables. From now on, we will refer to these directories as $ANDROID_SDK and $ANDROID_NDK throughout this book. Assuming you use a Bash command-line shell, edit your .profile file (be careful, this is a hidden file!) in your home directory and add the following variables:
export ANDROID_SDK="<path to your Android SDK directory>" export ANDROID_NDK="<path to your Android NDK directory>" export PATH="$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK"
Save the file and log out from your current session.
Log in again and open a terminal. Enter the following command:
$ androidThe Android SDK and AVD Manager window shows up.
Go to the Installed packages section and click on Update All:

A package selection dialog appears. Select Accept All and then Install.
After a few minutes, all packages get downloaded and a message asking to restart ADB service (the Android Debug Bridge) appears. Validate by clicking on Yes.
You can now close the application.
We have downloaded and deployed both Android SDK and NDK and made them available through the command line using environment variables.
We have also launched the Android SDK and AVD manager, which aims at managing the installation, updates, and emulation features of the SDK components. This way, new SDK API releases as well as third-party components (for example, Samsung Galaxy Tablet emulator, and so on) are made available to your development environment without having to reinstall Android SDK.
If you have trouble connecting at step 9, then you may be located behind a proxy. In this case, Android SDK and AVD manager provide a Settings section where you can specify your proxy settings.
Command line lovers, vi fanatics, please go to the next chapter or you may feel sick! For most humans, having a comfortable and visual-friendly IDE is essential. And hopefully, Android works with the greatest of all: Eclipse!
Eclipse is the only officially supported IDE for Android SDK through the Google official plugin named ADT. But ADT is only for Java. Hopefully, Eclipse supports C/C++ as well through CDT, a general C/C++ plugin. Although not specific to Android, it works well with the NDK. The version of Eclipse used throughout this book is Helios (3.6).
Open your web browser and go to http://www.eclipse.org/downloads/. This web page lists all available Eclipse packages: for Java, J2EE, C++.
Download Eclipse IDE for Java Developers.
Extract the downloaded Tar/GZ file (on Linux and Mac OS X) or ZIP file (on Windows) with your archive manager.
Once extracted, run Eclipse by double-clicking on the eclipse executable inside its directory. On Mac OS X, make sure to execute eclipse alias and not Eclipse.app or else environment variables defined earlier in
.profilewill not be available to Eclipse.If Eclipse asks for a workspace, define a custom workspace directory if you want to (default workspace is fine) and click OK.
After Eclipse has started, close the Welcome Page.
Go to the Help | Install New Software menu.
Tip
If a problem occurs in the next steps while accessing update sites, then check your Internet connection. You may be either disconnected or your computer is behind a proxy. In the latter case, it is possible to download ADT plugin as an archive file from the ADT web page and install it manually (or configure Eclipse to connect through a proxy but that is another matter).
Enter https://dl-ssl.google.com/android/eclipse/ in the Work with field and validate.

After a few seconds, a Developer Tools plugin appears; select it and click on the Next button.
Follow the wizard and accept conditions when asked. On the last wizard page, click on Finish.
ADT gets installed. A warning may appear indicating that plugin content is unsigned. Ignore it and click on OK.
When finished, restart Eclipse as requested.
When Eclipse is restarted, go to menu Window | Preferences (Eclipse | Preferences on Mac OS X) and go to the Android section.
Click on Browse and select the path to your Android SDK directory.

Validate preferences.
Go back to the Help | Install New Software... menu.
Open the Work with combobox and select the item containing Eclipse version name (here Helios).
Find Programming Languages in the plugin tree and open it.
Select CDT plugins. Incubation plugins are not essential. C/C++ Call Graph Visualization is for Linux only and cannot be installed on Windows or Mac OS X:

Follow the wizard and accept conditions when asked. On the last wizard page, click on Finish.
When finished, restart Eclipse.
Eclipse is now installed and official Android development plugin ADT and C/C++ plugin CDT are installed. ADT refers to the Android SDK location.
The main purpose of ADT is to ease integration of Eclipse with SDK development tools. It is perfectly possible to develop in Android without an IDE using command line only. But automatic compilation, packaging, deployment, and debugging are addictive features, which are hard to get rid of!
You may have noticed that no reference to the Android NDK is given to ADT. This is because ADT works for Java only. Hopefully, Eclipse is flexible enough to handle hybrid Java/C++ projects! We will talk about that further when creating our first Eclipse project.
In the same way, CDT allows easy integration of C/C++ compilation features into Eclipse. We also "silently" installed JDT, the Java plugin for Eclipse. It is embedded in the Eclipse IDE for Java Developers package. An Eclipse package including only CDT is also available on the Eclipse Website.
Tip
More on ADT
ADT update site given to Eclipse in step 8 comes from the official ADT documentation that you can find at http://developer.android.com/sdk/eclipse-adt.html. This page is the main information point to visit if new versions of Eclipse or Android are released.
Open Android SDK and AVD Manager using either the command line (key in android) or the Eclipse toolbar button:

Click on the New button.
Give a name to this new emulated device: Nexus_480x800HDPI.
Target platform is Android 2.3.3.
Specify SD card size: 256.
Enable snapshot.
Set Built-in resolution WVGA800.
Leave the Hardware section the way it is.
Click on Create AVD.

The newly created virtual device now appears in the list:

Let’s check how it works: click on the Start button.
Click on the Launch button:

The emulator starts up and after a few minutes, your device is loaded:

We have created our Android Virtual Devices which emulate a Nexus One with an HDPI (High Density) screen of size 3.7 inches and a resolution of 480x800 pixels. So we are now able to test applications we are going develop in a representative environment. Even better, we are now able to test them in several conditions and resolutions (also called skins) without requiring a costly device.
Although this is out of the scope of this book, customizing additional options, such as the presence of a GPS, camera, and so on, is also possible when creating an AVD to test an application in limited hardware conditions. And as a final note, screen orientation can be switched with Ctrl + F11 and Ctrl + F12. Check out the Android website for more information on how to use and configure the emulator (http://developer.android.com/guide/developing/devices/emulator.html).
Tip
Emulation is not simulation
Although emulation is a great tool when developing, there are a few important points to take into account: emulation is slow, not always perfectly representative, and some features such as GPS support may be lacking. Moreover, and this is probably the biggest drawback: Open GL ES is only partially supported. More specifically, only Open GL ES 1 currently works on the emulator.
Now that you know how to install and update Android platform components and create an emulator, try to create an emulator for Android Honeycomb Tablets. Using the Android SDK and AVD Manager, you will need to do the following:
Install Honeycomb SDK components
Create a new AVD which targets Honeycomb platform
Start the emulator and use proper screen scaling to match real tablet scale
Depending on your computer resolution, you may need to tweak AVD display scale. This can be done by checking Scale display to real size when starting the emulator and entering your monitor density (use the ? button to calculate it). If you perform well, you should obtain the new Honeycomb interface at its real scale (no worries, it is also in Landscape mode on my computer):

Emulators can be of really good help, but nothing compared to a real device. Hopefully, Android provides the sufficient connectivity to develop on a real device and make the testing cycle more efficient. So take your Android in hand, switch it on and let’s try to connect it to Windows or Mac OS X.
Installation of a device for development on Windows is manufacturer-specific. More information can be found at http://developer.android.com/sdk/oem-usb.html with a full list of device manufacturers. If you have got a driver CD with your Android device, you can use it. Note that the Android SDK also contains some Windows drivers under $ANDROID_SDK\extras\google\usb_driver. Specific instructions are available for Google development phones, Nexus One, and Nexus S at http://developer.android.com/sdk/win-usb.html.
Mac users should also refer to their Manufacturer’s instructions. However, as Mac’s ease of use is not only a legend, simply connecting an Android device to a Mac should be enough to get it working! Your device should be recognized immediately without installing anything.
Once the driver (if applicable) is installed on the system, do the following:
Go to the home menu, then go to Settings | Application | Development on your mobile device (may change depending on your manufacturer).
Enable USB debugging and Stay awake.
Plug your device into your computer using a data connection cable (beware some cables are alimentation cables only and will not work!). Depending on your device, it may appear as a USB disk.
Launch Eclipse.
Open the DDMS perspective. If working properly, your phone should be listed in the Devices view:

Say cheese and take a screen capture of your own phone by clicking the corresponding toolbar button:

Now you are sure your phone is correctly connected!
We have connected an Android device to a computer in development mode and enabled the Stay awake option to stop automatic screen shutdown when the phone is charging. If your device is still not working, go to the Trouble shooting a device connection section.
The device and the computer communicate through an intermediate background service: the Android Debug Bridge (ADB) (more about it in the next chapter). ADB starts automatically the first time it is called, when Eclipse ADT is launched or when invoked from the command line.
Emulators can be of really good help, but it is nothing compared to a real device. Hopefully, Android provides the sufficient connectivity to develop on a real device and make the testing cycle more efficient. So take your Android in hand, switch it on and let’stry to connect it to Linux.
Go to Home | Menu | Settings | Application | Development on your mobile device (may change depending on your manufacturer).
Enable USB debugging and Stay awake.
Plugin your device to your computer using a data connection cable (beware, some cables are alimentation cables only and will not work!). Depending on your device, it may appear as a USB disk.
Try to run ADB and list devices. If you are lucky, your device works out of the box and the list of devices appears. In that case, you can ignore the following steps:
$ adb devices
If ????????? appears instead of your device name (which is likely), then ADB does not have proper access rights. We need to find your Vendor ID and Product ID. Because Vendor ID is a fixed value for each manufacturer, you can find it in the following list:
Manufacturer
USB Vendor ID
Acer
0502
Dell
413c
Foxconn
0489
Garmin-Asus
091E
HTC
0bb4
Huawei
12d1
Kyocera
0482
LG
1004
Motorola
22b8
Nvidia
0955
Pantech
10A9
Samsung
04e8
Sharp
04dd
Sony Ericsson
0fce
ZTE
19D2
The current list of Vendor IDs can be found on the Android website at http://developer.android.com/guide/developing/device.html#VendorIds.
The device Product ID can be found using the lsusb command "greped" with Vendor ID to find it more easily. In the following example, the value
0bb4is the HTC Vendor ID and0c87is the HTC Desire product ID:$ lsusb | grep 0bb4
With the root user, create a file
/etc/udev/rules.d/52-android.ruleswith your Vendor and Product ID:$ sudo sh -c ‘echo SUBSYSTEM==\"usb\", SYSFS{idVendor}==\"<Your Vendor ID>\", ATTRS{idProduct}=\"<Your Product ID>\", MODE=\"0666\" > /etc/udev/rules.d/52-android.rules’Change file rights to 644:
$ sudo chmod 644 /etc/udev/rules.d/52-android.rulesRestart the udev service (the Linux device manager):
$ sudo service udev restartRelaunch the ADB server in the root mode this time:
$ sudo $ANDROID_SDK/tools/adb kill-server $ sudo $ANDROID_SDK/tools/adb start-server
Check whether your device works by listing the devices again. If ????????? appears, or worse, nothing appears, then something went wrong in the previous steps:
$ adb devices
We have connected an Android device to a computer in development mode and enabled the Stay awake option to stop automatic screen shutdown when the phone is charging. If your device is still not working, go to thon section.
We have also started the Android Debug Bridge (ADB), which is a background service used as a mediator for computer/device communication (more about it in the next chapter). ADB is started automatically the first time it is called, when Eclipse ADT is launched or when invoked from the command line.
And more important than anything, we have discovered that HTC means High Tech Computer! Jokes apart, the connection process can become tricky on Linux. If you belong to the unlucky group of people who need to launch ADB as the root, you are highly advised to create a startup script similar to the following one, to launch ADB. You can use it from the command line or add it to your main menu (Menu | Preferences| Main Menu on Ubuntu):
#!bin/sh stop_command="$ANDROID_SDK/platform-tools/adb kill-server" launch_command="$ANDROID_SDK/platform-tools/adb start-server" /usr/bin/gksudo "/bin/bash –c ‘$stop_command; $launch_command’" | zenity –text-info –title Logs
This script displays daemon startup message in a Zenity window (a Shell toolkit to display graphical windows using GTK+).
Having trouble connecting an Android development device to a computer can mean any of the following:
Your host system is not properly set up
Your development device is not working properly
The ADB service is malfunctioning
If the problem comes from your host system, check your device manufacturer instructions carefully to make sure any needed driver is correctly installed. Check the Hardware properties to see if it is recognized and turn on the USB storage mode (if applicable) to see if it is working properly. Indeed, after getting connected, your device may be visible in your hardware settings but not as a disk. A device can be configured as a Disk drive (if a SD-card or similar is included) or in charge-only mode. This is absolutely fine as the development mode works perfectly in the charge-only mode.
Disk-drive mode is generally activated from the Android task bar (USB connected item). Refer to your device documentation for the specificities of your device.

Tip
When the charge-only mode is activated, SD card files and directories are visible to the Android applications installed on your phone but not to your computer. On the opposite side, when Disk drive mode is activated, those are visible only from your computer. Check your connection mode when your application cannot access its resource files on a SD Card.
If problem comes from your Android device, a possible solution is to deactivate and reactivate the Debug mode on your device. This option can be switched from the Home | Menu | Settings | Application | Development screen on your mobile device (which may change depending on your manufacturer) or accessed more quickly from the Android task bar (USB debugging connected item). As a last measure, reboot your device.
Problem may also come from the ADB. In that case, check whether the ADB is working by issuing the following command from a terminal prompt:
$ adb devices
If your device is correctly listed, then ADB is working. This command will launch ADB service if it was not already. You can also restart it with commands:
$ adb kill-server $ adb start-server
In any case, to solve a specific connection problem or get up-to-date information, visit the following web page: http://developer.android.com/guide/developing/device.html. As a feedback from experience, never neglect hardware. Always check with a second cable or device if you have one at your disposal. I once purchased a bad quality cable, which performed badly when some contortions occurred...
Setting up our Android development platform is a bit tedious but is hopefully performed once and for all! We have installed the necessary utilities using the package system on Linux, Developer Tools on Mac OS X, and Cygwin on Windows. Then we have deployed the Java and Android development kits and checked if they are working properly. Finally, we have seen how to create a phone emulator and connect a real phone for test purposes.
We now have the necessary tools in our hands to shape our mobile ideas. In the next chapter, we are going to handle them to create, compile, and deploy our first Android projects!