[Sony Xperia ZL] motoridersd:
I've spent some time in the last couple of days trying to set up a Linux box to compile my own Cyanogenmod ROM and have run into some issues that are not mentioned in the official CM Wiki (http://wiki.cyanogenmod.org/w/Build_for_odin). You can start there, but to make things easier, I wanted to put everything in ONE single post so others don't have to go looking around different sources. Feel free to make any comments and suggestions.

This can easily be moved to a wiki if that's deemed more appropriate, but I just wanted to put it somewhere.

First, get yourself a 64 bit PC or VM (you can use Virtualbox) and install Ubuntu 12.04 LTS. You can install the latest version, but LTS builds have longer support and are more stable. If you're only using it for building ROMs, it's nice to be more consistent. Make sure you have at LEAST 35 GB, but the more the better. 100 GB are best if you have the space.

Once you have Ubuntu up and running, fire up a terminal, and get ready to type (or copy and paste). These steps are taken from Here

You need java, and you need the RIGHT java environment. We must get rid of any undesired ones that come with Ubuntu. These will be reinstalled if you do an update or install updates, so always make sure you are running the right version by default.

Remove unwanted JREs

sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*

Now we add a repository that contains the proper Sun Java 1.6 JRE (this repository works as of 7/30/13, but it might disappear due to Oracle licensing claims)

sudo add-apt-repository ppa:webupd8team/java

Once the PPA is added, Ubuntu will know where to install the correct packages from. Next we copy and paste:

sudo apt-get update && sudo apt-get install oracle-java6-installer

The above command will update the repository database and then install the JRE. Follow the onscreen prompts to accept the license agreement, and when done, you should be able to confirm you have the right version by typing

java -version

And it should return something like this:

java version “1.6.0_37″

Java(TM) SE Runtime Environment (build 1.6.0_37-b06)

Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01, mixed mode)

Now we install the packages needed to build and compile properly. Copy and paste this whole line:

sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python lzop

This might take a while, since the package manager has to download and install all those packages.

When done, we set up 'repo' which is the script in charge of downloading all the source code and files you will need to build your ROM. Copy and paste this into your terminal:

mkdir ~/bin && curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo && chmod a+x ~/bin/repo

Use your favorite text editor to add the new folder created above into your path (so you can run repo from anywhere). I use vi, but nano is more friendly:

sudo nano ~/.bashrc

At the very bottom, add this

export PATH=~/bin:$PATH

Save the file, exit the text editor, and then run

source ~/.bashrc

In the terminal, create a folder where you would like to have your code stored. If you have more than one drive, pick the fastest one. Avoid USB external drives, SSD is best. The official CM guide suggests:

mkdir ~/android/system

Go into the newly created folder and initialize your repo

cd ~/android/system
repo init -u git://github.com/CyanogenMod/android.git -b cm-10.2

In the line above, you can pick 10.1 if you want to build Jelly Bean 4.2.2 or 10.2 for Jelly Bean 4.3.

Once the repo is initialized, it's time to have it pull EVERYTHING. This next command will take a while, depending on your internet connection:

repo sync

You can run the 'repo sync' command as often as you want. Doing this will get the latest version of any code on the CM repository, so make sure you do it often.

When you have all the data synced up and downloaded to your build box, you need to do some Odin (code name for the Xperia ZL) specific steps. These are taken from the CM Wiki

You need to get the pre-built apps, this should only need to be done once.

cd ~/android/system/vendor/cm
./get-prebuilts

Now we get the build environment ready:

source build/envsetup.sh
breakfast odin

You will notice that you will get some errors regarding missing files in the vendor/ directory. The CM guide tells you to pull the ZL blobs through USB, but thankfully, these files are hosted on the internet. To get them, once the 'breakfast' command is done, fire up your favorite text editor:

nano ~/home/system/.repo/local_manifests/roomservice.xml

Your XML file will look like this

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<project name="CyanogenMod/android_device_sony_odin" path="device/sony/odin" remote="github" />
<project name="CyanogenMod/android_device_sony_common" path="device/sony/common" remote="github" />
<project name="CyanogenMod/android_device_sony_qcom-common" path="device/sony/qcom-common" remote="github" />
<project name="CyanogenMod/android_device_sony_fusion3-common" path="device/sony/fusion3-common" remote="github" />
<project name="CyanogenMod/android_kernel_sony_apq8064" path="kernel/sony/apq8064" remote="github" />
<project name="CyanogenMod/android_packages_apps_FMRadio" path="packages/apps/FmRadio" remote="github" />
<project name="CyanogenMod/android_hardware_sony_DASH" path="hardware/sony/DASH" remote="github" />
</manifest>

After the last project line, you will add the following (add it before the </manifest> line

<project name="TheMuppets/proprietary_vendor_sony" path="vendor/sony" remote="github" />

So it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<project name="CyanogenMod/android_device_sony_odin" path="device/sony/odin" remote="github" />
<project name="CyanogenMod/android_device_sony_common" path="device/sony/common" remote="github" />
<project name="CyanogenMod/android_device_sony_qcom-common" path="device/sony/qcom-common" remote="github" />
<project name="CyanogenMod/android_device_sony_fusion3-common" path="device/sony/fusion3-common" remote="github" />
<project name="CyanogenMod/android_kernel_sony_apq8064" path="kernel/sony/apq8064" remote="github" />
<project name="CyanogenMod/android_packages_apps_FMRadio" path="packages/apps/FmRadio" remote="github" />
<project name="CyanogenMod/android_hardware_sony_DASH" path="hardware/sony/DASH" remote="github" />
<project name="TheMuppets/proprietary_vendor_sony" path="vendor/sony" remote="github" />
</manifest>

Save the file, and run a repo sync again

repo sync

Now execute the breakfast command again. You don't need to execute the 'source build/envsetup.sh' command unless you open a new terminal window.

breakfast odin

Turn on caching

export USE_CCACHE=1

And you're ready to build!

brunch odin

When the build completes, cd into the $OUT folder

cd $OUT

And you will have a zip file ready to flash. It will be called something like this

cm-10.2-20130731-UNOFFICIAL-odin.zip

and you will have a

recovery.img

file that you can use to flash to your bootloader. If you already have a CM build or a working recovery, you can skip that part and just flash the zip.

If you get any build errors, check the CM wiki. A lot of errors are due to running out of disk space, hence why it's important to give your VM a lot of it.

That's it! You have built a ROM!