Although you can download most Android ROMs in ready-to-flash form, there are some benefits to learning how to build ROMs from their source code. The major benefit is that you’ll always be able to access the very latest version of the ROM before it’s packaged ready for ‘general release’ – although be warned that the most up-to-date version of a ROM’s code isn’t always going to be the most stable. You can also make significant changes to a ROM’s code before compiling it, and the experience of compiling a ROM will give you a deeper insight into how Android works ‘under the hood.’
This tutorial shows you how to build your chosen ROM from source, using the Architekt virtual machine (VM). Architekt is a handy, single download that includes many of the tools and packages you’ll need to start compiling ROMs. This tutorial is based on Mac, although Architekt works on Windows and Linux, too.
This tutorial concentrates on setting up the Architekt virtual machine and downloading the source for your chosen ROM, but it also provides a brief overview of how to prepare your ROM ready for flashing to a device. Because of the variety of Android ROMs and devices available, this is only a general outline – always check the instructions for your particular ROM and device, especially if you’re planning to flash the ROM after you’ve built it.
For more in-depth tutorials, make sure to check out the new issue of Android Magazine.
Choose your ROM
Find the GitHub repository that contains the ROM you want to build. The easiest method is to Google the ROM followed by “GitHub” (“Cyanogenmod GitHub.”) Most GitHub repositories contain multiple branches, so the next step is deciding which branch contains the version of the ROM you want to build.
Choose your branch
The easiest way of choosing which branch to compile is to click the Branches tab and look in the Active branch section. Alternatively, check the ROM’s website or blog for clues about what’s included in each branch. Once you’ve chosen your branch, make a note of its URL.
Import Architekt VM
Launch VirtualBox, then open its File menu and select Import Appliance. Click the little ‘Choose a virtual appliance file to import’ icon that appears alongside the empty textbox, then navigate to the unzipped Architekt folder. Select the architekt.ovf file, and click Open. Click Continue>Import.
Launch your VM
Once Architekt has loaded, click the Start icon. In the Terminal, select Arch Linux and hit the Return key on your keyboard. When you’re prompted to login, enter the username ‘android’, then press Return. Enter the password ‘android’ and press Return again. The virtual machine will then load.
Open the Terminal
You’ll see a few icons towards the bottom of your virtual machine. Click the ‘Terminal’ icon; this is how you’ll communicate with GitHub. Start by entering your name (git config –global user.name “Name”) and email address (git config –global user.email “email@example.com”) Next, you’ll prepare your repository.
Initalise your repo
Enter the command: ‘repo init -u git://github.com/’ followed by the URL of your branch, for example: ‘repo init -u git://github.com/CyanogenMod/android.git -b cm-11.0.’ Press Return and you should see a message that the repo has been initialised in ‘/home/android.’
Download the sources
You can now download the ROM from source, which may take a few hours. Run the command “repo sync,” and be prepared to wait. Once the sources have eventually downloaded, ensure your Terminal is pointing at the source’s root by issuing the command ‘cd android/system.’
Download device config
You now need to download the configuration and kernel source for your specific device. Run ‘source build/envsetup.sh,’ followed by ‘breakfast (device name).’ The next step is extracting the proprietary, binary blobs from your device, so attach your device to your computer using the USB cable.
Enable USB debugging
Ensure your device has USB debugging enabled. The location of these files varies between devices, so you’ll need to do some Googling to work out where you should point the Terminal. Extract the files using ‘ ./extract-files.sh,’ and then build your ROM with the following command ‘brunch (device name).’