[Galaxy S 4 General] x10forevers:
This is the thread for the tutorial about how to build android from source and it is simplified version of what google described Here and also you can post your build errors here and I will try to solve it if I can.

You should have some basic knowledge about Ubuntu system and how to work with it though if you don't understand something you can always ask in this thread.

I am starting this thread by requests I have got from this device's user though I don't have device, this process is fairly common for all devices and as you all know I have build MoKee Open source for i9500.

Let's start with tutorial :

Requirement :

You will need Ubuntu 64-bit environment running on your computer on either virtual machine or either as a separate OS

Some knowledge about repo, java, language C/C++, Shell and basic command-prompt

Lots of patience

A good internet connection (Don't do this if you have less than 512kb/s internet speed otherwise it will take forever to finish this process)

A minimum of 80GB of space on your ubuntu partition (Single build)

1. Installing required package for android building

Java JDK6 or later version

sudo apt-get install openjdk-6-jdk

Install Python

sudo apt-get install python

Install android sdk and sdk tools

Download android sdk from: http://developer.android.com/sdk/index.html

Extract it to your home directory and rename it to android-sdk

At home press ctrl+h to see hidden files and folder

Open .bashrc file with text editor

Add following lines at the end of it

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

Go to your home folder and open .profile file with text editor

Add following lines at the bottom of that file.

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

Now you have successfully install android-sdk

To check open new terminal and type android and you will see android-sdk UI

Installing other required libs and package for build

For all ubuntu variant

sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \ libxml2-utils xsltproc

For Ubuntu 10.10 only

sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so

For ubuntu 11.10 only

sudo apt-get install libx11-dev:i386

For ubuntu 12.10 only

sudo apt-get install git gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev x11proto-core-dev \
libx11-dev libreadline6-dev libgl1-mesa-glx \
libgl1-mesa-dev g++-multilib mingw32 tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

For Ubuntu 13.04 and 13.10 only

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

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

Now we have to configure USB for all devices

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

That will open a file named 51-android.rules, Copy paste following usb configuration to that file and save it and close it

#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"

Now execute that file doing following command

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

2. Setting up Repo Environment

Install Repo :

Open Terminal and run following commands one by one

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

Initialize Repo:

Here Working_Directory means folder to which you want to start your project (Either CM or Paranoid or Carbon or PAC-man or AOKP), you can give any name you want

mkdir Working_Directory
cd Working_Directory

Source specific repo commands :

For Example :

AOSP - 4.4.2
repo init -u https://android.googlesource.com/platform/manifest -b android-4.4.2_r1

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

For MoKee
repo init -u https://github.com/MoKee/android.git -b kk_mkt

Now Sync Repo

Repo sync will download almost 6 to 12 GiB of sources, So it will take a while, depending on your internet connection

repo sync

== Device specific configuration for I9500 in post 2 ==