[G2 and Desire Z Android Development] teh5abiking:
PART 2 - Compiling CyanogenMod.

This half of the tutorial covers the actual compilation of CyanogenMod, one of the most popular custom ROMS that are available to modded Android devices. CyanogenMod supports more devices than ANY custom ROM project that is available for the Android operating system, and let's see

Reasons why you might want to compile your own version of CyanogenMod might be one of the following:

- You might want an updated version of your ROM or an updated portion of your ROM (be that an updated kernel, updated core applications, or an updated version of the Android operating system)

- Certain bugs that you might have experienced in the stable releases of CyanogenMod may have been patched.

- The ROM that you'll compile will contain the most bleeding-edge features that have been committed into the CyanogenMod github.

- You can pick and choose which features that you want and which features you don't want (cherry-picking features won't be covered in this post.)

- You might want to see what goes into making a custom ROM.

- Certain features that you don't care for may have been omitted from the CyanogenMod github or may have been tweaked.

NOTE:

Even though 64-bit building environments are supported past Android 2.2, this tutorial will still work on a 32-bit computer.

UPDATE:

The Android Open Source Project has been updated to provide 32-bit build environments. However, the AOSP claims that this is experimental. So far, everything is stable. I've incurred no issues as of yet.

FOR 32-bit systems:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown libxml2-utils

For 64-bit systems:

$ 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

If you have a 64-bit system, you must also do the following:

-

If you are running Ubuntu 10.04, 10.10, or 11.04, execute the following command in a terminal

:

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

-

If you are running Ubuntu 11.10, execute the following command in a terminal

:

$ sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so

NOTE

: For 64-bit systems running Ubuntu 11.10, you may not need to install the 'ia32-libs' package, as the 64-bit edition of Ubuntu 11.10 comes with multiarch support, meaning you can run 32-bit programs without the need for additional libraries. However, I've yet to test this feature because I'm running a 32-bit computer. Please post your results if you've tried this tutorial without ia32-libs and instead used Ubuntu 11.10's multiarch support.

Once you do that, you should have something like this (I've already set up my build environment, so it won't be exactly the same as what you should have. Either way, it should go about as a standard package installation procedure)

Okay, now that we have our packages installed, we need to create the build directories. In that terminal window that you should still have open, enter the following commands so that we can create the build directories.

$ mkdir -p ~/android/system/
$ mkdir -p ~/bin/

NOTE: You can replace "~/android/system/" with any other type of directory. Some people go with "~/cm-build" other people go with "~/cm7" Any time you see "~/android/system/" in a command, just replace that with whatever your build directory is. Just make sure you enter the right location though for such commands.

Now we need to initialize the repo binary and make it executable. If you're wondering what the repo binary is, just look it up at http://source.android.com/source/version-control.html

To make the binary executuable, enter the following commands:

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

NOTE:

You may have to reboot for these changes to work.

Once you've done that, it should look a little something like this:

Okay, now that we've got the repo binary set up, we're now ready to download the source. I warn you though, it does take a long time, so you're gonna want to get a snack, watch a movie, play Quadrapassel, etc. just to pass the time. Trust me.

Okay, let's download the source so that we can continue :D

$ cd ~/android/system/
$ repo init -u git://github.com/CyanogenMod/android.git -b gingerbread
$ repo sync -j16

And now we play the waiting game. You may be wondering what the "-j16" addon is for, well it's essentially an addition to the repo sync command that starts 16 tasks at once. It's a little quicker than doing it withouth the -j16 addon. In total, it should take anywhere between one hour to two hours, depending on your internet connection. Well, I just played Quadrapassel (Ubuntu's version of Tetris) while it was syncing.

Once it's done syncing, you should have something that's in the picture below.

Congratulations! You've withstood the first test. Now let's continue.

This is the part where you're supposed to copy the proprietary files from your G2/DZ. The problem here is that most of the time, it'll give you an error message saying that "MS-HTCEMR-20-BLAHBLAHBLAH.apk is missing" Instead of having to copy the proprietary files straight from the device itself, I just got them from the Koush github.

Here's the link to the Koush github. Just hit the download button that's in the upper right-hand corner and save as .zip file.

https://github.com/koush/proprietary_vendor_htc

Extract it to "~/android/system/vendor/htc/" By doing this, not only do you have the proprietary files for Vision, you also have the proprietary files for ALL HTC devices that CyanogenMod currently supports. That means you can compile a ROM for ANY HTC Android phone you want (Passion/N1, Bravo/Desire, Glacier/MT4G. etc.) Score 1 for doing it unconventionally!

Now it's time to get ROM Manager. You only need to do this every time there's a new release of ROM Manager. So, in that terminal window that I hope you've kept open after all this time, enter the following:

$ ~/android/system/vendor/cyanogen/get-rommanager

This will get the latest version of ROM Manager that's currently available. We need to see if there have been any updates in the source. That means we're gonna have to repo sync again. Why? Well, we just spent about an hour or two gathering the source, and in that time, something could've changed in the github, so it only makes sense to check again. This time, the repo sync should be faster since we already have all the source.

$ cd ~/android/system/
$ repo sync

Once that's done, now we're ready to start cooking up the ROM. Enter the following:

$ make clean
$ make installclean
$ make clobber
$ . build/envsetup.sh && brunch vision

(make clean, make installclean, and make clobber clean out all the directories so that every time you make a ROM, older builds you made yourself won't conflict with the one you're making right now. the brunch is the one that actually sets up the build environment and builds the ROM.)

Compiling the ROM takes anywhere between 20-30 minutes on good hardware to 1 hour - 2 hours on older computers. If you're impatient, read this article from the CyanogenMod Wiki that explains how to speed up compiling, testing, etc.

http://wiki.cyanogenmod.com/wiki/Howto:_Speed_up_building

Congratulations! You've successfully compiled your first build of CyanogenMod! Give yourself a pat on the back. If you're curious as to how this should look, well the photo below should tell you how it should looks. All builds you'll compile have the KANG addition since it's not an official release of CM7.

Remember to hit that Thanks button people :)

All thanks go to the following people:

cyanogen for sharing his methods.

sykopompos for providing original instructions on how to set up the SDK and compiling CM7

plasmadragon007 for helping me getting the build to compile.