One way in which Android is quite different from other platforms is the distribution of its apps. On most other platforms, such as iOS, a single vendor holds a monopoly over the distribution of applications. Android allows many different stores, or markets. Each market has its own set of policies with respect to what is allowed, how the revenue is split, and so on. As such, Android is much more of a free market space in which vendors compete for business.
In practice, this free market is very much an oligopoly, with a few big markets and many smaller boutiques.
Google Play
The biggest market currently is Google Play, also known as Play Store (formerly “An‐
droid Market”), run by Google. All the major carriers and manufacturers have it pre‐
installed on their devices in order to provide users with the most apps. Google knows this and uses this near-monopoly as the tool to ensure those devices adhere to Android Compatibility Test Suite, or CTS for short. We discussed CTS in “Android Compatibil‐
ity” on page 4.
Other markets
In addition to Google’s own market, there are many smaller boutiques. Some of them are sponsored by carriers, such at T-Mobile, Sprint, and Verizon. Others may be run by specific manufacturers, such as Cisco and its enterprise app market to support the Cisco Cius business tablet. Additionally, enterprises are starting to roll out their own private boutiques to support their workforce, such as various US government departments.
Applications | 41
A notable exception in this group is Amazon’s App Store, which has big ambitions. It is also designed to support its Kindle Fire, an Android device that does not adhere to CTS and thus doesn’t get the access to Google Play.
Side-loading apps
Applications can also be distributed via the network or via the USB cable. When you download an APK file from a website through the browser, the application represented by the APK file is installed automatically on your phone. In the development mode, we’ll be using the ADB over USB to install apps on the device.
What about viruses, malware, spyware, and other bad things?
Given Android’s decentralized application distribution system, it is certainly possible for an unsuspecting user to download a malicious app that consequently does bad things.
For example, there have been reports of phishing attacks via fake banking apps. Android has succeeded at becoming the number one platform for vicious apps.
Doesn’t all this create an issue for the users? It certainly appears so. Android leaves it to the marketplace to sort itself out. Eventually, there will be stores that are more reputable and those that are less so, at least in theory. Google relies on user reports for policing its Google Play, but other markets may choose to do more proactive testing and raise the bar on what gets into the store in the first place.
Summary
In this chapter, you got a big-picture overview of what comprises the Android operating system and how its various pieces fit together. You now understand what makes Android so complete, open, and attractive to developers.
In the next chapter, we’ll look at how to set up your development environment so you can get up to speed quickly. We’ll also look at a simple “Hello World” application and dissect it to help you understand the various pieces of an Android application.
CHAPTER 4
Installing and Beginning Use of Android Tools
In this chapter, you will learn how to set up your environment for Android development.
We’ll go beyond just listing where you can download the software, and will cover some of the best practices in getting set up. We’ll look at choices for development operating systems as well as the Android tools available. You will see the good, the bad, and the ugly of the various tool and platform choices that you’re about to make (or that someone else has already made for you).
By the end of this chapter, you will have your entire development environment set up.
You’ll be able to write a Hello World application, build it, and run it on the emulator (or a physical device, if you want).
We use ~ to refer to your home directory. On Mac OS X, that’s typi‐
cally something like /Users/marko. On Linux, it would be /home/
marko, on Windows Vista and 7, it would be C:\Users\marko, and on Windows XP it would be C:\Documents and Settings\marko. To keep things simple and consistent, we’re going to use Unix-style forward slashes and not Windows backslashes to denote file path separators.
So, if you’re on Windows, just change ~ to C:\Users\ YourUser‐
Name and / to \. Other than that, everything should be pretty much the same for different operating systems, regardless of whether you use OS X, Linux, or Windows.
Installing Java Development Kit
Android development is based on Java language, tools, and libraries. So one of the first requirements is that you install Java on your machine. Before proceeding, you may want
43
to check whether you already have Java, and whether it’s an up-to-date version. To do this, open your command-line terminal:
On Windows
Click Start, choose Run, and type cmd. This should open up a command prompt window.
On Mac
Start the Terminal application located in the /Applications/Utilities/ folder.
On Linux
Open the Terminal application.
In your terminal, type java -version and press Enter. If the Java runtime environment is set up, you should see a version number. Make sure it is 1.6 or greater.
Next, type javac -version to check whether you have a Java compiler installed. You should see a version number of 1.6 or greater as well. Example 4-1 shows an example of the desired outcome.
Example 4-1. Example of Java command-line output
[marko:~]> java -version java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-413-10M3623) Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-413, mixed mode) [marko:~]> javac -version
javac 1.6.0_31
If you pass these two tests, you can proceed to “Installing the Android SDK” on page 45. Otherwise, continue.
Mac users can install Java directly from the Software Update app. Linux users may have an automated package installation utility, depending on the Linux flavor. Windows users should install it via a download from the official Oracle site. You want the Java Devel‐
opment Kit (JDK) Standard Edition (SE), version 1.6 or later.
Java comes as a Runtime Environment (JRE) and Development Kit (JDK). To program for Java, you need the JDK, which includes the Runtime Environment. The JRE on its own is good only for running existing Java code.
Java also ships in three editions: Standard Edition (JavaSE), which is your basic Java;
Enterprise Edition (JavaEE, also known as J2EE), which is a bloated enterprise superset of libraries and tools; and Mobile Edition (JavaME), which is used by some mobile devices, but not by Android devices. What you need is Java SE.
Regarding versions, Android was initially based on Java version 1.5, a.k.a. Java 5. Since Gingerbread, it has been upgraded to Java 1.6, a.k.a. Java 6. So, version 1.6 is what you want. Note that as of right now, Java 1.7 or Java 7 is not fully supported by Android, nor
does Android need any Java 7 features. So if possible, stay away from it. If you must use it, you can make it work for Android by setting it to behave as Java 1.6 (in Eclipse, go to Preferences → Java → Compiler and set the Compiler compliance level to 1.6 or above).
After you download Java Development Environment Standard Edition 1.6 or later for your appropriate operating system, you can usually set it up just by running the auto‐
mated installation script. Repeat the command-line terminal tests discussed at the be‐
ginning of this section to make sure the installation was successful and you have the right version of Java installed.
Installing the Android SDK
The Android Software Development Kit (SDK) is necessary to develop applications for Android. The SDK comes with a set of tools as well as a platform where you can run programs and see it all work. You can download the Android SDK for your particular platform from the Android SDK Download page.
Once you download it, unzip (or on Linux, untar) it into a folder that is easy to get to.
Further examples in the book will assume your SDK is in the folder ~/android-sdk. If it’s in a different location, use that location instead of ~/android-sdk. For example:
Windows
For Windows users, we strongly recommend choosing directories whose names contain no spaces. This is because we’ll be doing work on the command line and spaces just complicate things. Because the Windows XP home directory is in C:\Documents and Settings, we would recommend putting android-sdk in a top-level directory that you create, such as C:\apps.
However, on Windows Vista or 7, you can simply extract android-sdk into C:\Users\YourUserName.