[AT&T Samsung Galaxy Note II] AzraelsKiss:
How to build Dirty Unicorns

I personally use LMDE 2 "Betsy" for my build rig, but I would recommend Ubuntu 14.04 LTS because it's stable, it has a large installed base and it's a long term support release. Either way, these instructions should be nearly the same. If installing within VirtualBox (or VMware, because the process would be quite similar), make sure to select Linux as the type and Debian (64 bit), or Ubuntu (64 bit) for Ubuntu 14.04 LTS, as the version. You will also want to set the memory size to at least 4 GB, but if you have more than 8 GB of physical RAM, I would recommend a setting of half your physical RAM (i.e. if your system has 16 GB of physical RAM, set your virtual machine to use 8 GB). Finally, make sure you have at least 150 GB available on the hard drive (I tried to use 100 GB once, but there wasn't quite enough room to hold all the source files and all the build files while compiling). If you just can't spare the HDD space, you'll have to find unsupported ways to limit the necessary space for source files on your own.

Install the JDK

Lollipop requires Java 7 to build, so we need to install the proper JDK:

$ sudo apt-get update
$ sudo apt-get install openjdk-7-jdk

Install the required packages

Ubuntu doesn't preinstall all the packages we need, so we'll do that now:

$ sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

Make the required directories

There are two directories we need to make for the build environment:

$ mkdir -p ~/bin
$ mkdir -p ~/du

Add bin to PATH

Make sure ~/bin is added to PATH:

$ PATH=~/bin:$PATH

Get repo tool

We need to download and make executable the repo tool:

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

Configure git

This is where we add our information to git:

$ git config --global user.email "your@email.address"
$ git config --global user.name "Your Name"
$ git config --global gerrit.dirtyunicorns.com.username "username used on gerrit.dirtyunicorns.com"
$ git config --global gerrit.dirtyunicorns.com.email "email address used on gerrit.dirtyunicorns.com""
$ ssh-keygen -t rsa -C "your@email.com"

Now you will need to add your SSH public key to http://gerrit.dirtyunicorns.com/ so that you can submit patches in the future.

Get the code

First, we need to download the SDK from http://developer.android.com/sdk/index.html

Extract the SDK into your home directory and rename it android-sdk

Add the following to the bottom of your .bashrc file:

# Android tools
export PATH=${PATH}:~/android-sdk/tools
export PATH=${PATH}:~/android-sdk/platform-tools
export PATH=${PATH}:~/bin

Add the following to the bottom of your .profile file:

PATH="$HOME/android-sdk/tools:$HOME/android-sdk/platform-tools:$PATH"

Then type the following within terminal:

$ android

Make sure Updates/New and Installed are ticked and click the install button.

Now we need to initialize the Dirty Unicorn repository.

Change the directory to the du directory:

$ cd ~/du

Nexus devices will need:

$ repo init -u https://github.com/DirtyUnicorns/android_manifest.git -b lollipop

Non-nexus devices will need:

$ repo init -u https://github.com/DirtyUnicorns/android_manifest.git -b lollipop-caf

Finally we download the source code:

$ repo sync

Setting up ccache

ccache will allow future builds to process faster:

$ echo "export USE_CCACHE=1" >> ~/.bashrc
$ ~/du/prebuilts/misc/linux-x86/ccache/ccache -M 25G

You should make your ccache at least 10G, but a little more won't hurt and if you build for more than one device, you'll definitely need more.

Building the ROM

These are the commands you will enter every time you wish to build. These commands will update the code, ready the build and finally start the build:

$ repo sync
$ . build/envsetup.sh
$ lunch (Pick your device from the list)
$ make -j? bacon

Replace ? with how ever many threads your processor is capable of processing at once +1 (i.e. Intel Core i7 Quad has 4 cores with hyperthreading allowing 2 threads per core, or 8 simultanious threads, so you would use make -j9 bacon. This allows all 8 virtual cores to be used plus one queued thread, ready for processing.)

If everything goes okay, the build will successfully complete and the final zip will be located at ~/du/out/target/product/<device>/DU_<device>_<android version>_<date>-<time>.<DU version>-UNOFFICIAL.zip ready for flashing. If something goes wrong, the build will error out with an error message that hopefully helps you figure out what went wrong, so that you may fix it and try again.

Finally, you'll want to use the commands make clean or make clobber every once in a while before or after you build to clean up your build environment. This will clean up the various build files that are created during the build process. Using make clean or make clobber is similar in nature to doing a clean flash over a dirty flash... Although the build times are faster if you don't do a make clean or make clobber before the build, there's a chance that an old file may gum up the works when it's not replaced by a newer version when necessary. I've gotten into the habit of using make clobber after a build and make clean before, but I tend to like redundancy. Also... Because these commands will delete the entire contents of the out directory, including the zip file you just created, don't issue the commands until after you've copied the ROM zip to another location, such as your device.

If your device is not listed in the lunch menu, you will need to port DU for your ROM with a compatible device tree. A simple Google search should be able to help get you started. You may also find someone to assist you in the DU G+ community, but you should at least take the initiative to try to figure some things out on your own and have your device tree started before enlisting their assistance.

Further information

:

https://github.com/DirtyUnicorns/android_manifest

https://source.android.com/source/initializing.html

http://docs.omnirom.org/Setting_Up_A_Compile_Environment

https://plus.google.com/communities/109738128866939227235