Exploring SE for Android (2015)

Appendix A. The Development Environment

In order to build the Android 4.3 sources provided by UDOO, you need an Ubuntu Linux system with Oracle Java 6. While it may be possible to use a variant of this setup, Google's standard target development platform for Android 4.3 is Ubuntu 12.04. Therefore, we will use this setup to ensure the highest probability of success in our exploration of Linux, SE Linux, Android, the UDOO, and SE for Android.

In this appendix, we will do the following:

·        Download and install Ubuntu 12.04 using a virtual machine (VM)

·        Enhance our VM's performance by installing the VirtualBox Extension Pack and VirtualBox Guest Additions

·        Set up a development environment appropriate for building the Linux kernel and UDOO sources

·        Install Oracle Java 6

Tip

If you already use Ubuntu Linux 12.04, you can skip to the The Build Environment section. If you intend to install Ubuntu natively (not in a VM), you should skip to the Ubuntu Linux 12.04 section and follow those directions, ignoring the VirtualBox steps.

VirtualBox

There are a number of virtualization products available for running guest operating systems, such as Ubuntu Linux, but for this setup we will use VirtualBox. VirtualBox is a widely used open source virtualization system available for Mac, Linux, Solaris, and Windows hosts (among others). It supports a variety of guest operating systems. VirtualBox also allows the use of hardware virtualization of many modern/common processor families to increase performance by providing each virtual machine its own private address space.

The VirtualBox documentation has excellent installation instructions for various platforms, and we recommend referring to these for your host platform. You can find information about installing and running VirtualBox for your host operating system athttp://www.virtualbox.org/manual/ch02.html.

Ubuntu Linux 12.04 (precise pangolin)

To install Ubuntu Linux 12.04, you will first need to download an appropriate distribution image. These can be found at http://releases.ubuntu.com/12.04/. While there are a number of acceptable images there, we will install the 64-bit desktop version of the distribution—http://releases.ubuntu.com/12.04/ubuntu-12.04.5-desktop-amd64.iso. The host machine we're using in this example is a 64-bit Macbook Pro running OS X 10.9.2, so we're targeting a 64-bit guest as well. If you have a 32-bit machine, the basic mechanics of what we cover will be the same; only a few details will be different, so we will leave those for you to discover and resolve.

Launch VirtualBox on your host, wait for the VM Manager window to appear, and perform the following steps:

1.    Click on New.

2.    For the Name and Operating System settings, make the following selections:

·        NameSE for Android Book

·        TypeLinux

·        VersionUbuntu (64 bit)

3.    Set Memory Size to a value to at least 16 GB. Anything lower than this will lead to unsuccessful builds.

4.    To set up the hard drive, select Create a virtual hard drive now. Set this value to at least 80 GB.

5.    Choose the Hard Drive File TypeVDI (VirtualBox Disk Image).

6.    Ensure storage on the physical hard drive is set to dynamically allocated.

7.    When prompted for file location and size, name the new virtual hard drive SE for Android Book, and set its size to 80 GB.

Ensure the SE for Android Book VM is selected in the left pane. Click on the green Start arrow to perform an initial launch of the VM. A dialog will appear, asking you to select a virtual optical disk file. Click on the small folder icon and locate the ubuntu-12.04.5-desktop-amd64.iso CD image you downloaded earlier. Then click on Start.

When the screen turns black and shows a keyboard image at the bottom center of the VM window, press any key to begin the Ubuntu installation. As soon as you do this, the language selection screen will appear. Choose whichever language is most appropriate for you, but for this example, we'll select English. Then select Install Ubuntu.

Sometimes, you may see an unusual-looking error printed across your VM window—something like SMBus base address uninitialized. This message is shown because VirtualBox doesn't support a particular kernel module that is loaded by default with Ubuntu 12.04. However, this will not cause any difficulty and is only a cosmetic annoyance. After a few moments, a nice GUI installation screen will appear, waiting for you to choose a language again. We'll choose English again.

On the following Preparing to install Ubuntu screen, three checklist items are shown. You should have already satisfied the first item, since your virtual drive is much larger than the minimum requirement for Ubuntu. To satisfy the others, ensure your host system is plugged in with a power supply and has an established network connection. Although this is entirely unnecessary for our purposes here, we almost always mark the Download updates while installing and Install this third-party software boxes before continuing.

On the Installation type screen, we'll take the easy path and select Erase disk and install Ubuntu. Keep in mind that this will only erase the disk of your VM's virtual hard drive and leaves your host system intact. On the Erase disk and install Ubuntu screen, your virtual hard drive should already be selected, so you only need to click Install Now.

From this point forward in the Ubuntu installation, two separate tasks will happen simultaneously: in a background thread, the installer will prepare the virtual drive for the installation of the base system; secondly, you will configure some basic aspects of your new system. But first, you will have to identify your time zone by clicking on the appropriate point on the world map before continuing. Then identify your keyboard layout and continue.

Set up your first user account. In this case, it will be the account we used to do the work in this book, so we will enter the following information:

·        Your NameBook User

·        Your computer's nameSE-for-Android

·        Pick a usernamebookuser

·        Password fields: (whatever you prefer)

We will also select Log in automatically. While we would not normally do this for security reasons, we will do it in our local VM for convenience; but you may protect this account in whichever way you prefer.

Once the Ubuntu installation is complete, a dialog asking you to restart the computer will appear. Click the Restart now button, and after a few moments, a terminal prompt will inform you to remove all installation media and press Enter. To remove the virtual installation CD, go to Devices | CD/DVD Devices | Remove disk from virtual drive using the VirtualBox menu bar. Then press Enter to restart the VM, but interrupt the boot process by closing the VM window. It will ask you if you want to power off the machine. Just click OK.

