The Android operating system is like a cake
consisting of various layers. Each layer has its own characteristics and
purpose. The layers are not cleanly separated but often seep into each other.
Lets discuss about each layer from bottom to top.
- Linux Kernel
Android
is built on top of a solid and proven foundation: the Linux kernel. Created by
Linus Torvalds in 1991, Linux can be found today in everything from
wristwatches to supercomputers. Linux provides the hardware abstraction layer
for Android, allowing Android to be ported to a wide variety of platforms in
the future. There are many good reasons for choosing Linux as the base of the Android
stack. Some of the main ones are its portability, security, and features
- Native Libraries
The native libraries are C/C++ libraries, often
taken from the open source community in order to provide necessary services to
the Android application layer. Among others, they include:
Webkit
A fast web-rendering engine used by Safari, Chrome,
and other browsers
SQLite
A full-featured SQL database
Apache Harmony
An open source implementation of Java
OpenGL
3D graphics libraries
OpenSSL
The secure locket layer
Although many of these libraries are used as-is,
one notable exception is Bionic, which is basically a rewritten version of the
standard C library. Bionic is used for two reasons:
Technology
To make it purpose-built for tiny, battery-powered
devices
License
To make it license-friendly for others who might
want to adopt it and change it
Dalvik
Dalvik is a purpose-built virtual machine designed
specifically for Android, developed by Dan Bornstein and his team at Google.
The Java virtual machine (VM) was designed to be a
one-size-fits-all solution, and the Dalvik team felt they could do a better job
by focusing strictly on mobile devices. They looked at which constraints
specific to a mobile environment are least likely to change in the near future.
One of these is battery life, and the other is processing power. Dalvik was
built from the ground up to address those constraints.
Another side effect of replacing the
Java VM with the Dalvik VM is the licensing. Whereas the Java language, Java
tools, and Java libraries are free, the Java virtual machine is not. This was
more of an issue back in 2005 when the work on Dalvik started. Nowadays, there
are open source alternatives to Sun’s Java VM, namely the OpenJDK and Apache Harmony projects.
By developing a truly open source and
license-friendly virtual machine, Android yet again provides a full-featured
platform that others are encouraged to adopt for a variety of devices without
having to worry about the license.
Android and Java
In Java, you write your Java source file, compile
it into a Java byte code using the Java compiler, and then run this byte code
on the Java VM. In Android, things are different. You still write the Java
source file, and you still compile it to Java byte code using the same Java
compiler. But at that point, you recompile it once again using the Dalvik
compiler to Dalvik byte code. It is this Dalvik byte code that is then executed
on the Dalvik VM.
You may wonder, why not compile straight from Java
into the Dalvik byte code? There are a couple of good reasons for the extra
steps. Back in 2005, when work on Dalvik started, the Java language was going
through frequent changes, but the Java byte code was more or less set in stone.
So, the Android team chose to base Dalvik on Java byte code instead of Java
source code. A side effect of this is that in theory you could write Android
applications in any other language that compiles down to Java byte code. For
example, you could use Python or Ruby.
- Application Framework
Sitting above the native libraries and runtime, you’ll find the Application Framework layer. This layer provides the high-level building blocks you will use to create your applications. The framework comes preinstalled with Android, but you can also extend it with your own components as needed.
The most important parts of the framework are as follows:
Activity Manager: This controls the life cycle of applications
Content providers: These objects encapsulate data that needs to be shared between applications, such as contacts.
Resource manager: Resources are anything that goes with your program that is not code.
Location manager: An Android phone always knows where it is.
Notification manager: Events such as arriving messages, appointments, proximity alerts and more can be presented in an unobtrusive fashion to the user.
- Applications
And finally, there are the applications that you
and other developers create. These applications are what end users find
valuable about Android. They can come preinstalled on the device or can be
downloaded from one of the many Android markets.
The APK
An application is a single application package
(APK) file. An APK file roughly has three main components. An API consists of
the following major components:
Dalvik executable
This is all your Java source code compiled down to
a Dalvik executable. This is the code that runs your application.
Resources
Resources are everything that is not code. Your
application may contain a number of images and audio/video clips, as well as
numerous XML files describing layouts, language packs, and so on. Collectively,
these items are the resources.
Native libraries
Optionally, your application may include some
native code, such as C/C++ libraries.
These libraries could be packaged together with
your APK file.