[HTC Desire C] <CyberAnarchy>:
Okay so there are several guides on XDA on how to compile Roms from source etc. Since the development for this device is growing... I want to encourage other members to contribute to development and teach those who don't know yet about compiling. This is an extremely indepth tutorial intended not only to teach basics...but also to clear up working of some stuff.

THIS IS A 5 PART TUTORIAL COVERED IN 5 POSTS.

So without further ado.......

################

THE BASIC STUFF

################

This will cover all the basics of android development...which is I think common to most other tutorials. This part will teach you how to compile a ROM from source.

First we select an OS. You can use gentoo or mint

But I prefer to use Ubuntu 12.04 64 bit.(OUTDATED)

Note: YOU CANNOT COMPILE ROMS ON 32 BIT ONLY KERNELS.

So let's download Ubuntu 16.04 (Xenial Xereus) image

http://releases.ubuntu.com/16.04/

Now that you have downloaded it.. You can set it up as a virtual machine in virtual box or dual boot it. You may also use it as primary os if you want.

Now let's set up the build environment.

Open up the terminal

Type this in the terminal window:

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

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

For Marshmallow and up replace openjdk7 with 8...

Now you need to install the android SDK

Get it here :http://developer.android.com/sdk/index.html

Extract this in the home directory

Now in the terminal window type this:

gedit .bashrc

A text editor will pop up. Add these lines at the very end:

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

Now again in terminal window type:

gedit .profile

Add this:

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

The SDK is now installed!

Now before we install the repo tool

Run this in terminal window

gksudo gedit /etc/udev/rules.d/51-android.rules

and add these lines:

#Acer
SUBSYSTEM=="usb", ATTR{idVendor}=="0502", MODE="0666"

#ASUS
SUBSYSTEM=="usb", ATTR{idVendor}=="0b05", MODE="0666"

#Dell
SUBSYSTEM=="usb", ATTR{idVendor}=="413c", MODE="0666"

#Foxconn
SUBSYSTEM=="usb", ATTR{idVendor}=="0489", MODE="0666"

#Garmin-Asus
SUBSYSTEM=="usb", ATTR{idVendor}=="091E", MODE="0666"

#Google
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666"

#HTC
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666"

#Huawei
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", MODE="0666"

#K-Touch
SUBSYSTEM=="usb", ATTR{idVendor}=="24e3", MODE="0666"

#KT Tech
SUBSYSTEM=="usb", ATTR{idVendor}=="2116", MODE="0666"

#Kyocera
SUBSYSTEM=="usb", ATTR{idVendor}=="0482", MODE="0666"

#Lenevo
SUBSYSTEM=="usb", ATTR{idVendor}=="17EF", MODE="0666"

#LG
SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666"

#Motorola
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666"

#NEC
SUBSYSTEM=="usb", ATTR{idVendor}=="0409", MODE="0666"

#Nook
SUBSYSTEM=="usb", ATTR{idVendor}=="2080", MODE="0666"

#Nvidia
SUBSYSTEM=="usb", ATTR{idVendor}=="0955", MODE="0666"

#OTGV
SUBSYSTEM=="usb", ATTR{idVendor}=="2257", MODE="0666"

#Pantech
SUBSYSTEM=="usb", ATTR{idVendor}=="10A9", MODE="0666"

#Philips
SUBSYSTEM=="usb", ATTR{idVendor}=="0471", MODE="0666"

#PMC-Sierra
SUBSYSTEM=="usb", ATTR{idVendor}=="04da", MODE="0666"

#Qualcomm
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666"

#SK Telesys
SUBSYSTEM=="usb", ATTR{idVendor}=="1f53", MODE="0666"

#Samsung
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666"

#Sharp
SUBSYSTEM=="usb", ATTR{idVendor}=="04dd", MODE="0666"

#Sony Ericsson
SUBSYSTEM=="usb", ATTR{idVendor}=="0fce", MODE="0666"

#Toshiba
SUBSYSTEM=="usb", ATTR{idVendor}=="0930", MODE="0666"

#ZTE
SUBSYSTEM=="usb", ATTR{idVendor}=="19D2", MODE="0666"

Save it and run:

sudo chmod a+r /etc/udev/rules.d/51-android.rules

What we just did was Adding vendor id's for USB connectivity.

Whew ..... That was quite long.... Now let's be back to business.

Installing the repo tool:

To manage the git repos and to use them for our various needs like initializing them and syncing we use a tool made by Google called the repo tool.

Type this in terminal window:

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

Now you are all geared up for compiling roms !

For demonstration in this tut we will take the device as golfu and our source path as:

/home/user/android/system

So make the source folder by:

cd ~/
mkdir android
cd android
mkdir system
cd system

Now let's initialize the repo..... Let's decide which one to sync.... I'll use cm11 for this tutorial.

When you are in source folder type in terminal:

repo init -u *git link to source* -b *branch name*

The repo init link can generally be found in the manifest of the ROM on github.

So for cm 11 it should be like this :

repo init -u git://github.com/CyanogenMod/android.git -b cm-11

Now you have successfully initialized cm11 source code in your directory!

Now you need to download the sources..... The android source code is very large and it may take a little to a looong time to download depending on your internet speed.

So when you are in your source directory:

repo sync -j#

# will be the no. Of jobs

A larger number will give better result if your internet is fast but entering an insane number won't help.

I use:

repo sync -j8

Now wait till your source is synced...long process.

After the source is downloaded you need to get the device specific parts.

You need to get the kernel source, device tree and vendor tree.

For this device you need not download the vendor tree

Download device tree as a zip from github

Extract CONTENTS to:

/home/user/android/system/device/htc/golfu

Create folders if not present.

Download the kernel source from github as a zip

Extract CONTENTS to:

/home/user/android/system/kernel/htc/golfu

Create folders if not present.

Now your source code is completely set up for compiling for our device !

Before building get the prebuilts:

cd /home/user/android/system/vendor/cm
. get-prebuilts.sh

Set up for building:

Type this in terminal

. build/envsetup.sh

Do this every time before building

And now finally start building!!

Type this in terminal to start building:

brunch cm_devicename-userdebug -jx+1

Where x is number of cores. My laptop has 4 cores.

So for golfu it should be :

brunch cm_golfu-userdebug -j5

Wait for it to complete building.

After it is done .... Your build can be found at

/home/user/android/system/out/target/product/golfu.

It will look like : cm-11-YYYYMMDD-UNOFFICIAL.zip

CONGRATULATIONS! You have built your very own ROM

Remember to make clean before every build!

This is the end of part one of series.

Please note, if by any chance there is a problem of java, python, maven, git etc.. not installed:

sudo apt-get install neededthing