VirtualBox extension pack and guest additions

To get the best performance from your guest Ubuntu VM and access to the virtual USB devices necessary for working with the UDOO, you will need to install the VirtualBox extension pack and guest additions.

VirtualBox extension pack

Download the extension pack from the VirtualBox website, at http://www.virtualbox.org/wiki/Downloads. There will be a download link there intended for All supported platforms. Once this file is downloaded, you'll need to install it. This process is different for each type of host system, but it is very straightforward. For Linux and Mac OS X hosts, simply double-clicking on the downloaded extension pack file will do the trick. For Windows systems, you will need to run the installer you've downloaded.

VirtualBox guest additions

Once you've completed the installation of the extension pack, boot your Ubuntu Linux 12.04 VM from VirtualBox by selecting the VM from the left pane and clicking on Start in the toolbar. Once your Ubuntu desktop is active, you'll notice it does not fit into your VM window. Resize the VM window to make it larger, and the VM screen will remain the same size. This, among other performance issues, will be resolved by installing the VirtualBox guest additions. You may also see a window open on your virtual desktop indicating a new version of Ubuntu is available. Do not upgrade; just close that window.

Using the VirtualBox menu bar, go to Devices | Insert Guest Additions CD Image…. Shortly afterward, a dialog will appear, asking whether you want to run the software on the new media you just inserted. Click the Run button. You will then need to authenticateyour user by entering your user's password (which you entered during setup). Once the user is authenticated, a script will automatically build and update several kernel modules. Once the script completes, reboot the VM by clicking on the gear in the top-right corner of the screen, selecting Shutdown…, and clicking on Restart in the dialog that follows.

When the VM reboots, the first thing you should notice is that the VM screen now fits into the VM window. Moreover, if you resize the VM window, the VM screen resizes with it. This is the simplest way to determine you've successfully installed the VirtualBox guest additions.

Save time with shared folders

Another thing you can do to boost your aggregate performance while developing images for the UDOO is to set up shared folders between your host system and your Ubuntu Linux guest system. In this way, once you've built a new SD card image for the UDOO, you can make the image directly available to the host through the shared folder. The host can then execute the long-running commands to flash the SD card without adding time to the process by slowing down access to your host's card reader through the virtualization layer. In the case of the system we're using to write this book, there is a savings of around 10 minutes per image flashed.

To set up a shared folder, you must begin with the VirtualBox Manager open and your Ubuntu VM powered off. Click the Settings toolbar icon. Then select the Shared Folders tab of the Settings dialog that opens. Click the Add Shared Folder icon to the right. Enter Folder Path to a folder on your host that you want to share. In our case, we created a new folder called vbox_share to share with our VM guest. VirtualBox will generate Folder Name, but make sure you select Auto-mount before clicking OK. When you boot your Ubuntu VM from now on, the shared folder will be accessible in your guest VM as /media/sf_<folder_name>. However, if you attempt to list the files in that directory from your guest, you will likely be denied. To gain full access to this folder (as in read-and-write access) for our bookuser, we'll need to add that UID to the vboxsf group:

$ sudo usermod -a -G vboxsf bookuser

Log out and log in to your guest again or restart the guest VM to complete the process.

The build environment

To prepare our system to build the Linux kernel, Android, and Android applications, we need to install and set up some key pieces of software. Click the Ubuntu dashboard icon at the top of the launch bar on the left of your screen. In the search bar that appears, type term and press Enter. A terminal window will open. Then execute the following commands:

$ sudo apt-get update

$ sudo apt-get install apt-file git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev ia32-libs dialog liblzo2-dev libxml2-utils minicom

Type y and press Enter when asked whether you want to continue.

Oracle Java 6

Download the most recent Java 6 SE Development Kit (version 6u45) from the Oracle Java archive website, at http://www.oracle.com/technetwork/java/javase/archive-139210.html. You'll need the jdk-6u45-linux-x64.bin version to satisfy Google's target development environment. Once it is downloaded, execute the following commands to install the Java 6 JDK:

$ chmod a+x jdk-6u45-linux-x64.bin

$ sudo mkdir -p /usr/lib/jvm

$ sudo mv jdk-6u45-linux-x64.bin /usr/lib/jvm/

$ cd /usr/lib/jvm/

$ sudo ./jdk-6u45-linux-x64.bin

$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_45/bin/java" 1

$ sudo update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk1.6.0_45/bin/jar" 1

$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_45/bin/javac" 1

$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.6.0_45/bin/javaws" 1

$ sudo update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk1.6.0_35/bin/jar" 1

$ sudo update-alternatives --install "/usr/bin/javadoc" "javadoc" "/usr/lib/jvm/jdk1.6.0_45/bin/javadoc" 1

$ sudo update-alternatives --install "/usr/bin/jarsigner" "jarsigner" "/usr/lib/jvm/jdk1.6.0_45/bin/jarsigner" 1

$ sudo update-alternatives --install "/usr/bin/javah" "javah" "/usr/lib/jvm/jdk1.6.0_45/bin/javah" 1

$ sudo rm jdk-6u45-linux-x64.bin

Summary

In this appendix, we discussed Google's target development environment for Android and showed how to create a compatible environment, potentially in a virtual machine. You should feel free to modify other elements of your system, but having the elements of this appendix installed will provide you with the minimally viable environment necessary to perform all the steps outlined in Chapter 4Installation on the UDOO, and beyond.