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 3. Set up and Build – the Emulator Way

In the previous chapter, we learned how to retrieve the source code and we had an overview of the folder's structure. We now know how the branching model works and how to contribute to the project. This is an important topic, because Android is an open source prot, but it's managed in a very different way compared to other popular open source projects.

In this chapter, we will set up the whole environment to get ready to build our first Android system and flash it to a real target. Our efforts will be focused to create a fully-working version for the official Android emulator.

The user will learn how to use tools such as adb and fastboot, two of the most important tools that Google provides.

Preparing the host system


To build a complex system such as Android, we need to satisfy a few hardware and software requirements. First of all the host system.

The official Linux distribution supporting the Android build environment is Ubuntu Linux. Google periodically releases new Android builds for its devices and all of them are created using Ubuntu. Currently, Google is using Ubuntu 14.04 even if this is not the latest version available.

Every example in this book will be developed and executed on a common notebook, with an Intel i5 CPU and 4 GB of RAM, running Ubuntu Linux 15.05, that's the latest available version. Using a different Linux version proves that if all the requirements are satisfied, you could build Android with any Linux distribution or even Mac OS X— if you can't set up Ubuntu, trying with a different version will be challenging, but will be worth trying, as a learning experience.

If you are a Microsoft Windows user, it is sad to say, you won't be able to build Android...

The Android build system


Before digging into configuring and building your first Android system, we will have an overview of the build system itself, the tools involved, and the unique approach to the whole process Google has.

There is very little official documentation available about creating new modules and about the build system itself. Most of your knowledge at the end of this journey will come from your own hands-on experience and from our experience that we put in these pages.

An overview

As with lots of projects out there, open source or closed source, Android uses the powerful tool make to build the whole system, but compared to all other projects, Android uses it in a completely different way.

The common approach of using make would be to use a hierarchy of Makefiles: one single root Makefile retrieves and runs every other Makefile, contained in some of the subfolders of the project. Usually, every subfolder represents a submodule of the main project and it can be built alone or could...

Creating a custom device


During our journey, you learned how to retrieve the source code and how to set up the build system. In this section, you are going to learn how to create a new target device and add it to the build system. The device we are going to create now has specific hardware features. It's a proof-of-concept device, with the only purpose of showing you how easily and quickly you can create a brand new device and then customize it.

Every device definition is contained in the device/ folder. First level folders contains all the manufacturer's folders. Every manufacturer folder contains its own devices. Let's create our own manufacturer and device folders: our brand is Irarref and our model is an F488. Open a Terminal, reach the WORKING_DIRECTORY folder, and run:

~$ mkdir –p device/irarref/f488

Once we have the folder structure in place, we need to create all those files that will allow the build system to detect our device and make it available as a target for the build system...

From zero to the screenlock


So far we have gathered an incredible amount of information about the architecture, about how to configure the build system, and our PoC device. It's time to create our first image for a real device and use it! We want to keep away all the possible hardware-related issues, so we will target the simplest nonhardware Android device: the Android emulator.

We are going to build the latest available Android Lollipop source code. As we learned, we are going to download it, configure it to target the emulator, build it, and try it on the device.

Setup

Let's set up our WORKING_DIRECTORY and download our precious source code. Open a Terminal and run the following commands:

:$ mkdir WORKING_DIRECTORY
:$ cd WORKING_DIRECTORY
:$ repo init –u https://android.googlesource.com/platform/manifest -b \
android-5.1.1_r9
:$ repo sync

After the download is completed, we can configure the environment. Let's run:

:$ build/envsetup.sh

This will create all those handy tools we will need...

Summary


This chapter was a great run! You prepared your system to build your first Android system. You learned how to configure and customize the build system. You learned the basic skills to create a custom module and include it into your system image. You created a system image from scratch and tested it on the Android emulator.

In the next chapter, we will raise the bar. We are going to move our efforts to a real hardware device. We will work with a smartphone, the Nexus 5, and a development board, the UDOO. We will manipulate the bootloader and the recovery partition to take complete control of the system.

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 €14.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