Android devices continue to grow in popularity within the smartphone and tablet markets, and the demand for good applications on the platform is ever increasing. For those of you who may be curious about what it takes to develop an application for Android, let us take a look together at the key concepts you will need to know in order to get started.
Android is a free and open-source mobile platform that is currently shepherded and maintained by Google. What I mean by free is that anyone who wishes to use the core Android platform for their own hardware can freely obtain the source code and modify it for their specific device without needing to obtain any licensure from Google or pay a royalty. Android is also open-sourced under the Apache 2.0 license, which means that anyone may freely modify the Android code and distribute their modified version without being required to submit their modifications back to the platform, or in any way make those addition open source as well.
Because of these two elements, device manufacturers have been very receptive to using Android in their products. They are drawn in by the fact that they can customize the system to create differentiation, while still delivering a product that is part of a common platform for developers; and all this without any license fees from Google.
Android is somewhat unique in the way its applications are constructed. Unlike many popular mobile platforms, Android doesn’t clearly define a singular application concept. Instead, Android classifies an “application” as a loosely grouped-together package of screens that interact with the user (each known as an Activity) and background operations (known as Services).
Developers will find that the framework included in the Android software stack does not provide a global set of events to assist them in determining when a user launches or leaves their application as a whole. Instead, Android’s primary focus is on the user moving from one Activity to another, regardless of whether those two Activities were within the same application. With this model comes the ability to seamlessly launch portions of other applications from within your own, even if those applications were not bundled with the system.
Services are the other main component of an Android application, designed to represent any operation an application may need to do in the background without direct user interaction. Services are a very important part of what makes Android such a powerful platform. They allow a developer to create portions of an application to execute for as long as necessary at any time, even when that application is not in the foreground. However, since Android does not provide hard-limits Service execution, it is up to developers to make sure they are being good citizens and not destroying the user’s battery in exchange for executing in the background.
System events: Android uses a mechanism known as Broadcasts to notify applications of system events. If an application needs to know when a device has finished booting, when the screen turns on and off, or about status changes in the network or battery, it can register to receive these broadcasts that the system generates when these events occur. The Broadcast system is also quite extensible; any application can generate a Broadcast. In this way, developers can create a powerful event-notification system within their own apps using Broadcasts.
Google Services: It should be noted that there are software components found on most Android devices, known as Google Services, that are not part of the core Android platform and are not open source. These include applications like Google Talk, Gmail, and Google Play (Google’s application marketplace). In order for a device to include these services, they must first be approved by Google to receive that application package.
One thing that Google requires in order for Google Services to be included on a device is for that device to successfully pass the Compatibility Test Suite, or CTS. CTS is Google’s method of guaranteeing that the Android platform code used on a particular device complies properly with all the APIs and frameworks application developers expect to be available. If a device manufacturer has modified its Android version to the point where these core APIs do not function as documented, that device will not be able to include the Google Services package.
The development environment: Google provides two packages to developers to assist them in creating applications for Android: the SDK and the NDK. Most developers will write applications based on the Android SDK, which uses primarily Java and XML.
XML is the primary language of Android to define resources and views. Developers will use XML heavily in applications to define the view layouts that will be displayed on-screen by each Activity. In addition, drawable content like shapes, colors, gradients and image backgrounds can also be defined completely using XML. While both of these functions can also be done using Java code, XML is often preferred for its clean syntax and simplicity. The remainder of the application code that utilizes the SDK will be written using Java.
Developers will need to download the Android SDK Manager from Google and use it to get the latest version of the SDK components, which is not tied to any particular IDE. Applications can be written using any preferred editor, then built and exported as an APK (the final application binary) using Apache Ant. Most developers, however, prefer a more integrated approach and choose an IDE such as Eclipse or JetBrains’ IntelliJ. Eclipse supports Android development through a plug-in called ADT, which is supported and maintained by the Android team at Google. IntelliJ’s Android support is independently maintained by JetBrains and is baked into the IDE.
Even if you choose to develop using a recommended IDE, the SDK tools will still need to be downloaded first.
Android NDK: Because Android applications are written in Java, they run inside of a virtual machine instead of as truly native code, which some may see as a performance detractor. For most applications, this will not be an issue thanks to the highly optimized Dalvik VM that Android uses. However, developers looking to add a bit more performance to aspects of their application can look to the Android NDK. The NDK includes a tool chain and small set of APIs to compile bits of native code (written primarily in C) to be included in their applications. The native code is compiled into a dynamic library (.so) that is included with the main application and accessed using JNI. It can be found here.
The trade-off in doing so is that native code must be compiled for a specific Application Binary Interface (ABI), so the NDK code will only run on that platform architecture, reducing the ubiquity of the application. (As of this writing, the NDK supports the ARM, ARMv7, MIPS and x86 ABIs.) The NDK does support creation of a “fat binary,” where a library file is compiled for each ABI a developer wants his or her application to support, and all of them can then be included in the resulting Android application binary. Android is smart enough to load the library that corresponds to the ABI of the device the user is running on if multiple versions are included, but this can dramatically increase the binary size, hence the name.
Until recently, developing with the NDK has been much less integrated. Installing the NDK tools from Google provides the build tool chain that can be run from a command line to compile the native files into the .so file hierarchy. There, each ABI is listed by directory with the appropriate libraries inside, and those files are then installed into the SDK application’s libs directory to be referenced by the main application.
However, starting with ADT 20, NDK development can also be done inside the Eclipse IDE alongside SDK development by utilizing the Eclipse C Development Tools plug-in.
Once your company has finished development on your Android app, it’s time to ship it to market! The Android ecosystem is fairly open in terms of how you can distribute your applications to users, and as such there are a multitude of options to choose from, ranging from Google’s marketplace to simply hosting the file yourself for download.
The most common method to distribute your application is Google Play (formerly Android Market). In order to distribute applications with Google Play, you must register for an account through the Android Developer Console, which will cost you a one-time fee of US$25. Afterward, you are free to upload any APK for sale on the Google Play marketplace.
In addition to being the “official” marketplace for applications, Google Play is the most popular choice for developers because of the CTS requirement. Developers can be assured that the SDK frameworks used in their applications are properly supported by a user’s device if that device includes Google Play.
Third-party app stores
Because Google Services are optional, not all Android devices will have Google Play. Android devices are sold in more countries than the current 129 countries that Google Play operates in. If you are interested in distributing applications into these other markets, marketplaces such as GetJar, Handango or SlideME allow you that opportunity.
Even if targeting only customers in the United States, you may still consider distributing your application through third-party channels in addition to Google Play. Both Amazon and Barnes & Noble have their own application marketplaces, which is the only place for users of the Kindle Fire and Nook devices to buy apps. These consumer tablet devices are quite popular and do not have Google Play, so if you plan to develop an application specifically for tablets, this mechanism may be of interest.
Both of these marketplaces run a little more tightly than Google Play. While both are free, getting a developer account will first require approval before you can start distributing any applications. These accounts are still simple to obtain, but there is a bit more red tape. In addition, the apps themselves are subject to review before going live, something that Google Play still does not do, so you do have the small possibility of an application being rejected.
Finally, if you would like to distribute the application yourself, or if it is for internal use at your company, the application’s APK file can easily be sent or hosted directly for access by any Android device, which can download and install the file without any additional market software. This can also be an effective way of distributing applications to early users during beta testing.
The popularity trend of the Android platform continues to be a strong one. As more users come to the platform, the demand for quality applications also begins to grow. Get started today by heading over to developer.android.com.
For more on Android development, check out this addendum from David Smith.
David Smith is the lead engineer for mobile and embedded development at Xcellent Creations. Prior to that, he worked as an engineer developing embedded wireless monitoring and control systems for the industrial automation market. Today, his focus is on writing mobile applications that interface with custom hardware and accessories.