Reader small image

You're reading from  Learning Embedded Android N Programming

Product typeBook
Published inJul 2016
Reading LevelIntermediate
PublisherPackt
ISBN-139781785282881
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Ivan Morgillo
Ivan Morgillo
author image
Ivan Morgillo

Ivan Morgillo is a computer engineer, a conference speaker, and a community organizer. He is passionate about programming and embedded systemsfrom DIY domotics to Android devices. He is cofounder of Alter Ego Solutions, a mobile development consulting company. He is also the author of RxJava Essentials, by Packt Publishing and Grokking Rx, by Manning Publications.
Read more about Ivan Morgillo

Right arrow

Chapter 2. Obtaining the Source Code – Structure and Philosophy

In the previous chapter, we had an overview about the system layer-based architecture and we had our first hands-on experience, testing a real-world device using CTS tools suite.

In this chapter, the user will learn about the philosophy behind the Android and Google development model. We will show how the source code is organized, which are the main branches, and what the workflow is. We will create a step-by-step journey to retrieve the Android Open Source Project (AOSP) source code and prepare the environment by installing all the required tools.

The user will learn how to contribute to the Android Open Source Project, how to use tools such as git, the version-control system, and, repo, the repository manager.

To complete the chapter, we will dig into the AOSP folder structure, analyzing the most important components that create the most popular mobile operating systems of the world.

The Android philosophy


Android is an open source platform created to be compatible with a huge number of different devices, from a hardware point of view to a purpose point of view. The main goal is to provide a freely available software platform for both large enterprise companies and small independent makers or even single developers. Android aims to provide an easy way to create innovative solutions and bring them to market with no effort.

Everything started in 2005, when Google acquired Android Inc., a small company that was developing an operating system for mobile devices. A couple of years later, the Open Handset Alliance was born. In 2007, 84 companies, including mobile operators, handset manufacturers, and semiconductor and software companies, publicly announced their brand new, upcoming mobile operating system.

For one more whole year the project was kept a secret. Google worked hard to bring the project to version 1.0 and in 2008 Android was shown to the world. In the following...

Setting up the environment


The Android build system is officially supported by Ubuntu Linux. Google assures that the system setup, the environment setup, and all the requirements are easily reproducible on this particular Linux distribution. The truth is, nowadays, every Linux distribution can be prepared to perform a proper Android build with little effort.

To be closest to the guidelines and because we think that Ubuntu is the easiest system to set up for the job, in this book we are going to use Ubuntu Linux 15.04 to perform all our building procedures.

If you are working on OS X or Windows and you prefer to stick to these operating systems, we are going to show you how to achieve our goal even using a virtual machine.

Free space

The amount of free space on the hard drive needed by the build system is massive. The Android source code by itself can reach 100 gigabytes of occupied space. When we move to more advanced scenarios, such as building using a caching system, such as ccache, to speed...

Installing the required tools


Even if officially the supported Linux distribution is Ubuntu, the following procedures and commands are equally correct on every Debian-based distribution, if it is actually installed on your computer or is running as a virtual machine.

To be able to acquire the source code, retrieving it from Google git repository, we need to install git. Let's open a Terminal and run:

~$ sudo apt-get install git

Apt will ask for our super user password and will take care of installing git in the system. Once we have git, we need its trusted companion tool—repo. Repo does not need a real installation. It's a Python script, so we just need to download it and place it in a handy folder.

Let's create a bin folder in our home folder and add it to the system path:

~$ mkdir ~/bin
~$ export PATH=~/bin:$PATH

Now that we have a folder, we can download repo using curl:

~$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
~$ chmod a+x ~/bin/repo

Note

If curl is...

Getting ready


As we already know, Google is the official manager of the entire hardware infrastructure supporting Android—everything is hosted and maintained by Google. The source code repository also provides a web UI to graphically navigate the source code. This source code browser is available at https://android.googlesource.com/.

The following screenshot shows an example of what the page looks like:

Every single item of the list shown in the previous screenshot is a git repository. This can give you a perfect idea of the importance of Google's repo tool—manually managing this many repositories would be pure madness! Using repo, retrieving, downloading, and creating the proper folder structure is a few-lines' task. Let's do it!

First things first—create a working folder. Open a Terminal and create a folder like this:

~$ mkdir WORKING_DIRECTORY
~$ cd WORKING_DIRECTORY

Once in the folder, run:

~/WORKING_DIRECTORY$ repo init -u https://android.googlesource.com/platform/manifest

The URL specifies...

A look inside AOSP


At this point, we have our copy of AOSP so we can start looking inside to see what the project consists of.

Before delving inside, we must warn you that, when generating a new build image from scratch, you won't find any of the Google applications that you can find on most of the Android devices. That is because the Google applications are not licensed under Apache 2.0 license, so they are not provided with the public project. We are talking about applications such as Play Store, Gmail, YouTube, Maps, and all other official Google apps.

These applications are provided only to the compatible devices, that is, the devices that pass the Compatibility Test Suite we met in the first chapter.

Being able to distribute an Android device with all Google's app on-board is no easy trip. After confirming that the device is compatible using CTS, it is also necessary to obtain a particular Google Mobile Services (GMS) license by contacting Google directly.

Obviously, you can find those...

Summary


In this chapter, we have learned lots of very important things that represent the basis of Android.

We started with the Android philosophy regarding the licenses and the development model touching on different versions of Android that followed. We have learned to install and use the tools necessary to contribute to the AOSP project, and also how to download a copy of the AOSP source code, selecting the right TAG to get the wanted version of Android.

In the next chapter, we will make the first build, generating an image for the emulator, but first we will explain how the Android build system works and what tools we need to install.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning Embedded Android N Programming
Published in: Jul 2016Publisher: PacktISBN-13: 9781785282881
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ivan Morgillo

Ivan Morgillo is a computer engineer, a conference speaker, and a community organizer. He is passionate about programming and embedded systemsfrom DIY domotics to Android devices. He is cofounder of Alter Ego Solutions, a mobile development consulting company. He is also the author of RxJava Essentials, by Packt Publishing and Grokking Rx, by Manning Publications.
Read more about Ivan Morgillo