How To Build LineageOS For Barnes & Noble Nook Color ("encore")

Restored from the LineageOS (formerly CyanogenMod) Wiki. Some links below will no longer work, and there are some references to "cm" and "cyanogenmod" which should now refer to "los", "lineage" or "LineageOS"



Introduction

These instructions will hopefully assist you to start with a stock Nook Color, unlock the bootloader (if necessary), and then download the required tools as well as the very latest source code for LineageOS (based on Google’s Android operating system). Using these, you can build both LineageOS and LineageOS Recovery image from source code, and then install them both to your device.

It is difficult to say how much experience is necessary to follow these instructions. While this guide is certainly not for the very very very uninitiated, these steps shouldn’t require a PhD in software development either. Some readers will have no difficulty and breeze through the steps easily. Others may struggle over the most basic operation. Because people’s experiences, backgrounds, and intuitions differ, it may be a good idea to read through just to ascertain whether you feel comfortable or are getting over your head.

Remember, you assume all risk of trying this, but you will reap the rewards! It’s pretty satisfying to boot into a fresh operating system you baked at home :) And once you’re an Android-building ninja, there will be no more need to wait for “nightly” builds from anyone. You will have at your fingertips the skills to build a full operating system from code to a running device, whenever you want. Where you go from there-- maybe you’ll add a feature, fix a bug, add a translation, or use what you’ve learned to build a new app or port to a new device-- or maybe you’ll never build again-- it’s all really up to you.

What you’ll need

If you are not accustomed to using Linux-- this is an excellent chance to learn. It’s free-- just download and run a virtual machine (VM) such as Virtualbox, then install a Linux distribution such as Ubuntu (AOSP vets Ubuntu as well). Any recent 64-bit version should work great, but the latest is recommended.

Note:

You want to use a 64-bit version of Linux. A 32-bit Linux environment will only work if you are building LineageOS 6 and older. For LineageOS 10.1, if you encounter issues with 64bit host binaries, you can set BUILD_HOST_32bit=1 in your environment. This is generally not needed, though, especially with LineageOS 10.2 and newer.

Using a VM allows Linux to run as a guest inside your host computer-- a computer in a computer, if you will. If you hate Linux for whatever reason, you can always just uninstall and delete the whole thing. (There are plenty of places to find instructions for setting up Virtualbox with Ubuntu, so I’ll leave it to you to do that.)

So let’s begin!


Build LineageOS and LineageOS Recovery

Prepare the Build Environment

Note:

You only need to do these steps the first time you build. If you previously prepared your build environment and have downloaded the LineageOS source code for another device, skip to Prepare the device-specific code.


Install the SDK

If you have not previously installed adb and fastboot, install the Android SDK. "SDK" stands for Software Developer Kit, and it includes useful tools that you can use to flash software, look at the system logs in real time, grab screenshots, and more-- all from your computer.

Helpful Tip

While the SDK contains lots of different things-- the two tools you are most interested in for building Android are adb and fastboot, located in the /platform-tools directory.

Install the Build Packages

Several "build packages" are needed to build LineageOS. You can install these using the package manager of your choice.

Helpful Tip

A package manager in Linux is a system used to install or remove software (usually originating from the Internet) on your computer. With Ubuntu, you can use the Ubuntu Software Center. Even better, you may also use the apt-get install command directly in the Terminal. (Learn more about the apt packaging tool system from Wikipedia.)

For both 32-bit & 64-bit systems, you'll need:

bc bison build-essential curl flex git gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop maven openjdk-7-jdk pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev

In addition to the above, for 64-bit systems, get these:

g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev

For Ubuntu 15.10 (wily) and newer, substitute:

For Ubuntu 16.04 (xenial) and newer, substitute (additionally see java notes below):

Java versions: Different versions of LineageOS require different versions of the JDK (Java Development Kit):

