Building Snappy Android for Galaxy Nexus

Build Environment

If you do not have a build environment setup, I strongly suggest you read Setting Up Your Build Environment first.

Unlocking the phone

Congratulations on completing the initial setup before building. Now we can focus on the actual build process.... in a minute. First the phone has to be unlocked so we can get access to internal files and eventually to replace the stock recovery (if it’s still there).

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

  1. Enable USB debugging on the device.

  2. Connect the device to the computer through USB.

  3. From a terminal on a computer, type the following to boot the device into fastboot mode:

  4. $ adb reboot bootloader

  5. From the same terminal, type the following command to unlock the bootloader (under Linux, you must be root):

  6. $ 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 need to re-enable USB debugging.

Downloading the Android source code

    Install repo

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

    $ curl > ~/bin/repo

    $ chmod a+x ~/bin/repo

    Initialize the repo

    Enter the following to initialize the repository:

    $ cd ~/android/system/
    $ repo init -u git://
    robustUTEP/android.git -b Snappy-11.0

    The argument after -b is the branch to be downloaded. To see which branches are available from Robust, please see:

    Note: Ubuntu 10.04's repositories include only an earlier version of git. If you see some error about needing a newer version, then you will need to add some custom repositories to get it to work. So if repo init fails:

        $ sudo add-apt-repository ppa:git-core/ppa

        $ sudo apt-get update

        $ sudo apt-get install git

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

    $ repo sync

    This command will run for some time.

    *Optional Tip:

    I created an executable script within my bin directory that would play a sound which I named myAlert  (I installed mpg123 and I downloaded an mp3 of an alert    sound that I fancied, the script just combines the two into a single command). In addition to the repo, and upcoming breakfast, and brunch commands, I added the following to each command so my alert noise would play, alarming me to the fact that the long process has finally completed:

    $ <comand>; myAlert


    $ repo sync; myAlert

    This is completely optional, however I felt a bell of some sort really helps when you’re probably AFK after being bored by the exciting-as-paint-drying action of the aforementioned commands.

    A Note about Errors after this point

    As I mentioned earlier, the directory hierarchy for building CyanogenMod is very fragile. Executing repo sync in any folder besides ~/android/system will cause scripts downloaded and run after this point to call incorrect commands to non-existent folders. It is even possible to continue and build without completing some of the following, BUT THAT WILL LEAVE YOU WITH AN INVALID OPERATING SYSTEM ON YOUR PHONE. (Sorry for the caps, but it needs to be said) Basically you'll have a phone that doesn't work because the wifi and wireless data drivers weren't initialized correctly. 

    In Short, follow the instructions here exactly, or else your CyanogenMod builds will secretly fail, meaning you could go all the way to installing your build before realizing your error came from e.g. step 2.

    After you've downloaded the android source code:

    The suggested cache size is 50-100GB. You will need to run the following command once you have downloaded the source code:

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

    When building Ice Cream Sandwich (4.0.x) or older, ccache is in a different location:

    $ prebuilt/linux-x86/ccache/ccache -M 50G

    This setting is stored in the CCACHE_DIR and is persistent.

    Starting the Build (finally!)

    Get the prebuilt apps


    $ 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.

    If get-prebuilts throws a signature not found error, I followed this suggestion and it fixed it.

    Run breakfast

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

    $ source build/ $ breakfast maguro

    (Remember to use '; myAlert' with the breakfast and brunch commands so you can be alerted when these long commands complete)

    Note: repo's breakfast command requires the latest version of repo to run without errors, to get

    this version, run with admin privileges:

    $ sudo repo selfupdate

    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:

    Extract Proprietary Blobs

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

    $ ./

    You should see the proprietary files (aka “blobs”) get pulled from the device and moved to the right place in the vendor 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 the branch of CyanogenMod you wish to build your own version of for the script to function properly (or stock). If you are savvy enough to pull the files yourself off the device by examining the script, you may do that as well without flashing CyanogenMod first.


    It’s important that these proprietary files are properly extracted and moved to the vendor directory. Without them, CyanogenMod will build without error, but you’ll be missing important functionality, such as the ability to see anything!

    Build, Build, Build

    Let's continue building! Ensure you are in the root of the source code (cd ~/android/system), then type:

    $ croot $ brunch maguro

    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 maguro 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.

    Once the Build is done

    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. It should look something like the following, possibly even including your username:

    Push the update files to the phone

    With the phone connected to the computer, and while in the $OUT directory, run the following:

    $ adb push cm-*.zip /sdcard/

    That command should work (take note of the dash in 'cm-' as using an underscore will yield a different zip file that can't be used to install CM on your phone), however, if that does not work, replace the wild card (*) with the actual file name from the out directory.

    At this point, you also want to push the correct Google Apps file to the phone as well. Be sure to download the correct version of google apps; a convenient table that matches CyanogenMod versions with the correct google apps can be found here (at rootzwiki).

    To download the file, you can get it here (ignore the table at the top of the page and download the correct file from the bin found below the table according to the version needed according to the rootzwiki link above).

    While in the folder where the gapps-[something].zip file resides, use the following command, again, replacing the wild card with the correct file name if necessary:

    $ adb push gapps*.zip /sdcard/

    Installing ClockWorkMod (CWM) Recovery

    You can skip to the next section about installing CyanogenMod if your phone already has ClockWorkMod or some other custom recovery flashed.

    You can use fastboot to install your recovery image to the device.

    1. Connect the Galaxy Nexus (GSM) to the computer via USB.

    2. Make sure the fastboot binary is in your PATH or that you place the downloaded 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.

    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.

    5. Flash ClockworkMod Recovery onto your device by entering the following command: fastboot flash recovery your_recovery_image.img where the latter part is the name of the file you downloaded.

    6. Once the flash completes successfully, reboot the device into recovery to verify the installation. This can be done by typing fastboot boot your_recovery_image.img.

      • 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. This shouldn’t be a problem if you’ve pushed the install files in the previous section.

    Installing CyanogenMod via CWM recovery mode

    You should now be in the ClockWorkMod recovery menu. Use the volume buttons to move up and down and use the power button to select options (although, you probably already knew that).

    1. From this menu, select backup and restore to create a backup of your phone before installing a new build (just in case). This should be a mandatory step in the process, unless you're absolutely sure the build will work (or if you just like to live dangerously).

    2. Select the option to wipe data/factory reset.

    3. Select install zip from sdcard.

    4. Select choose zip from sdcard.

    5. Select the CyanogenMod file you placed on the sdcard. You will then need to then confirm that you do wish to flash this file.

    6. Repeat steps 4 and 5 but with the google apps update package that you pushed to the phone.

    7. Once the installation has finished, return back to the main menu, and select the reboot system now option. The device should now boot into CyanogenMod.

    If the phone does not reboot to CyanogenMod and hangs at any of the boot splash screens, there is a problem. Remove the battery and enter fastboot mode by holding down the volume up, volume down, and power buttons until the phone vibrates. In fastboot mode, enter recovery mode by selecting the option using the volume buttons. Select backup and restore again and restore the backup image that you created in step one from this section (you did do step one, didn't you?). Try rebooting the phone at this point to make sure it still works, then return to recovery mode and try installing CyanogenMod with the instructions above but skip step 6. If this still doesn't work, there is a problem with the build - sorry, better luck next time.

    If the phone boots but keeps displaying a popup that explains that the android keyboard has stopped working (if you can't read the popup from disappearing so quickly, then this applies to you as well), then you have the wrong version of Google apps installed. With the phone on, go to Settings > About Phone and double check which version of android you have built and take note of it. Then please return to the section above about downloading Google apps and double check you have the correct version. Try running the steps above again. (The previous paragraph explains how to enter recovery mode from the phone being turned off).