[Galaxy Ace S5830 General] CallMeVentus:
Alright, now you've built AOSP and CM7 and you love it, what next?

Ice Cream Sandwich *insert holy choir here*

Requirements (they are much more different now):

A computer that's capable of 64-bit

A dual-core processor of a speed of at least 2.2Ghz (Intel Xeon/Core i7 recommended)

Either Ubuntu 10.04 LTS

64-bit

(later versions have experimental support) but if you're using a later version that's fine.

Or Mac OSX 10.6

At least 8GB of RAM and

10~GB swap maybe?

(Otherwise you could have 4Gb of RAM and ~20GB swap this time)

At least a 70GB partition for Ubuntu (to make sure there is space for compiling + installing required stuff)

Well, here are the steps to build it:

Instructions (Taken from http://source.android.com/source/initializing.html & http://wiki.cyanogenmod.com/wiki/Android_SDK_Emulator:_Compile_CyanogenMod_(Linux)):

---------ONLY FOR UBUNTU 10.10--12.04---------

Chapter 1: Initializing a Build Environment

This section describes how to set up your local work environment, how to use Repo to get the Android files, and how to build the files on your machine. To build the Android source files, you will need to use Linux or Mac OS. Building under Windows is not currently supported.

Note: The source download is approximately 6GB in size. You will need 25GB free to complete a single build, and up to 90GB (or more) for a full set of builds.

Section 1 (Linux/Ubuntu): Setting up a Linux build environment

The Android build is routinely tested in house on recent versions of Ubuntu LTS (10.04), but most distributions should have the required build tools available. Reports of successes or failures on other distributions are welcome.

Note: It is also

possible to build Android in a virtual machine

. If you are running Linux in a virtual machine, you will need

at least 16GB of RAM/swap and 30GB or more of disk space in order to build the Android tree

.

In general you will need:

Python 2.5 -- 2.7.

GNU Make 3.81 -- 3.82.

JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older.

Git 1.7 or newer.

Detailed instructions for Ubuntu 10.04+ follow.

Step 1: Installing the JDK

The Sun JDK is no longer in Ubuntu's main package repository. In order to download it, you need to add the appropriate repository and indicate to the system which JDK should be used.

To download Java 6, do this:

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

Note: The lunch command in the build step will ensure that the Sun JDK is used instead of any previously installed JDK.

Alternatively you can follow eoghan2t7's instructions:

Or bs828's instructions:

Step 2: Installing required packages (Ubuntu 10.04 -- 11.10)

You will need a 64-bit version of Ubuntu. Ubuntu 10.04 is recommended. Building using a newer version of Ubuntu is currently only experimentally supported and is not guaranteed to work on Git branches other than master (http://github.com/android).

To install the required packages, do this:

$ 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

---------ONLY FOR UBUNTU 10.10--11.10---------

For Ubuntu 10.10 users, do this as well:

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

Note: This is used to avoid a compile error with libGL later on.

For Ubuntu 11.10 users, do this:

$ sudo apt-get install libx11-dev:i386

---------END FOR UBUNTU 10.10--11.10---------

----------ONLY FOR UBUNTU 12.04----------

Step 2: Installing required packages (Ubuntu 12.04)

Building on Ubuntu 12.04 is currently only experimentally supported and is not guaranteed to work on branches other than master.

To install the required packages, do this:

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

---------END FOR UBUNTU 10.10--12.04---------

I won't do MacOSX for ICS, mainly because it has a very unstable success chance of compilation.

Your build environment is good to go! Proceed to

Chapter 2: Downloading the Source Tree

Section 1: Repo

Repo is a tool that makes it easier to work with Git in the context of Android.

It is also a tool that allows you to download source files from Android easily.

Step 1: Installing Repo

To install, initialize, and configure Repo, follow these steps:

Make sure you have a bin/ directory in your home directory, and that it is included in your path:

$ mkdir ~/bin
$ PATH=~/bin:$PATH

Download the Repo script and ensure it is executable:

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

For version 1.15, the SHA-1 checksum for repo is 8eb56d98b36d615c3efec51868e87bebe757feb1

For version 1.16, the SHA-1 checksum for repo is f3bfa7fd2d0a44aa40579bb0242cc20df37b5e17

Step 2: Initializing a Repo client

After installing Repo, set up your client to access the android source repository:

Create an empty directory to hold your working files. If you're using MacOS, this has to be on a case-sensitive filesystem. Give it any name you like:

$ mkdir I_HATE_STEVE
$ cd I_HATE_STEVE

Run

repo init

to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.

For AOSP:

$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.1.1_r1

or

$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.1.1_r2

or

$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.1.1_r3

or even

$ repo init -u https://android.googlesource.com/platform/manifest -b ics-plus-aosp

For CM9:

$ repo init -u git://github.com/CyanogenMod/android.git -b ics

When prompted, please configure Repo with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account. Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions.

A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a .repo directory where files such as the manifest will be kept.

Step 3: Getting the files

To pull down files to your working directory from the repositories as specified in the default manifest, run

$ repo sync

The Android source files will be located in your working directory under their project names. The initial sync operation will take an hour or more to complete, depending on your Internet bandwidth.

Note: If you initialize your repo on your root area for all projects, the time for downloading will decrease ;)

If you haven't set up ccache now, now is a good time to set it up.

Chapter 2.5 (AOSP only): Downloading the various device specific configurations from GitHub

Now that you have a full copy of AOSP, you will realise that inside your working directory/device you will only see only a few device configurations. That's because AOSP only supports those devices and you will need to manually download other devices for use with AOSP.

You can either adapt from MaclawStudios' repo of the Galaxy Gio: https://github.com/MaclawStudios/android_device_samsung_gio

Or make an ICS device config yourself.

Meanwhile PabloPL has made an ICS branch here, but currently nothing is being worked on, as it seems.

Chapter 3: Building the System

The basic sequence of build commands is as follows:

Step 1: Initialize

Initialize the environment with the envsetup.sh script. Note that replacing "source" with a single dot saves a few characters, and the short form is more commonly used in documentation.

Either:

$ source build/envsetup.sh

or

$ . build/envsetup.sh

Step 2: Choose a target

Choose which target to build with lunch. The exact configuration can be passed as an argument, e.g.

$ lunch full-eng

The example above refers to a complete build for the emulator, with all debugging enabled.

If run with no arguments lunch will prompt you to choose a target from the menu.

Step 3: Build the Code

Build everything with make. GNU make can handle parallel tasks with a -jN argument, and it's common to use a number of tasks N that's between 1 and 2 times the number of hardware threads on the computer being used for the build. E.g. on a dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), the fastest builds are made with commands between make -j16 and make -j32.

If you are using a dual-core computer do either of these:

make -j2

or

make -j4

It is usually recommended that you make the -jN amount twice the number of cores your processor has.

Therefore if you have a quad-core processor do this:

make -j4

or

make -j8

There are different ways to run make:

$ make clean

or

$ make clobber

Cleans the compile directory and deletes all compiled files.

$ make update-api

Makes part of the framework, usually used to update the API.

make otapackage

Makes a flashable .zip file, as otapackage = Over The Air package.

make (app name, like framework-res)

Makes the specified app and the .apk will be compiled in the output directory.

Once you finish make, you are done! Congratulations!

Chapter 4: Troubleshooting Common Build Errors

Sometimes, things don't go as planned such as unexpected build errors. Here are some solutions to common problems:

Section 1: Wrong Java Version

If you are attempting to build froyo or earlier with Java 1.6, or gingerbread or later with Java 1.5, make will abort with a message such as

************************************************************
You are attempting to build with the incorrect version
of java.

Your version is: WRONG_VERSION.
The correct version is: RIGHT_VERSION.

Please follow the machine setup instructions at
https://source.android.com/source/download.html
************************************************************

This may be caused by:

failing to install the correct JDK as specified on the Initializing chapter. Building Android requires Sun JDK 5 or 6 depending on which release you are building.

another JDK that you previously installed appearing in your path. You can remove the offending JDK from your path with:

$ export PATH=${PATH/\/path\/to\/jdk\/dir:/}

Section 2: Python Version 3

Repo is built on particular functionality from Python 2.x and is unfortunately incompatible with Python 3. In order to use repo, please install Python 2.x:

$ apt-get install python

Optional Step: Setting up ccache

You can optionally tell the build to use the ccache compilation tool. Ccache acts as a compiler cache that can be used to speed-up rebuilds. This works very well if you do "make clean" often, or if you frequently switch between different build products.

Put the following in your .bashrc or equivalent.

$ export USE_CCACHE=1

By default the cache will be stored in ~/.ccache. If your home directory is on NFS or some other non-local filesystem, you will want to specify the directory in your .bashrc as well.

$ export CCACHE_DIR=

The suggested cache size is 50-100GB. You will need to run the following command once you have downloaded the source code, if you use CCache.

$ prebuilt/linux-x86/ccache/ccache -M 50G

Optional Step: Using a separate output directory

By default, the output of each build is stored in the out/ subdirectory of the matching source tree.

On some machines with multiple storage devices, builds are faster when storing the source files and the output on separate volumes. For additional performance, the output can be stored on a filesystem optimized for speed instead of crash robustness, since all files can be re-generated in case of filesystem corruption.

To set this up, export the OUT_DIR_COMMON_BASE variable to point to the location where your output directories will be stored.

export OUT_DIR_COMMON_BASE=

The output directory for each separate source tree will be named after the directory holding the source tree.

For instance, if you have source trees as /source/master1 and /source/master2 and OUT_DIR_COMMON_BASE is set to /output, the output directories will be /output/master1 and /output/master2.

It's important in that case to not have multiple source trees stored in directories that have the same name, as those would end up sharing an output directory, with unpredictable results.

This is only supported on branches newer than 4.0.x (IceCreamSandwich).