As a newbie ( still remain a big newbie ) , I always had a tough time managing my ROMs and kernel projects.
I blindly followed what guides said .. and then realized how much time and energy I was wasting on downloading unnecessary $#!t from the internet as I have a very limited bandwidth and a particularly slow speed. ( around 80 kbps download speed )

While I am not a pro at this stuff, I would like to share a few tips and tricks about ROM building which will save some of your time , energy, space as well as a lot of the money while returning back to our great community out here.

After all efficiency is what matters in the end right ?

Also , understanding how the process works is more important that the process itself .

For what its worth , even a build bot can compile a ROM.. thats no biggie.

Learning how it works matters more !

Tired of waiting for that repo sync to end ?!!!

READ ON !

Prerequisites / Requirements

Some rough knowledge on compiling a ROM or experience of compiling a ROM.

So in order to use the repo tool you need to run this command at least once.

What this does is it download the repo tool from Google's source and makes it executable for your own use.

How does the repo tool work ?

The repo tool is used for downloading a bunch of remote repositories that are on the internet thru one single command :

Code:

repo sync -j4

Details , details and more details

To explain this , I will take an example of a ROM, say AOKP.

For building AOKP you need to download its source code.

AOKP ROM developers have maintained the ROM's source code in a large number of Repositories that are located at www.github.com/AOKP.

What they have done is they have organized their source code into a number of folders for and uploaded it to separate repositories online.

What this does is , it enables all the ROM developers to work on a specific part of the source on their own computers and then push the source online to remote repository online so that he can share the code with all the developers of the same ROM. ( just a basic idea. it involves a lot more including pull requests and code reviews but we will stick with this for now )

Social coding at its best.

So during the command :

Code:

repo sync -j4

What is done is the repo tool fetches all the remote repositories that the AOKP ROM devs have deemed necessary for building the ROM for a device through 4 threads.

If you have a slow internet connection then it is advised to use -j1 or -j2.
If you have a fast internet connection then you can use a -j16 or a -j32 whatever suits you the best.

Where does the repo tool take all the reference when downloading ??

The repo tool takes all the reference for the code to be downloaded from a Default.xml or a Manifest.xml.

The manifest.xml is a file which is written in xml markup and directs the repo tool to the repositories and their respective branches that need to be downloaded .

This is basically a huge list of all the repositories that need to be downloaded by the repo tool.

Where can this list of yours be found ?

Once you have initialized your repo sync which will be somewhat similar to this :

A local manifest is like a specific copy of the manifest of a particular ROM that is maintained by YOU the ROM compiler in your own computer.

This local manifest allows you to override some of the projects mentioned in the manifest and hence allows you to delete / add / modify the source code according to your preferences.

Best part about this is that every time you sync your source , even the onces mentioned in the local manifest get updated by themselves.

Hence, you dont need to keep track of all your device trees and kernel sources manually, let the repo tool do the work for you.

Let us see how this wonderful tool works :

Go to the folder where you have inited the repo and open the .repo ( press ctrl + H if it is NOT visible ).

Create a folder named local_manifests

Download this local_manifest.txt and rename it to local_manifest.xml and copy it in the / .repo / local_manifests / directory

NOTE : In some older ROMs where an older version of the repo tool is used the local manifests has to be placed like

As opposed to a folder named local_manifests as illustrated in the above pictures

Functions of the local manifest :

The local manifest looks somewhat similar to the main manifest.xml ... however in this you can even remove projects or add them

> To remove projects the basic syntax is :

Code:

<remove-project name="name of the project" />

What to remove :

Consider my case

I am building AOKP JB-MR1 for the HTC Explorer.

As a result of that I do not need the various device trees that are officially supported by AOKP.

Such all these :

Quote:

So why do I waste my data and time downloading those ?

I think I should modify the default.xml / manifest.xml .

NO !

Beware ! If you try to edit the default.xml / manifest.xml the git will tell you to commit these changes as they do NOT match with the online / and the synced version of the default.xml that you have originally initializeed with.

So this means you will either have to commit those changes , push it to github and update the default.xml
This is not possible unless you are a device maintainer for a ROM and even if you are such drastic changes mean it can affect the other users of the same default.xml . So chances are you can never bring about a change in the default.xml.

So dont even think about editing the default.xml

OR

