What is Android?
Android is the world's most famous operating system for mobile devices and tablets. It is an open-source running system, created by means of Google, and available to all types of builders with various know-how levels, ranging from rookie to professional.
(The time period 'open source' sounds pretty familiar, would not it? Well, open-source means software program with source available for modification and sure to an open-source license agreement. More about open source terminology can be located here.
From a developer's perspective, Android is a Linux-based operating system for smartphones and tablets. It consists of a contact display screen person interface, widgets, camera, network information monitoring, and all the other facets that allow a phone cellphone to be called a smartphone. Android is a platform that helps a number of applications, available through the Android Play Store. The Android platform additionally approves end-users to develop, install, and use their own applications on top of the Android framework. The Android framework is licensed below the Apache License, with Android application builders holding the proper to distribute their applications under their customized license.
Like most software, Android is released in versions. Google has also assigned names to its versions since April 2009. Below are all the versions of Android released to date:
Version No. | Name | For: |
1.0 | Android Beta | Phone |
1.1 | Android | Phone |
1.5 | Cupcake | Phone |
1.6 | Donut | Phone |
2.0/2.1 | Eclair | Phone |
2.2.x | Froyo | Phone |
2.3.x | Gingerbread | Phone |
3.x | Honeycomb | Tablet |
4.0.x | Ice Cream Sandwich | Phone and Tablet |
4.1/4.2 | Jelly Bean | Phone and Tablet |
As we can see in the table above, various versions of Android are supported on phones and tablets. There are umpteen Android devices available in the market from manufacturers like Samsung, HTC, Motorola and others. Google itself also has phones made in conjunction with OEMs, branded as the Nexus series.
Understanding Android
To begin development on Android even at the application level, I think it is paramount to understand the basic internal architecture. Knowing how things are arranged inside helps us understand the application framework better, so we can can design the application in a better way.
Android is an OS based on Linux. Hence, deep inside, Android is pretty similar to Linux. To begin our dive into the Android internals, let us look at an architectural diagram.
Applications
The diagram shows four basic apps (App 1, App 2, App 3 and App 4), just to give the idea that there can be multiple apps sitting on top of Android. These apps are like any user interface you use on Android; for example, when you use a music player, the GUI on which there are buttons to play, pause, seek, etc is an application. Similarly, is an app for making calls, a camera app, and so on. All these apps are not necessarily from Google. Anyone can develop an app and make it available to everyone through Google Play Store. These apps are developed in Java, and are installed directly, without the need to integrate with Android OS.
Application Framework
Libraries
This layer holds the Android native libraries. These libraries are written in C/C+ and offer capabilities similar to the above layer, while sitting on top of the kernel. A few of the major native libraries include
- Surface Manager: Manages the display and compositing window-ING manager. - Media framework: Supports various audio and video formats and codecs including their playback and recording.
- System C Libraries: Standard C library like lib targeted for ARM or embedded devices.
- Open GL ES Libraries : These are the graphics libraries for rendering 2D and 3D graphics.
- SQLite : A database engine for Android.
Android Runtime
Kernel
The Android OS is derived from Linux Kernel 2.6 and is actually created from Linux source, compiled for mobile devices. The memory management, process management etc. are mostly similar. The kernel acts as a Hardware Abstraction Layer between hardware and the Android software stack.
Android SDK
As already mentioned, Android is open source and hence the source code is available for all developers. In totality it is called the Android SDK. You can download, build and work on Android in a number of different ways-it all depends on what you want to do. If your goal is to develop an Android application, you don't necessarily need to download all the source. Google recommends the Eclipse IDE, for which there is an available Android Developer Tools (ADT) plugin, through which you can install the specific SDK, create projects, launch emulators, debug, etc. You can see more details of Eclipse and ADT through Android's official website for developers - http://developer.android.com/sdk/index.html
Android Development for Windows Users
Android as of now does not support building on Windows, so if you want to modify the Android OS itself, you'll have to use Linux (see building the Android OS). However, on Windows, we do have tools and plugins for application and native Android development. And here we will talk about setting up basic Android development tools on Windows.
Downloading the Android SDK and developer tools
Google provides a convenient bundle to download and setup Android for Windows developers, which you can download here, under the name ADT bundle for Windows. The exact name of the file you download will depend on your OS architecture (32 vs 64 bit), but for my case (64 Bit Win 7), I see the following zip file downloaded: adt-bundle-windows-x86_64.zip. Extracting the zip file, I have contents as in the following snapshot:
This is the SDK Manager, via which we can install or delete whatever version of SDK we want. As you can see, it mentions we have the Android SDK Tools and Android SDK Platform Tools installed.
The latest Android available, as of the writing of this article, is 4.2, but with the SDK we can download and install any of the previous versions too. Now let us play around with the latest Android-i.e., 4.2, which is also known as Jelly Bean.
Select the check box for "Android 4.2(API 17)", which will select everything required for and under Android 4.2.
In all, as we can see, SDK Manager found 6 packages that need installation. Click the "Install 6 packages" button. We see another dialog box for package descriptions and license.
Select "Accept All" and click Install, which will initiate the download and then installation. When done, you will see "Installed" in front of all the packages selected.
It's now time to launch Eclipse, but first, we need to make sure that we have the Java Developer Kit (JDK) installed. If you don't have it, you can download it from Oracle here. I have JDK 7 installed in my case. Next, we need to launch Eclipse from the executable present in the Eclipse directory. If we obtained Eclipse via the instructions in this article, it should already have the ADT plugin installed. (Otherwise, you can download the ADT separately by following the instructions here.) Eclipse generally asks for a workspace path where it will create and maintain projects.
Here is what the newly launched Eclipse looks like:
Another window will pop up to take inputs for device type, target processor, memory, etc.
You can provide customized device specifications for a virtual device. Once the device is created by clicking 'OK', it will be available in the list on "Android Virtual Device Manager" window. To launch the emulator for your own defined virtual device, select it and click "Start".You can also select pre-loaded options that correspond to the specifications of existing Android devices. To see them in the Android Virtual Device Manager, go to the Device Definitions tab.
We will assign Target as "Android 4.2 - API level 17" CPU as "ARM" and SD Card Size equals "1024 MiB" and click "OK". We can now see the newly defined virtual device in the AVD list
We can now use our newly-created emulator for running our Windows Android apps. All we have to do is compile our code, then load the app onto the emulator.
Building the Android OS
Memory Requirements
Prerequisite Installations
Prior to downloading the SDK and starting cross-compiling, there are certain prerequisites of the Android SDK we have to have. It is better to set up these before jumping into the Android SDK, as we all know prevention is much better than debugging! First of all, for the Android version we have chosen (i.e Android 4.0.1) cross compilation is well tested on 64 -bit machines, but the documentation says it is experimental on 32-bit machines.
1. JDK Android SDK building requires the JDK, so you must install the JDK. For Android versions 2.3.x and later, one needs to install Java 6. It is recommend to install Sun JDK only, rather than Open JDK. First, download the JDK 6. Then run the following commands. (Please Note: To avoid specifying a specific version, the installer binary name and directories are modified to be generic names.)
$ chmod +x jdk-6xxxx-linux-xxx.bin $ sudo./jdk-6xxxx-linux-xxx.bin $ sudo mv jdk1.6.xxxx /usr/lib/jvm/ $sudo update-alternatives -install /usr/bin/java java /usr/lib/jvm/jdk1.6.xxxx/bin/java 1 $ sudo update-alternatives -install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.xxxx/bin/javac 1 $ sudo update-alternatives -install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.xxxx/bin/javaws 1 $ sudo update-alternatives -config java $ sudo update-alternatives -config javac $ sudo update-alternatives -config javaws
For versions prior to 2.3.x, Java 5 is required. 2. You also need to install the following packages:
$sudo apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev ant gcc-multilib g+-multilib $sudo apt-get install libx11-dev:i386
These packages are needed for downloading and compiling the SDK. Once these get installed, you are ready to download the Android SDK. There may be some optional things to do, for example enabling caching, etc. But we will not go into much detail here as we don't really need to do those things.
Downloading the Android SDK
The entire Android SDK is stored in a git repository that also maintains various other versions as well. We need to know the repository path and then download to a separate directory where we wish to store the complete source.
Let us first create a root source directory.
$mkdir android
Further, we will initialize and configure a tool 'repo', which is used to work with git conveniently. To download it, we need a 'bin' directory in our home, which should be added to the path.
$mkdir bin $export PATH=$PATH:~/bin $curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > bin/repo $chmod a+x bin/repo
Now we have the repo installed and must initialise it with the path of git where the Android SDK lies. There is a master branch of git, which holds the latest Android version. The master branch in git is the main source repository, which means any new release or new update would be part of this master branch. However, if we want a specific Android version, we need to initialise with a specific branch.
Here in this article, we will go for a specific branch, since the master will keep on changing.
$repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
It will ask you for a name and email id, and you must provide them.
To get all the Android SDK files, you just now need to do:
$repo sync
It may take some time to download the complete source. In the end, we get
Syncing work tree: 100% (221/221), done.
This indicates the sources are downloaded. Let's have a look at the folder structure from the topmost level; here is what I have:
$ls abi build development external libcore packages system bionic cts device frameworks Makefile prebuilt bootable dalvik docs hardware ndk sdk
Building Android
Now that we have the source, the next step is to build it. The first factor we want to determine before the buildingis what platform are we going to run this Android on? It is necessary to decide this. The options could be the type ofyour device or an emulator.When flashing a phone, the worst case it that you may brick the smartphone in the event of a necessary bug. As aresult, it is a good idea to develop on Android thru an emulator-so we will do that.First of all, we want to set the environment variables, which are specified in a shell script.$ source build/envsetup.sh including device/samsung/maguro/vendorsetup.sh including device/samsung/tuna/vendorsetup.sh including device/ti/panda/vendorsetup.sh including sdk/bash_completion/adb.bashNext, we need to specify the target for which we need to cross-compile, using the command 'lunch'. But first of all, what is cross-compiling and why we need to do it? Well, cross-compiling is a compiling process that is done for a different platform, to create an executable or library to be used on a that different platform. Therefore, we would have two platforms,
- host : On which we have the sources and are being cross-compiled. In our case, this is our Linux machine.
- target: The platform for which the sources are being compiled for, and the compiled image or library will be used on the target platform. In this case, this would be our Android emulator.
This is required for embedded systems, as not all platforms support compiling and debugging. Examples of such platforms are ARM, MIPS, etc. For the target emulator and development build, we do
$lunch full-eng = PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=4.0.1 TARGET_PRODUCT=full TARGET_BUILD_VARIANT=eng TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm TARGET_ARCH_VARIANT=armv7-a HOST_ARCH=x86 HOST_OS=linux HOST_BUILD_TYPE=release BUILD_ID=ITL41D =Here 'full' is for emulator and 'eng' is because we want a development build. To see other available options, do:
$lunch You're building on Linux Lunch menu. pick a combo: 1. full-eng 2. full_x86-eng 3. vbox_x86-eng 4. full_maguro-userdebug 5. full_tuna-userdebug 6. full_panda-enNext, we just have to build the code using 'make'. GNU make has the ability to run parallel tasks. How many tasks to run in parallel is determined by the '-j' option. The usage is make -jN, where N is the number For example, to run 4 parallel tasks, our command would be
$make -j4It is common to set this number between 1 to 2 times the number of hardware threads the computer supports, which is generally the number of processors. To know how many processors we have in our system, we need to peek into the cpuinfo. To get the CPU info, we have command.
$cat /proc/cpuinfoHowever, to get to know the number of processors in a single command, we can use
$grep -c ^processor /proc/cpuinfoThe building of Android also takes quite a lot of time when done for the first time. Note, all the images, libraries and applications built are placed in the directory out/target/product/generic/
Running on the Emulator
To launch the emulator with our built Android, just run the following command
$emulatorThis will automatically pick the built images and binaries for the recently built Android. You can have the look and feel of the emulator environment, which is pretty similar to a device.
No comments: