[Nexus One Android Development] samir5421:
My other tutorial for building CM for G2x

Last tested on 6/2/2011

This tutorial requires a basic to intermediate knowledge of linux terminal commands. First you will need to be running the latest CM nightly. Then you will need to install Ubuntu 11.04. This tutorial will work for if you are running Ubuntu in a virtual machine and if you installed it to your hard drive. I have tested this by installing it to my hard drive and in a virtual machine, but I have not tried it in Wubi but it should work. You need 11.04 64 bit.

How to install Ubuntu: https://help.ubuntu.com/community/Installation

After you have installed Ububtu, make sure that your OS is up to date. You can do that by running the Update Manager from the System>Administration menu. Once that is completed, go to Applications>Accessories and open Terminal.

Now you will be setting up your build environment.

Next lets open a terminal. Copy and paste the following into terminal.

(Copy from this tutorial with control+c and paste in terminal with control+shift+v)

sudo apt-get update && sudo apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev gitg qt3-dev-tools libqt3-mt-dev eclipse valgrind pngcrush schedtool

sudo add-apt-repository ppa:ferramroberto/java && sudo apt-get update && sudo apt-get install sun-java6-jdk && sudo update-java-alternatives -s java-6-sun

Now you will be installing ADB

Download the sdk from the android website (use the Linux download) http://developer.android.com/sdk/index.html

extract the sdk to your ~/ directory (home directory). So you should be able to go to a terminal and cd ~/AndroidSDK/platform-tools to access your platform-tools folder in your sdk. After that, update your android sdk by opening terminal and run:

~/AndroidSDK/tools/./android

Open the terminal, and type gedit .bashrc and at the top of the file, paste this (replacing user with your username)

#AndroidDev PATH
export PATH=${PATH}:/home/user/AndroidSDK/platform-tools
export PATH=${PATH}:/home/user/AndroidSDK/tools

This will make ADB, Fastboot and DDMS available from the terminal on next login.

Now, to make the device available to normal users, open a terminal and type

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

Then paste

SUBSYSTEMS == "usb", ATTRS {idVendor} == "18d1", ATTRS {idProduct} == "4E11", MODE = "0666"
SUBSYSTEMS == "usb", ATTRS {idVendor} == "18d1", ATTRS {idProduct} == "4e12", MODE = "0666"
SUBSYSTEMS == "usb", ATTRS {idVendor} == "0bb4", ATTRS {idProduct} == "0FFF", MODE = "0666"
SUBSYSTEM=="usb",ATTRS(idVendor)=="18d1",SYMLINK+="android_adb",MODE="0666"
SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"
SUBSYSTEM=="usb", SYSFS{idVendor}=="1004", MODE="0666"

Save and exit.

Ensure that the rules are executable:

sudo chmod a+rx /etc/udev/rules.d/*

Then type

sudo restart udev

You should restart your computer (or virtual machine) right now to ensure that everything is running properly.

Note: idVendor may vary. Use lsusb from the terminal, look for your Android device and replace “0bb4? with the first 4 characters after “ID”.

If ADB is still not working, read http://xdaforums.com/showthread.php?t=533 and http://alan.lamielle.net/2010/01/22/nexus-one-usb-in-ubuntu-9-10

You should now have a fully working android build environment.

Now before you begin getting and building the source, make sure that you are on the latest CM7 nightly and have the latest gapps from Rom Manager.

Now to setup the CyanogenMod build environment and to build it

Enter the following lines in terminal:

cd ~/
mkdir -p ~/bin
mkdir -p ~/cm7
cd ~/bin
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
cd ~/
chmod a+x ~/bin/repo
PATH="$HOME/bin:$PATH"
PATH="$HOME/AndroidSDK/platform-tools:$PATH"
PATH="$HOME/AndroidSDK/tools:$PATH"
cd ~/cm7
repo init -u git://github.com/CyanogenMod/android.git -b gingerbread

Press enter and enter the information it asks for.

The next command will download all of the CM source. It will take at least a few hours or more depending on your internet speed.

repo sync -j16

After the sync, plug your phone in, and run adb devices and if your phone is listed, continue. Otherwise, go back and make sure you have properly installed adb and the drivers.

Plug your phone in, copy the following commands into terminal, and press enter.

cd ~/cm7/device/htc/passion/
./extract-files.sh
cd ~/cm7/vendor/cyanogen/
./get-rommanager
./get-google-files

now you your CM build environment is complete.

Warning: Building CM pushes your computer to the max your cpu can handle. Make sure that your computer can handle compiling CM. If It cannot, DO NOT DO THIS.

To build, just run(use this command every time you want to build CM):

**** Here is a new updated command to build CM****

cd ~/cm7 && make clean && repo sync -j6 && . build/envsetup.sh && brunch passion

If you come across any problems while syncing use repo sync -f -j6 -d and it will force sync and override any changes made to the source on your computer.

and it will make an update.zip in ~/cm7/out/target/product/passion/update-cm-7.1.0-RC1-N1-signed.zip (or whatever the latest RC is)

Congratulations you have just compiled CyanogenMod for the Nexus One!

Possible causes if the build fails:

1. Make sure you followed the directions precisely.

2. Try all three of the build commands.

3. If you changed any of the code, make sure it has no errors. Open it up in eclipse and check for errors.

4. Search Google and XDA.

**If you are getting a problem with getting the gapps, it it because of the CM gapps mirror system.

1. download and install the latest gapps

2. plug your phone in and run:

~/cm7/vendor/cyanogen/./extract-google-files

Sources:

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

http://wiki.cyanogenmod.com/index.php?title=Compile_CyanogenMod_for_passion

http://www.lineardroid.co.uk/2010/07/configure-build-environment/

http://www.lineardroid.co.uk/2010/04/how-to-set-up-adb-in-ubuntu/

http://xdaforums.com/showthread.php?t=533090

http://alan.lamielle.net/2010/01/22/nexus-one-usb-in-ubuntu-9-10

http://xdaforums.com/showthread.php?t=704561

Be sure to thank if this was helpful!