How To Build CyanogenMod Android for Google Galaxy Nexus (Sprint) ("toroplus")

From CyanogenMod
Jump to: navigation, search

How to Build CyanogenMod for Galaxy Nexus (Sprint) (codename: toroplus)


This CyanogenMod build walkthrough is auto-generated specifically for the Galaxy Nexus (Sprint) based on the device template at Template:device_toroplus. You can find similar build instructions for every officially supported device. See here for more info.


These instructions will hopefully assist you to start with a stock Galaxy Nexus (Sprint), unlock the bootloader (if necessary), and then download the required tools as well as the very latest source code for CyanogenMod (based on Google’s Android operating system). Using these, you can build both CyanogenMod and ClockworkMod recovery image from source code, and then install them both to your device.

It is difficult to say how much experience is necessary to follow these instructions. While this guide is certainly not for the very very very uninitiated, these steps shouldn’t require a PhD in software development either. Some readers will have no difficulty and breeze through the steps easily. Others may struggle over the most basic operation. Because people’s experiences, backgrounds, and intuitions differ, it may be a good idea to read through just to ascertain whether you feel comfortable or are getting over your head.

Remember, you assume all risk of trying this, but you will reap the rewards! It’s pretty satisfying to boot into a fresh operating system you baked at home :) And once you’re an Android-building ninja, there will be no more need to wait for “nightly” builds from anyone. You will have at your fingertips the skills to build a full operating system from code to a running device, whenever you want. Where you go from there-- maybe you’ll add a feature, fix a bug, add a translation, or use what you’ve learned to build a new app or port to a new device-- or maybe you’ll never build again-- it’s all really up to you.

What you’ll need

Add a comment to this section
  • A Galaxy Nexus (Sprint)
  • A relatively recent computer (Linux, OS X, or Windows) with a reasonable amount of RAM and about 50 GB of free storage (more if you enable ccache). The less RAM you have, the longer the build will take (aim for 8 GB or more). Using SSDs results in considerably faster build times than traditional hard drives.
  • A USB cable compatible with the Galaxy Nexus (Sprint) (typically micro USB, but older devices may use mini USB or have a proprietary cable)
  • A decent internet connection & reliable electricity :)
  • Some familiarity with basic Android operation and terminology. It would help if you've installed custom roms on other devices and are familiar with recovery. It may also be useful to know some basic command line concepts such as cd for “change directory”, the concept of directory hierarchies, that in Linux they are separated by /, etc.

If you are not accustomed to using Linux-- this is an excellent chance to learn. It’s free-- just download and run a virtual machine (VM) such as Virtualbox, then install a Linux distribution such as Ubuntu. Any recent 64-bit version should work great, but the latest is recommended.


You want to use a 64-bit version of Linux. According to Google, 32-bit Linux environment will only work if you are building older versions prior to Gingerbread (2.3.x)/CyanogenMod 7. However, as of 10.1 CyanogenMod does not build with 64bit host binaries on some systems. You will have to set something like BUILD_HOST_32bit=1 in your environment when building on such 64bit system.

Using a VM allows Linux to run as a guest inside your host computer-- a computer in a computer, if you will. If you hate Linux for whatever reason, you can always just uninstall and delete the whole thing. (There are plenty of places to find instructions for setting up Virtualbox with Ubuntu, so I’ll leave it to you to do that.)

So let’s begin!

Unlocking your Galaxy Nexus (Sprint)

What does "unlocking" mean?


If you’ve already installed CyanogenMod or another ROM on your Galaxy Nexus (Sprint), your device is already unlocked. Assuming you also have adb and fastboot installed on your computer, you can skip this whole section and proceed to the HOW TO BUILD section below.

The first step in putting any custom operating system on your Galaxy Nexus (Sprint) is to unlock the bootloader. A bootloader is the very first program that runs when you turn on your device. The bootloader initializes some hardware and then loads the kernel and ramdisk, and gets the boot process going. If the bootloader is in locked mode, it will ensure that only the stock operating system can run. Since you will be installing your own operating system, you need to turn this off. Luckily, Google and samsung make it easy.

Note: A Warning About Unlocking


Okay. I’m in. What do I need to do this?

