Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[TUTORIAL]Setting up and compiling CM9/CM10 from source

OP mbroeders

26th March 2012, 10:38 PM   |  #1  
OP Senior Member
Flag Amsterdam
Thanks Meter: 218
 
942 posts
Join Date:Joined: May 2010
More
Since I’ve seen many questions on how to build cyanogenmod 9 (CM9) from source for the Galaxy Nexus, but there isn’t a proper guide, I will attempt to write a small how-to. There already is a very good guide how to build ICS from source, but there are a few extra things you’ll have to do for CM9. I hope it will be useful, and if not, well, at least I’ve tried

LATEST UPDATE: August 20th - also added CM10


SETTING UP THE BUILD ENVIRONMENT
I highly recommend Ubuntu 12.04 64 bit for development or Linux Mint 13. It is possible to build on different linux distro’s, but I cannot cover all exceptions. (If you don’t have linux installed or are afraid to set up a dual boot, it is possible to build in a virtual environment –e.g. virtualbox-. Building in a virtual environment however, can be very slow. Also, 64 bit is recommended.)

Make sure java is installed! At the end of this post, I have written a small guide how to install java.

Set up adb and create proper udev rules
I will not write these steps down, but rather point you to some very nice and easy guides. It would be best to do this first, however, it is not completely necessary if you just want to build a fully functioning rom.
1) set up adb (follow this excellent guide)
2) set up udev rules which allow you to start adb without having to use sudo (follow this terrific tutorial)

Installing all necessary packages and set up repo (source)
Open a terminal and copy the following code:
Code:
 
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
WARNING: run the following commands as user (NOT as root) unless stated otherwise (e.g., when it explicitly shows ‘sudo’ before a command)!!!

Next, you’ll have to install repo to download the source. First we’re going to create a bin folder (1) in our home directory and include it in our path (2). Also, download the repo script (3) and make it executable (4). All from the command line:
Code:
mkdir ~/bin
PATH=~/bin:$PATH
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
Okay, we’re done with the first part. So far it’s been similar to building pure AOSP.For CM, there will be some additional things you’ll have to do.

DOWNLOADING THE CM SOURCE
Create a directory (CM9 -or CM10-) for your working files:
Code:
mkdir CM9
cd CM9
and then initialize the main CM repo (For CM10, just replace ics with jellybean):
Code:
repo init -u git://github.com/CyanogenMod/android.git -b ics

Good, now you’re ready to download the source. This can take a couple of hours!! Run the following command from the terminal (Run the following commands in the terminal from the root of the directory that contains the source, e.g., ~/CM9/):
Code:
repo sync
Okay, the majority of the files needed to build CM are now on your computer. However, device specific files are needed. To get them, issue the following command in your terminal:
Code:
source build/envsetup.sh
lunch
After the lunch command, choose your device. If you have a GSM version, choose cm_maguro, if you have the CDMA version, choose cm_toro. Additional files needed for your device are being downloaded right now.


Before you can actually build the rom, you’ll need to run two more commands to get some proprietary files.
1) Open a terminal and go to CM9/vendor/cm/. Run the following command:
Code:
./get-prebuilts
This will download term.apk and rommanager.apk. You will need these files otherwise you’ll get an error while building.

2) Now we need to grab some files from your phone. Make sure you have a working build cyanogenmod version (just install a nightly) on your phone. Make sure adb is setup properly (see beginning of this post)!

Connect your phone to the pc. Open a terminal and go to CM9/device/samsung/(Maguro OR Toro)/. Run the following command:
Code:
sh extract-files.sh

BUILDING CM9/CM10
The building part is very easy. It just requires two simple commands:
Code:
source build/envsetup.sh
brunch
After the brunch command, choose your device. Again, if you have a GSM version, choose cm_maguro, if you have the CDMA version, choose cm_toro. Depending on your computer, hopefully you’ll have a fully functioning CM9 or CM10 in 30minutes-2hours (or even longer) . You can find the rom in: /out/target/product/(Maguro OR Toro)/

Next time you build, first clean your working directory. Enter the following command in the terminal:
Code:
make clobber
This will completely remove your output directory!
To update the source, before each build just run:
Code:
repo sync

