How to Download/Compile Specific Parts of a ROM

This is a tutorial about how to download and compile specific parts in AOSP based roms (such as CyanogenMod, AOKP, SlimRom etc)
It’s mainly dedicated for the people who want to get more familiar with the AOSP build environment, and would like to manipulate it’s behavior to complete specific tasks.

Downloading ROM sources is done with the tool “repo”, this is the most awesome downloader in existence. Not only it looks very cool, it also reaches top speed at all times. But it’s only for linux (which is good, since when you are busy with aosp roms, you should be on linux!)
Why is it awesome? Since you decide yourself how many jobs (aka connections) you make with the server. This means you always will get top speed, there is probably no faster download method available on the Internet (except for speedtests, but they don’t count). Next to the downloading of specific parts it’s of course also handy to know how to actually compile them.


1. Download
2. Compile

3. Automate (optional)


Chapter 1. Download:
The easiest way of fetching for example a batch of AOSP apps is like this:

1. Choose the desired tag you want to use, in the example I will use android-4.2.2_r1
2. Now make a dir somewhere:

3. Download repo when not installed yet:

4. Enter the line that will download the initial manifest.

for AOSP:

Enter your name and email address and wait until it completes

for CM:

5. Go in the hidden “.repo” dir and change the manifest

If you don’t have decent text editor such as “gedit”, install it! “sudo apt-get install gedit”


For example when you only want to download the apps, just remove all lines that are not app related. simple as that

When done, save it and go a dir back in the terminal

6. Download the packages

(With a 60mb/s connection you already get the max download speed with ” -j4 ” which is the default of github)

The packages will be download as quickly as possible to your harddrive now.


Chapter 2. Compile:
To compile the obtained packages separately you will need a AOSP environment (or CM/AOKP etc). When you have a succesfull environment which is able to compile for your device you may enter:

now you’re theoretically ready to compile
to compile an app on the easiest way:

where “Appname” is the name of the folder placed in packages/apps/..
This also counts for “SystemUI” which is not in that folder

And the -j param again stands for the number of jobs, remember that this is compiling and not downloading, so the “standard rule” with this is, number of cores of your CPU + 1.
Which makes a regular quad core (-j5) but makes a i7 CPU with Hyper threading (-j9). When using -j16 for example on a regular quad core it could happen that your CPU will be overloaded so much that your mouse will lag all over the place.
(Linux forces the cpu to perform higher then it actually should, resulting in unwanted situations)

When having trouble, when it stops or just nags about some missing symbols or something like that.
You should try using the “-k” param, this tells the make command to keep going when a non-critical error occurs.

When having issues with the local module tags, you should enter this:

To compile other parts you also need to enter the folder name, here are some examples from /frameworks/base

or more examples:


Chapter 3. Automate

If you regularly want to compile specific ROM parts you can make a shell script that automates the process for you.

Make a new document with some name, for example “buildessentials”, open the file with your favorite text editor (gedit is recommended)
and place this line at the very top of your document:

This indicates that this file should call /bin/bash, which is the shell interpreter.

Under this line you should place all the single commands that you want to be executed when running the script. For example:

So your total output would be:

Now you should change the permissions of the files, which need to be RWX-RX-RX, which is 755.
This can be done by entering this in the shell:

Now you can run the script by entering:

Thats it!