Ubuntu 16.04 (Xenial Xerus) or newer and OpenJDK: Since OpenJDK 1.7 was removed from the official Ubuntu repositories, you have a couple options:

  1. Obtain OpenJDK 1.7 from the openjdk-r PPA
  2. Enable experimental OpenJDK 1.8 support in LineageOS 13.0 (not available in earlier version). To enable OpenJDK 1.8 support, add this line to your $HOME/.bashrc file: export EXPERIMENTAL_USE_JAVA8=true.

Also see http://source.android.com/source/initializing.html which lists needed packages.

Create the directories

You will need to set up some directories in your build environment.

To create them:

$ mkdir -p ~/bin
$ mkdir -p ~/android/system

Install the repo command

Enter the following to download the "repo" binary and make it executable (runnable):

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

Put the ~/bin directory in your path of execution

In recent versions of Ubuntu, ~/bin should already be in your PATH. You can check this by opening ~/.profile with a text editor and verifying the following code exists (add it if it is missing):

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

Initialize the LineageOS source repository

Enter the following to initialize the repository:

Note: Make sure the lineage branch entered here is the one you wish to build and is supported on your device.
$ cd ~/android/system/
$ repo init -u https://github.com/LineageOS/android.git -b lineage-13.0


Download the source code

To start the download of all the source code to your computer:

$ repo sync