ADDITIONAL INFO
Install Java
Installing java is very easy in Ubuntu 12.04. Java 6 is recommended. To install it in Ubuntu 12.04 or Linux Mint 13, download the most recent Java 6 SDK from HERE. To install, open a terminal and run the following commands:

Code:
$ chmod +x jdk-6u34-linux-x64.bin
$ sudo ./jdk-6u34-linux-x64.bin
$ sudo mv jdk1.6.0_34 /usr/lib/jvm/

$sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_34/bin/java 1
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_34/bin/javac 1
$ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_34/bin/javaws 1

$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config javaws
NOTE: after each 'update-alternative'-command, choose the correct (new) java version!


To check if you have the correct java version, type in a terminal:
Code:
java –version
I also added JAVA_HOME to my path; I don’t know if it is still necessary, but it doesn’t hurt either. First, check where java is located. In a terminal type:
Code:
which java
In my case the output shows /usr/bin/java, but it could be located somewhere else. Write down the path minus '/java'. Then open /home/USERNAME/.bashrc and add the following line to the bottom of the file:
Code:
export JAVA_HOME=/usr/bin
Of course replace /usr/bin with your path. Then save and close, and in a terminal run:
Code:
source ~/.bashrc
Odexed version
Some people like their rom to be odexed. There are multiple ways to achieve this (special thanks to Planet X for helping me with this):

1)Instead of ‘brunch’ do the following (if you are building for toro, replace maguro with toro):
Code:
source /build/envsetup.sh
lunch cm_maguro-user
make –j4
(Note:
taken from source.android.com: 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.)