To unlock your bootloader, you’ll first need a program on your computer called fastboot. One way to get fastboot is to download and install the Android SDK (Software Developer Kit) from Google. The SDK is used by app developers when they’re writing programs for Android, and who knows, you may want to write apps someday. But the SDK also contains two great tools that are useful even to non-developers. They are:

  • adb - Android Debug Bridge - this is a program that lets your computer “talk” to your Galaxy Nexus (Sprint) while the device is running. Among the many things you can do with adb-- you can push files from your computer to the device or pull files from the device to your computer, you can get a running real-time log of Android activity (which is very useful for debugging or having others help you debug), you can create an interactive “shell” session (similar to Linux or OS X) to type commands to your device, and much more.

  • fastboot - fastboot works a little bit like adb, except it’s often used at a much earlier point in the boot process, even before Android or any operating system loads. You can put your Galaxy Nexus (Sprint) into a “fastboot” mode, whereby, if you are connected via USB cable, you can copy entire partitions from your computer (usually in the form of an image file, such as boot.img or recovery.img) over to the device, wiping over whatever happened to be there. Fastboot is able to do more than that, however. It’s also used to send special commands to the device to do things such as unlock your bootloader.

How do I do the actual unlocking?

So this should be a one time thing...

Install the Android SDK

Add a comment to this section

To unlock your Galaxy Nexus (Sprint), you will need fastboot installed. Go ahead and download the SDK, per the steps on Google's web page. Then install it by following the specific instructions for your computer.


Google's instructions may be out of date for 12.04. The Sun JDK isn't available anymore as a dpkg AND they say Eclipse 3.6 isn't available as a package. Well, 3.7.X is now available. Doing a "$ sudo apt-get install eclipse" will now install the proper Eclipse and JDK (OpenJDK 6).

Unlocking the device


Unlocking the bootloader on a Nexus device will automatically wipe all device data.

  1. Make sure your computer has working fastboot and adb.
  2. Enable USB debugging on the device.
  3. Connect the device to the computer through USB.
  4. From a terminal on a computer, type the following to boot the device into fastboot mode:
    $ adb reboot bootloader
  5. Once the device is in fastboot mode, verify your PC sees the device by typing fastboot devices
    • If you don't see your device serial number, and instead see "<waiting for device>", fastboot is not configured properly on your machine. See fastboot documentation for more info.
    • If you see "no permissions fastboot", try running fastboot as root.
  6. From the same terminal, type the following command to unlock the bootloader:
    $ fastboot oem unlock
  7. A disclaimer will display on the device that must be accepted. Use the volume keys to cycle through the options. Pressing the power button should confirm your selection.
  8. If the device doesn't automatically reboot, reboot it from the menu. It should now be unlocked. You can confirm this is the case if you see an unlocked icon at the bottom of the Google boot screen during reboots.
  9. Since the device resets completely, you will need to re-enable USB debugging on the device to continue.


Add a comment to this section

If you have issues with fastboot or adb not being found, make sure that the Android SDK folder /platform-tools, which contains the adb and fastboot files, are in the path of execution for commands typed at the terminal. Usually typing something like

# PATH=$PATH:/your/specific/path/to/android/sdk/platform-tools/

will work for that terminal session.


The above command requires a bash-like shell. If you're running a linux distribution which uses a shell such as csh or tcsh, first run /bin/bash to start a bash shell. See or google for more help on that. You will need bash later as well, when using the ". build/" command.

Note: Linux Mint users

If you have problems with adb (“file not found”) and you’re using 64-bit linux (I don’t know much about Mint, so maybe it’s all 64-bit?) try doing this to see if adb works better:

$ sudo apt-get install ia32-libs

You’ll be using fastboot again to install ClockworkMod recovery.

Build CyanogenMod and ClockworkMod Recovery

Prepare the Build Environment

Add a comment to this section


You only need to do these steps the first time you build. If you previously prepared your build environment and have downloaded the CyanogenMod source code for another device, skip to Prepare the device-specific code.

Install the SDK

Add a comment to this section
If you have not previously installed adb and fastboot, install the Android SDK. "SDK" stands for Software Developer Kit, and it includes useful tools that you can use to flash software, look at the system logs in real time, grab screenshots, and more-- all from your computer.

Helpful Tip

While the SDK contains lots of different things-- the two tools you are most interested in for building Android are adb and fastboot, located in the /platform-tools directory.

Install the Build Packages

Add a comment to this section

Several "build packages" are needed to build CyanogenMod. You can install these using the package manager of your choice.

Helpful Tip

A package manager in Linux is a system used to install or remove software (usually originating from the Internet) on your computer. With Ubuntu, you can use the Ubuntu Software Center. Even better, you may also use the apt-get install command directly in the Terminal. (Learn more about the apt packaging tool system from Wikipedia.)

For both 32-bit & 64-bit systems, you'll need:

bison build-essential curl flex git gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop openjdk-6-jdk openjdk-6-jre pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev

In addition to the above, for 64-bit systems, get these:

g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev

Also see which lists needed packages.

Create the directories

Add a comment to this section

You will need to set up some directories in your build environment.

To create them:

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

Install the repo command

Add a comment to this section

Enter the following to download the "repo" binary and make it executable (runnable):

$ curl > ~/bin/repo
$ chmod a+x ~/bin/repo

Put the ~/bin directory in your path of execution

In recent versions of Ubuntu, ~/bin should already be in your PATH. You can check this by opening ~/.profile with a text editor and verifying the following code exists (add it if it is missing):

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then

Initialize the CyanogenMod source repository

Add a comment to this section

Enter the following to initialize the repository:

$ cd ~/android/system/
$ repo init -u -b cm-10.2

Download the source code

Add a comment to this section

To start the download of all the source code to your computer:

$ repo sync

The CM manifests include a sensible default configuration for repo, which we strongly suggest you use (i.e. don't add any options to sync). For reference, our default values are -j 4 and -c. The -j 4 part means that there will be four simultaneous threads/connections. If you experience problems syncing, you can lower this to -j 3 or -j 2. -c will ask repo to pull in only the current branch, instead of the entire CM history.

Prepare to wait a long time while the source code downloads.

Helpful Tip

The repo sync command is used to update the latest source code from CyanogenMod and Google. Remember it, as you can do it every few days to keep your code base fresh and up-to-date.

Get prebuilt apps (CM11 and below)

Add a comment to this section


$ cd ~/android/system/vendor/cm

then enter:

$ ./get-prebuilts

You won't see any confirmation- just another prompt. But this should cause some prebuilt apps to be loaded and installed into the source code. Once completed, this does not need to be done again.

Prepare the device-specific code

Add a comment to this section

After the source downloads, ensure you are in the root of the source code (cd ~/android/system), then type:

$ source build/
$ breakfast toroplus

This will download the device specific configuration and kernel source for your device. An alternative to using the breakfast command is to build your own local manifest. To do this, you will need to locate your device on CyanogenMod's GitHub and list all of the repositories defined in cm.dependencies in your local manifest.

Helpful Tip– Errors during breakfast

Different maintainers setup their device inheritance rules differently. Some require a vendor directory to be populated before breakfast will even succeed. If you receive an error here about vendor makefiles, then jump down to the next section Extract proprietary blobs. The first portion of breakfast should have succeeded at pulling in the device tree and the extract blobs script should be available. After completing that section, you can rerun breakfast toroplus

Helpful Tip

If you want to know more about what "$ source build/" does or simply want to know more about the breakfast, brunch and lunch commands, you can head over to the Envsetup_help page

Helpful Tip

Instead of typing cd ~/android/system every time you want to return back to the root of the source code, here’s a short command that will do it for you: croot . To use this command, you must first run . build/ from ~/android/system. Notice there is a period and space (. ) in that command.

Extract proprietary blobs

Add a comment to this section

Now ensure that your Galaxy Nexus (Sprint) is connected to your computer via the USB cable and that you are in the ~/android/system/device/samsung/toroplus directory (you can cd ~/android/system/device/samsung/toroplus if necessary). Then run the script:

$ ./

You should see the proprietary files (aka “blobs”) get pulled from the device and moved to the ~/android/system/vendor/samsung directory. If you see errors about adb being unable to pull the files, adb may not be in the path of execution. If this is the case, see the adb page for suggestions for dealing with "command not found" errors.


Your device should already be running a build of CyanogenMod for the branch you wish to build for the script to function properly. Nexus users: While it maybe be tempting to run the script on stock Android, and in fact it may succeed, realize that some of the blobs CyanogenMod uses are modified or otherwise different from stock blobs (e.g. Adreno graphics libraries). Save yourself some trouble and install a copy of CyanogenMod on your device before extracting blobs.


It’s important that these proprietary files are extracted to the ~/android/system/vendor/samsung directory by using the script. Makefiles are generated at the same time to make sure the blobs are eventually copied to the device. Without these blobs, CyanogenMod may build without error, but you’ll be missing important functionality, such as graphics libraries that enable you to see anything!

Turn on caching to speed up build

Add a comment to this section

You can speed up subsequent builds by adding

export USE_CCACHE=1

to your ~/.bashrc file (what's a .bashrc file?). Then, specify the amount of disk space to dedicate to ccache by typing this from the top of your Android tree:

prebuilts/misc/linux-x86/ccache/ccache -M 50G

where 50G corresponds to 50GB of cache. This only needs to be run once and the setting will be remembered. Anywhere in the range of 25GB to 100GB will result in very noticeably increased build speeds (for instance, a typical 1hr build time can be reduced to 20min). If you're only building for one device, 25GB-50GB is fine. If you plan to build for several devices that do not share the same kernel source, aim for 75GB-100GB. This space will be permanently occupied on your drive, so take this into consideration. See more information about ccache on Google's android build environment initialization page.

Start the build

Read comments on this section

Time to start building! So now type:

$ croot
$ brunch toroplus

The build should begin.

Helpful Tip

If the build doesn't start, try lunch and choose your device from the menu. If that doesn't work, try breakfast and choose from the menu. The command make toroplus should then work.

Helpful Tip

A second, bonus tip! If you get a command not found error for croot or brunch or lunch, be sure you’ve done the “ . build/” command in this Terminal session from the ~/android/system directory.

If the build breaks...

Add a comment to this section
  • If you experience this not-enough-memory-related error...
ERROR: signapk.jar failed: return code 1make: *** [out/target/product/toroplus/] Error 1 may want to make the following change to:

$ system/build/tools/releasetools/

Change: java -Xmx2048m to java -Xmx1024m or java -Xmx512m

Then start the build again (with brunch).

  • If you see a message about things suddenly being “killed” for no reason, your (virtual) machine may have run out of memory or storage space. Assign it more resources and try again.

Install the build

Add a comment to this section

Assuming the build completed without error (it will be obvious when it finishes), type:

$ cd $OUT

in the same terminal window that you did the build. Here you’ll find all the files that were created. The stuff that will go in /system is in a folder called system. The stuff that will become your ramdisk is in a folder called root. And your kernel is called... kernel.

But that’s all just background info. The two files we are interested in are (1) recovery.img, which contains ClockworkMod recovery, and (2) cm-[something].zip, which contains CyanogenMod.

Installing recovery using fastboot

See All About Recovery Images for more information about custom recoveries and their capabilities.

  1. Make sure your computer has working fastboot and adb.
  1. Connect the Galaxy Nexus (Sprint) to the computer via USB.
  2. Make sure the fastboot binary is in your PATH or that you place the recovery image in the same directory as fastboot.
  3. Open a terminal on your PC and reboot the device into fastboot mode by typing
    adb reboot bootloader
    or by using the hardware key combination for your device while it is powered off.
  4. Once the device is in fastboot mode, verify your PC sees the device by typing
    fastboot devices
    • If you don't see your device serial number, and instead see "<waiting for device>", fastboot is not configured properly on your machine. See fastboot documentation for more info.
    • If you see "no permissions fastboot", make sure your UDEV rules are setup correctly.
  5. Flash recovery onto your device by entering the following command:
    fastboot flash recovery your_recovery_image.img
    where the latter part is the filename of the recovery image.
  6. Once the flash completes successfully, reboot the device into recovery to verify the installation.
    • Note: Some ROMs overwrite recovery at boot time so if you do not plan to immediately boot into recovery to install CyanogenMod, please be aware that this may overwrite your custom recovery with the stock one.

Install CyanogenMod

Add a comment to this section

Back to the $OUT directory on your computer-- you should see a file that looks something like:


The above file name may vary depending on the version of CM you are building. Your build may not include a version number or may identify itself as a "KANG" rather than UNOFFICIAL version. Regardless, the file name will end in .zip and should be titled similarly to official builds.

Now you can flash the file above as usual via recovery mode. (Be sure you have backed up any previous installation before trying your new build.)

Success! So....what's next?

You've done it! Welcome to the elite club of self-builders. You've built your operating system from scratch, from the ground up. You are the master/mistress of your domain... and hopefully you've learned a bit on the way and had some fun too.

Now that you've succeeded in building CyanogenMod for your device, here are some suggestions on what to do next.

Also, be sure to take a glance at the Dev Center on this wiki for all kinds of more detailed information about developer topics ranging from collecting logs, understanding what's in the source code directories, submitting your own contributions, porting CyanogenMod to new devices, and a lot more.

Congrats again!

To get assistance

Add a comment to this section
  • #cyanogenmod-dev - A helpful, real-time chat room (or “channel”) on IRC- the Internet Relay Chat.