The LineageOS manifests include a sensible default configuration for repo, which we strongly suggest you use (i.e. don't add any options to sync). For reference, our default values are -j 4 and -c. The -j 4 part means that there will be four simultaneous threads/connections. If you experience problems syncing, you can lower this to -j 3 or -j 2. -c will ask repo to pull in only the current branch, instead of the entire LineageOS history.

Prepare to wait a long time while the source code downloads.

Helpful Tip

The repo sync command is used to update the latest source code from LineageOS and Google. Remember it, as you can do it every few days to keep your code base fresh and up-to-date.

Get prebuilt apps (CM/LOS11 and below)

Next,

$ cd ~/android/system/vendor/cm

then enter:

$ ./get-prebuilts

You won't see any confirmation- just another prompt. But this should cause some prebuilt apps to be loaded and installed into the source code. Once completed, this does not need to be done again.


Prepare the device-specific code

Helpful Tip – Errors during breakfast

Different maintainers setup their device inheritance rules differently. Some require a vendor directory to be populated before breakfast will even succeed. If you receive an error here about vendor makefiles, then jump down to the next section Extract proprietary blobs. The first portion of breakfast should have succeeded at pulling in the device tree and the extract blobs script should be available. After completing that section, you can rerun breakfast encore

After the source downloads, ensure you are in the root of the source code (cd ~/android/system), then type:

$ source build/envsetup.sh
$ breakfast encore

This will download the device specific configuration and kernel source for your device. An alternative to using the breakfast command is to build your own local manifest. To do this, you will need to locate your device on LineageOS's GitHub and list all of the repositories defined in lineage.dependencies in your local manifest.

Helpful Tip

If you want to know more about what source build/envsetup.sh does or simply want to know more about the breakfast, brunch and lunch commands, you can head over to the Envsetup help page.

Helpful Tip

Instead of typing cd ~/android/system every time you want to return back to the root of the source code, here’s a short command that will do it for you: croot. To use this command, you must first run source build/envsetup.sh from ~/android/system.

Extract proprietary blobs

Read comments on this section

Now ensure that your Nook Color is connected to your computer via the USB cable and that you are in the ~/android/system/device/bn/encore directory (you can cd ~/android/system/device/bn/encore if necessary). Then run the extract-files.sh script:

$ ./extract-files.sh

You should see the proprietary files (aka “blobs”) get pulled from the device and moved to the ~/android/system/vendor/bn directory. If you see errors about adb being unable to pull the files, adb may not be in the path of execution. If this is the case, see the adb page for suggestions for dealing with "command not found" errors.

Note:

Your device should already be running a build of LineageOS for the branch you wish to build for the extract-files.sh script to function properly.

Note:

It’s important that these proprietary files are extracted to the ~/android/system/vendor/bn directory by using the extract-files.sh script. Makefiles are generated at the same time to make sure the blobs are eventually copied to the device. Without these blobs, LineageOS may build without error, but you’ll be missing important functionality, such as graphics libraries that enable you to see anything!


Turn on caching to speed up build

You can speed up subsequent builds by adding

export USE_CCACHE=1

to your ~/.bashrc file (what's a .bashrc file?). Then, specify the amount of disk space to dedicate to ccache by typing this from the top of your Android tree:

prebuilts/misc/linux-x86/ccache/ccache -M 50G

where 50G corresponds to 50GB of cache. This only needs to be run once and the setting will be remembered. Anywhere in the range of 25GB to 100GB will result in very noticeably increased build speeds (for instance, a typical 1hr build time can be reduced to 20min). If you're only building for one device, 25GB-50GB is fine. If you plan to build for several devices that do not share the same kernel source, aim for 75GB-100GB. This space will be permanently occupied on your drive, so take this into consideration. See more information about ccache on Google's android build environment initialization page.

Helpful Tip

If you are a very active developer, working on many other projects than just Android, you might prefer to keep your Android ccache independent (because it's huge and can slow down the efficiency of ccache in your other projects). Beginning with LineageOS 12.1, you can specify environment variables for the location and size of LineageOS's ccache. Some syntax examples: export ANDROID_CCACHE_DIR="$HOME/android/.ccache" and export ANDROID_CCACHE_SIZE="50G".

Start the build

Time to start building! So now type:

$ croot
$ brunch encore

The build should begin.

Helpful Tip

If the build doesn't start, try lunch and choose your device from the menu. If that doesn't work, try breakfast and choose from the menu. The command make encore should then work.

Helpful Tip

A second, bonus tip! If you get a command not found error for croot, brunch, or lunch, be sure you’ve done the source build/envsetup.sh command in this Terminal session from the ~/android/system directory.

Helpful Tip

A third tip! If the build to fails while downloading Gello, you'll need to import a missing certificate into Maven's truststore. Detailed instructions on how to do that can be found here


If the build breaks...

ERROR: signapk.jar failed: return code 1make: *** [out/target/product/encore/lineage_encore-ota-eng.root.zip] Error 1

...you may want to make the following change to ~/android/system/build/tools/releasetools/common.py:

Search for instances of -Xmx2048m (it should appear either under OPTIONS.java_args or near usage of signapk.jar), and replace it with -Xmx1024m or -Xmx512m.

Then start the build again (with brunch).

Install the build


Assuming the build completed without error (it will be obvious when it finishes), type:

$ cd $OUT

in the same terminal window that you did the build. Here you’ll find all the files that were created. The stuff that will go in /system is in a folder called system. The stuff that will become your ramdisk is in a folder called root. And your kernel is called... kernel.

But that’s all just background info. The two files we are interested in are (1) recovery.img, which contains LineageOS Recovery, and (2) lineage-13.0-20161224-UNOFFICIAL-encore.zip, which is the LineageOS installation package.


Install LineageOS

Back to the $OUT directory on your computer-- you should see a file that looks something like:

lineage-13.0-20161224-UNOFFICIAL-encore.zip

Note:

The above file name may vary depending on the version of CM you are building. Your build may not include a version number or may identify itself as a "KANG" rather than UNOFFICIAL version. Regardless, the file name will end in .zip and should be titled similarly to official builds.

Now you can flash the cm...zip file above as usual via recovery mode. Before doing so, now is a good time to make a backup of whatever installation is currently running on the device in case something goes wrong with the flash attempt. While LineageOS Recovery doesn't have a backup feature, there are other custom recoveries available that do. You can also use something like Titanium Backup (root required) as an alternative.

Success! So....what's next?

You've done it! Welcome to the elite club of self-builders. You've built your operating system from scratch, from the ground up. You are the master/mistress of your domain... and hopefully you've learned a bit on the way and had some fun too.

Now that you've succeeded in building LineageOS for your device, here are some suggestions on what to do next.

Also, be sure to take a glance at the Dev Center on this wiki for all kinds of more detailed information about developer topics ranging from collecting logs, understanding what's in the source code directories, submitting your own contributions, porting LineageOS to new devices, and a lot more.

Congrats again!

To get assistance