2)If you want to build an odexed version every time and just want to use the brunch command, do the following:
-Open build/core/main.mk
-Comment out (place a # at the beginning of the line) lines 240, 241, 245, and 246. Thus, replace:
Quote:

ifneq (true,$(DISABLE_DEXPREOPT))
ifeq ($(user_variant),user)
Ifeq ($(HOST_OS),linux)
WITH_DEXPREOPT := true
Endif
endif
endif


Quote:

# ifneq (true,$(DISABLE_DEXPREOPT))
# ifeq ($(user_variant),user)
Ifeq ($(HOST_OS),linux)
WITH_DEXPREOPT := true
Endif
# endif
# endif

Now you can use the brunch command to build an odexed version with insecure boot image.


Hopefully this guide will benefit some people, if not, it kept me busy for a while. Enjoy building!!
(btw, I'm not a native english speaker, so excuse me if I made errors in grammar )
Last edited by mbroeders; 7th September 2012 at 03:01 PM.
The Following 25 Users Say Thank You to mbroeders For This Useful Post: [ View ]
27th March 2012, 02:08 AM   |  #2  
Senior Member
Flag Los Angeles, CA
Thanks Meter: 396
 
5,581 posts
Join Date:Joined: Apr 2010
Wow great work. These tutorials keep getting better making it so easy to compile your own rom!
The Following User Says Thank You to RogerPodacter For This Useful Post: [ View ]
10th April 2012, 06:23 PM   |  #3  
inffy's Avatar
Senior Member
Flag Helsinki
Thanks Meter: 692
 
2,059 posts
Join Date:Joined: Jun 2005
Donate to Me
More
So what does that "brunch" command actually do?

Is it just a script that does the make otapackage commands and stuff?
10th April 2012, 08:15 PM   |  #4  
OP Senior Member
Flag Amsterdam
Thanks Meter: 218
 
942 posts
Join Date:Joined: May 2010
More
Quote:
Originally Posted by Infra

So what does that "brunch" command actually do?

Is it just a script that does the make otapackage commands and stuff?

Indeed! Brunch is actually a combination of 'lunch' and 'make'. Using the 'lunch-part' you choose your build (in our case the maguro or toro). Next, the 'make-part' actually gets things going. The nice thing using brunch is that it automatically detects the maximum number of threads it can use so that it will run at maximum speed.
The Following User Says Thank You to mbroeders For This Useful Post: [ View ]
29th April 2012, 09:05 PM   |  #5  
SupWiz17's Avatar
Senior Member
Flag Chicago, IL
Thanks Meter: 67
 
561 posts
Join Date:Joined: Jan 2012
More
Finally set my computer up to compile CM9 last night for the first time and after a few tries I finally got it going. The only problem is that I am now getting an error very close to this one.

http://forum.xda-developers.com/show...postcount=3093

That poster says that it has been happening for a few days now. Is this a known issue with compiling CM9 or is this just user error? I have tried twice compiling now and have had no luck. Is it working for anyone else?

---------- Post added at 02:05 PM ---------- Previous post was at 01:19 PM ----------

Here is the exact error that Im getting. I tried it again today just to see if it anything had changed.

make[1]: *** [sub-make] Error 2
make[1]: Leaving directory `/home/mark/CM9/kernel/samsung/tuna'
make: *** [TARGET_KERNEL_BINARIES] Error 2
make: *** Waiting for unfinished jobs....
15th May 2012, 01:16 AM   |  #6  
housry23's Avatar
Senior Member
Flag Springfield, OH
Thanks Meter: 830
 
2,794 posts
Join Date:Joined: Sep 2009
More
Thanks for this guide. I just built my first CM9 kang. Getting ready to flash it. Now to find a guide on what I can and can't change and recompile or do I just remove stuff and use 7-zip to zip it back up?
15th May 2012, 04:29 PM   |  #7  
OP Senior Member
Flag Amsterdam
Thanks Meter: 218
 
942 posts
Join Date:Joined: May 2010
More
Quote:
Originally Posted by housry23

Thanks for this guide. I just built my first CM9 kang. Getting ready to flash it. Now to find a guide on what I can and can't change and recompile or do I just remove stuff and use 7-zip to zip it back up?

Glad to hear you succeeded building your first kang. I don't really understand what you want to do next? If you want to remove stuff from the zip, you can. I for instance always remove stk.apk. But you can also modify the build files so that only things you want will be built. You can play around with the source code and things like that. Anyway, most of the answers you will find using google. I also very much like the development board on Rootzwiki; people are really helpful and friendly there. So if you have any specific questions, i recommend that forum as well!
The Following User Says Thank You to mbroeders For This Useful Post: [ View ]
16th May 2012, 01:34 AM   |  #8  
housry23's Avatar
Senior Member
Flag Springfield, OH
Thanks Meter: 830
 
2,794 posts
Join Date:Joined: Sep 2009
More
Quote:
Originally Posted by mbroeders

Glad to hear you succeeded building your first kang. I don't really understand what you want to do next? If you want to remove stuff from the zip, you can. I for instance always remove stk.apk. But you can also modify the build files so that only things you want will be built. You can play around with the source code and things like that. Anyway, most of the answers you will find using google. I also very much like the development board on Rootzwiki; people are really helpful and friendly there. So if you have any specific questions, i recommend that forum as well!

Okay thanks. I was asking just what you answered. I want to be able to remove and/or add stuff to the zip for starters. I found the answer through Google, but I do appreciate you taking the time to answer. I'll definitely be visiting the Rootzwiki dev board. Thanks for the suggestion.
The Following User Says Thank You to housry23 For This Useful Post: [ View ]
16th May 2012, 04:36 AM   |  #9  
SupWiz17's Avatar
Senior Member
Flag Chicago, IL
Thanks Meter: 67
 
561 posts
Join Date:Joined: Jan 2012
More
I have successfully compiled cm9 from source but have never tried to cherry pick or Kang anything yet. Could you quickly explain how you cherry pick with cm9?

Sent from my Galaxy Nexus using Tapatalk 2
16th May 2012, 06:49 AM   |  #10  
Senior Member
Thanks Meter: 83
 
380 posts
Join Date:Joined: Jan 2012
Quote:
Originally Posted by SupWiz17

I have successfully compiled cm9 from source but have never tried to cherry pick or Kang anything yet. Could you quickly explain how you cherry pick with cm9?

Sent from my Galaxy Nexus using Tapatalk 2

Check out this link it may be helpful

http://rootzwiki.com/index.php?/topic/13189-[TUTORIAL]-Everything-you-ever-wanted-to-know-about-GIT#entry322735

Sent from my GT-S5360 using Tapatalk 2

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes