[HTC Rezound] shrike1978:
So you want to build CyanogenMod and don't know where to start?​

I wanted to make a step-by-step guide for installing and configuring everything necessary for building CM9 in a virtual machine (VM) on a Windows machine. There's a scattered information in the forums on most of this, but I wanted to bring it together and share what worked best for me for any newbies who want to try to get their feet wet with AOSP development, or who would just like to be able to have their own up to date builds from source.

Huge thanks go out to dmeadows013 and antp121. It was their guides I started with when doing this myself, and without them, I don't think I would have even known where to begin. Their guides are at http://xdaforums.com/showthread.php?t=1810297 and http://xdaforums.com/showpost.php?p=31530111&postcount=12

This guide is designed to allow people with no Linux or development experience to get up and running as quickly as possible. Though no prior knowledge should be required, I highly recommend that you pay attention to what you are doing, and research or ask about anything you have questions about so that you'll understand the process. I've divided this into multiple parts to make it easier to do in stages.

What you need:

1) A Windows computer, preferably with a CPU that supports hardware virtualization. Most relatively modern processors do, so if you've bought your computer in the last 4 or 5 years, it's probably fine. Without this, you won't be able to run 64-bit or multiple processor VM's. Your Windows OS doesn't have to be 64-bit, your CPU just needs to support hardware virtualization. I won't say that this will not work on a 32-bit VM, but I've never tried it, so I can't support it if it doesn't. If you want to try, just replace all of the references to 64-bit in this guide with 32-bit.

2) Plenty of memory. I recommend at least 4GB on the host computer. You can make it work on less, but more is better.

3) At least 60GB of free hard drive space during the install, at least 50GB of which will be used permanently.

4) Plenty of time on your hands. You don't want to be rushed while you're doing this the first time.

Preliminaries:

1) Go to https://www.virtualbox.org/wiki/Downloads and download the latest version of VirtualBox for Windows hosts. The current version as of this writing is 4.2.

2) From the same website, download the latest version of the Virtual Box Extension Pack.

3) Go to http://www.ubuntu.com/download/desktop and download the 64-bit version of Ubuntu Desktop 12.04.1 LTS. This version will be supported for at least two years and will provide a stable OS base for at least that length of time.

Install and configure VirtualBox:

1) Run the VirtualBox installer executable you downloaded in the preliminaries section. Choose the default options at every prompt.

2) During the installation, the software will ask you for permission to install drivers. Choose install when it asks.

3) When the installation is complete, uncheck the box to start the application, then click Finish.

4) Run the VirtualBox Extension Pack installer that you downloaded in the preliminaries, and click Install and Agree.

5) From the VirtualBox Manager, click New

6) Name your machine whatever you wish (Android Build Box, for example), select Linux as the type, and Ubuntu (64-bit) as the version. Click Next

7) Give the machine as much memory as you can spare and click Next. I've found myself to need at least 1536MB (1.5GB) as a minimum to build with. More memory will result in a faster build time. If you intend to give the machine more than one processor, you need to give it more memory as well.

8) On the Hard drive prompt, click Create

9) Choose VDI and click Next

10) Choose Dynamically allocated and click Next

11) Give the drive at least 50GB of space and click Create. As always, more is better. 50GB will give you enough room to work on a single copy of CM9 with a little breathing room. You need more if you want to work on multiple copies.

12) Choose your VM and click Settings

13) Click the Advanced tab in General settings. Set Shared Clipboard to Bidirectional. This will allow you to copy and paste between the virtual machine and your Windows host.

14) If you wish to give your VM access to more than one processor, click on System, then choose the Processor tab. Select the number of processors you wish your VM to use.

15) Click OK. Your VM is now configured.

Install Ubuntu 12.04.1:

1) In the VirtualBox Manager, choose your VM and click Settings.

2) Click Storage.

3) Click Empty, underneath the IDE Controller entry.

4) On the far right, under Attributes, click the small CD icon and click "Choose a virtual CD/DVD disk file..."

5) Choose the file ubuntu-12.04.1-desktop-amd64.iso that you downloaded earlier

6) Click OK

7) Make sure your VM is selected, and click Start.

8) As it boots, confirm the messages that appear, click "Do not show this message again" if desired.

9) After a few minutes, the VM will boot to a selection screen. Choose Install Ubuntu.

10) Click Download updates while installing and Install this third party software. Click Continue.

11) Leave Erase disk and install Ubuntu checked, then click Continue. This will only erase the virtual drive.

12) Click Install Now.

13) Choose your time zone and click Continue.

14) Choose your keyboard layout and click Continue.

15) Set up your username, password, and a machine name. REMEMBER THIS PASSWORD. You will need it, even if you enable Log in automatically. Click Continue.

16) Now sit back and relax. The installation will take a while.

17) When installation is complete, click Restart Now

18) When prompted, press Enter

19) The VM will reboot into your new Ubuntu installation.

A note about your new VM installation of Ubuntu: This is just like any other computer and should be treated as such. It needs to be properly shut down to prevent disk corruption. To shut down the system, click the gear icon in the upper right and choose Shut down. You should also keep the system properly updated, because when it is running, it is just as accessible to the Internet as any other computer on your network, so keep the security updates installed as you are notified.

Update Ubuntu 12.04.1 and install Guest Additions:

1) Log into your system with the user you created during installation. Ignore any warnings you may get about new drivers being available. We will take care of that in a bit.

2) Click the top icon of the sidebar (Dash Home), type update, and click Update Manager.

3) Click Install Updates

4) When prompted, enter your user password.

5) When updating is complete, click Restart Now

6) After restart, log back in.

7) In the VM Window menu, click Devices, then click Install Guest Additions...

8) Click Run and enter your password when prompted.

9) After process completes, reboot by clicking the gear in the upper right corner, clicking Shut Down, and clicking Restart.

Configure your build environment

1) Log into your Ubutntu system, open Firefox from the sidebar and go to http://www.oracle.com/technetwork/java/javase/downloads/jdk6u35-downloads-1836443.html

2) Click agree and download jdk-6u35-linux-x64.bin

3) Click on Dash Home, type terminal, and open the Terminal app.

4) Right click on Terminal in the sidebar and select Lock to Launcher.

5) Retrieve the build tools:

sudo apt-get install git-core git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 schedtool gcc-multilib g++-multilib pngcrush g++ gcc dpkg-dev

6) Unpack Java by typing the following commands in terminal:

chmod a+x ~/Downloads/jdk-6u35-linux-x64.bin
sudo mv ~/Downloads/jdk-6u35-linux-x64.bin /usr/lib
cd /usr/lib
sudo ./jdk-6u35-linux-x64.bin

7) Install Java by executing the following commands:

sudo mv jdk1.6.0_35/ jvm/
sudo rm jdk-6u35-linux-x64.bin
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_35/jre/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_35/bin/javac 1
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_35/bin/jar 1
sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.6.0_35/bin/javadoc 1

8) Make Java 1.6 the default by typing the following commands individually, and selecing the jdk1.6.0_35 line in each (typically number 2):

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config jar
sudo update-alternatives --config javadoc

Create the build directories and retrieve the code:

1) Log into your Ubuntu system and open a terminal window

2) Create your build directories:

mkdir ~/android ~/android/bin ~/android/cm-10.1

3) Open your profile config:

gedit ~/.bashrc

4) Insert the following into the end of your profile:

ANDROID_JAVA_HOME=/usr/lib/jvm/jdk1.6.0_35
export ANDROID_JAVA_HOME
PATH=~/android/bin:$PATH
export PATH

5) To reload your profile, exit your terminal window and open a new one.

6) Download the repo binary:

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

7) Initialize and sync the repo (download the code). This will typically take a couple of hours the first time you run it:

cd ~/android/cm-10.1
repo init -u git://github.com/Chad0989/android.git -b cm-10.1
repo sync

8) Retrieve the prebuilts:

./vendor/cm/get-prebuilts

Build CM10.1

1) Now, all that's left is to build. If you want to get the latest code, run another repo sync (included here). It only retreives changes, so it should only take a few minutes from now on. Ignore warnings and let it build. As long as it doesn't crash, you're fine. It can take anywhere from an hour to half a day, depending on the resources you gave the VM:

cd ~/android/cm-10.1
repo sync
. build/envsetup.sh
make clobber
brunch vigor

2) Go get your freshly baked CM10.1 from ~/android/cm-10.1/out/target/product/vigor.

I hope this is useful for someone. This guide is the result of several days of learning on my part, and several hours of writing. If there is anything that doesn't work, let me know. I will probably be cleaning it up a bit in the near future, and I may add an FAQ and/or glossary if it appears that one is needed. I'll also attempt to keep it updated with the newest versions of the tools. Thanks for reading, and have fun building.

Special thanks to:

dmeadows013 and antp121 - For providing the guides that got me started. I couldn't have done any of this without you.

chad0989 - For AOSP on the Rezound.

IAmTheOneTheyCallNeo - For answering my stupid questions and inspiring me to get more involved

Snuzzo - For answering more stupid questions and giving more inspiration

synisterwolf - For being generally awesome and putting up with me in chat

puhleez - Who's environment issues inspired me to make this guide
​