You will have to revert back to the original default.xml that you was present in your .repo and create a local_manifest.xml and remove projects / add them .

How do I do that ?

Basic syntax for removing them is :

Code:

<remove-project name="name_of_project" />

As shown in the image since I dont need those projects the syntax will be somewhat like :

In a similar way , I went on removing projects that were not required... only device trees and saved the local_manifests.xml

Remember when I earlier synced there were 415 projects ?

Look at it now .. slimmed down around 50 projects !

That means a much quicker repo sync for me !

> How to add projects to get it synced :

To add projects just use the code like I explained in the manifests.xml

Basic syntax is :

Code:

<remote name=" any name here "
fetch="url of the remote website/hosting/server "
review="url of the code review of the repo :optional: " />
<project path=" directory in work tree" name="name of the repository in remote" remote="name of remote defined earlier" revision="branch
of the repository" />

EG :

I wanted to add my own device tree of AOKP and the kernel source for my device in the local manifests cause I am too lazy to manually download them

If you don't own an HTC device you don't need any of their repos ! Same goes with Sony , Samsung and all other manufacturers.

Note: Do NOT delete generic repos like android_device_common etc.

If you own a samsung/sony/htc/blah device DO NOT Remove their common/ generic repos using the local manifest !

Also download a few sample device trees which are similar to your device so that you can reference the way the device trees are while compiling your unofficial ROM.

This process is called" KangBang"-ing.

Remove all kernel source repos that you do not need !

Remove all projects named :

Code:

android_kernel_oem_codename
kernel_oem_codename

or similar !

If you don't plan on building for that device , Why do you need its kernel source code !

And most of these sources are HUGE !

Remove all the unnecessary packages that are present in the manifest; for example if your phone does not have flash, there is no point downloading the torch.apk.. so might as well remove that from manifest

This includes many packages like CDMA specific packages for a GSM phone , torch , flashlight packages for a phone that doesnt have flash , unnecessary live wallpapers , and many more stuff.

If your phone's ROM is less you can also remove many packages from syncing itself instead of removing them from the build !

Once that is done just type in this command while you are in youre source directory

Code:

prebuilts/misc/linux-x86/ccache/ccache -M 50G

ICS and lower change it accordingly.

50 G ---> 50 GB of ccache..

Ideal values range for 50-100 GB.

Though if you want you can set it to around 40 GB

How does ccache work ?

Well , in short , what it does is that for C and C++ programs it caches the output. One it detects that the program is getting repeated it directly sends out the output and thus reduces the time of compilation.

After using ccache you will really feel the difference in the compilation speeds of your ROMs and kernels .

Tip # 4 : Use a custom toolchain

Try to use toolchains like linaro toolchains for compiling your ROMs and kernels.

For me personally it made a lot of difference in the performance of the ROM compiled. Nearly a 20-30 % increase in the performance.

Just extract the toolchain in a directory similar to the one I have mentioned in the picture

and edit these 2 lines in the envsetup.sh

To compile the inline kernel using a custom toolchain :

Place your toolchain in the ~source~/prebuilt/linux-x86/toolchains/

and in your device tree edit the BoardConfig.mk for eg :

In addition to this, you may need some device specific patches too. That maybe you will be able to find out in your device specific forums.

Tip # 5 Cherry-picking

So here's the scenario.

I have built a ROM and simeltaneously CyanogenMod development is taking place and their developer is fixing some bugs that are present in the device tree of the ROM.

He has implemented some changes that might help me fix stuff in my device tree thereby improving my ROM .

So what do I do ?

Manually apply those commits ?

There is a better way than that. Manually applying commits may result in a few human errors in your source code and thereby may cause some unwanted errors. So why not apply the CyanogenMod dev's commits itself!

To do this, we use a git feature called cherry-picking.
How to cherry pick commits :

First change your directory to the directory in which you want to apply the commits in.

I will take an example of my phone's device tree.

Code:

cd device/htc/pico

The best thing is to initialize an empty git and pull your own repo from here.

This allows you to push your changes to your github so that you can track your changes effectively.

If you dont have a repo on your github then push one right away or fork someone else and do :

XDA Developers was founded by developers, for developers. It is now a valuable resource for people who want to make the most of their mobile devices, from customizing the look and feel to adding new functionality.Are you a developer?