How I Built a ROM from Source (Hopefully?)

flapjack.fiasco

Well-known member
Sep 13, 2011
776
102
0
Visit site
WHERE DO ROMs COME FROM?
​-
I built Android from source once. Once. Haven't done it since, but I've been itchin' to. Real bad. I mean, what's better than seeing your own name printed in one lonely section of the system settings, which no one's going to see unless you show them? I'll tell you: Nothing. Nothing is better. Seriously though, building Android from source is surely the zenith of Android customization. Follow along with me as I fail repeatedly, and completely misunderstand what I'm supposed to be doing. I'm going to document every step I take along the way. All I ask of you is that you correct me when I'm wrong, because I will be, and lead me to better practices if you know any, because you likely know more than I do.

** DISCLAIMER **
I don't know what I'm doing. I'm serious. I've done research, I've asked questions, and what I'm telling you worked for me (hopefully). That, by no means, guarantees that it will work for you. Be careful. I barely know my way around Linux. I took a Linux systems administration course about 3 years ago, but I've only used it on and off since then for various reasons. This means that some of the things I do will be blindly following the direction of others. If you're following along at home, do some additional research on your own. Some of the steps I take may end up being superfluous, or even unintentionally malign. These errors will be corrected as I find them by my own research, or as I am made aware of them by others. Underlying point of all of this: I'm going to make mistakes. Please be careful not to make the same mistakes as me.


SO, HOW DO WE GET STARTED?

That's a great question! Where do we get started? Research. Always research before you do anything. Hopefully this thread will become a primary resource for help in building ROMs for the Optimus V, because that will mean that I succeeded. On the other hand, if I fail, everyone will know what not to do. Win/win, right? Moving along, my own research informs me that the first step is...


I. SETTING UP THE BUILD ENVIRONMENT

First things first, if you want to build Android, you can't use just any operating system. Well, sort of. You must use Linux, however you can run Linux in a virtual machine on Windows. It is my understanding that it's going to take a lot more time to compile using a virtual machine, so I'm choosing to dual-boot Windows and Linux. Since this thread is going to document my attempt at building Android from source, the resulting instructions will be based on the method I used. Other methods will not be documented, but links might be provided to alternate methods where appropriate.

There are so many different Linux distributions to choose from, but the choice, for me, was pretty easy. Since my goal is to build Android from source, I need a distribution that is likely to have the most number of users who have tried to do the same. The more attempts to build on a particular OS, the more likely it is that there's a forum thread or blog article addressing whatever issue I might run into. DistroWatch gives me some idea of the number of users on any particular distribution, and the top two are Mint and Ubuntu. Seeing that Mint is based on Ubuntu, and that it uses the Ubuntu repositories, it follows that most of the forum topics and blog posts are going to be in terms of Ubuntu. I'm going to try to use the current release, 13.04. Once the OS is done, there's still a lot of software that needs to be installed in order to build. I'm following the build environment setup instructions given in this thread on XDA: [GUIDE] How to Configure Ubuntu 13.04 Raring Ringtail for Compiling Android ROMs.





  • Install OS
    Download Ubuntu: Download Ubuntu Desktop (Make sure to get the 64-bit version)
    NOTE: If you want to try to build on a 32-bit machine, here's a link to some instructions, which I have not tried myself, but may help you to get that going: Building latest AOSP 4.2.2_r1 from source, using 32 bit Ubuntu 12.04
    Make a bootable USB-Drive/DVD-ROM: I used the Universal USB Installer to make a bootable flash drive.
    Reboot.
    Boot off of the flash drive/DVD-ROM.
    Follow the on-screen instructions to install Ubuntu alongside Windows.
    -
  • Install JDK
    First, we need to add the correct repository.

    There's going to be lots of terminal use here, so if you're not that familiar with using the terminal, here's a cheat sheet for you: Linux Terminal Command Reference

    Open a terminal and type the following and press enter:
    Code:
    sudo add-apt-repository ppa:webupd8team/java
    Press enter when prompted.
    This repository will allow you to perform the next step.

    Now type this into the terminal, followed by enter:
    Code:
    sudo apt-get update && sudo apt-get install oracle-java6-installer
    Agree to install the JDK, and accept any agreements. This took about 8 minutes (@~175kB/s) for me. Once the installation finishes, that's it, you've installed the JDK.

    If you'd like to check, you can enter the following command in order to display your current version of Java:
    Code:
    java -version

    This was the output I got from the command:
    Code:
    java version "1.6.0_45"
    Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
    Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

    NOTE: For those of you who might already have OpenJDK installed, I've read that it can be a pain to work with when compiling Android. I have not successfully built a ROM using OpenJDK. That does not mean that it is not possible. I believe that EarthnFire78 uses OpenJDK for building his ROMs, but I'm not positive. Point is, if you wish to follow these instructions precisely as laid out here, your gonna want to stick with Oracle's version of the JDK. Here's a command to remove OpenJDK if you already have it installed:

    Code:
    sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
    -
  • Install the Build Dependencies
    You can copy and paste the following long command into the terminal and then press enter:
    Code:
    sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python

    This command took about 35 minutes to complete on my box.

    Here's a list of all the individual components you need to install, for reference:
































    Then, create a symbolic link to /usr/lib/i386-linux-gnu/mesa/libGL.so.1 by entering the following into the terminal:
    Code:
    sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
    -
  • Setup Repo and Sync with a Repository
    Next step, make a new directory, download repo to it, and then make repo executable. All of that can be done with the following command. Type or copy and paste it and press enter:
    Code:
    mkdir ~/bin && curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo && chmod a+x ~/bin/repo

    The next step is to add ~/bin to your path variable. To edit it in terminal, type the following and execute:
    Code:
    sudo nano ~/.bashrc
    --OR--
    To do it in a GUI editor, do the following instead:
    Code:
    sudo gedit ~/.bashrc

    Whichever method you're comfortable with will work, they both have the same effect. Once you have ~/.bashrc open in either nano or gedit (or whatever editor you like), add the following line to the very bottom:
    Code:
    export PATH=~/bin:$PATH
    Write out in nano, or save and close in gedit.

    If you omit this last step, when you go to execute repo init, you'll get an error like the following:
    Code:
    No command 'repo' found, did you mean: Command 'repl' from package 'mailutils-mh' (universe)
     Command 'repl' from package 'nmh' (universe)
     Command 'repro' from package 'repro' (universe)
     Command 'rep' from package 'rep' (universe)
    repo: command not found
    So don't skip this step. Skipping the next step will give you the same error, so don't miss it either.

    Now that you've edited ~/.bashrc, save it and close it.

    Type the following command to make those changes apply to the current terminal session:
    Code:
    source ~/.bashrc

    At this point, your system is setup to build any (I think) recent branch of Android. The instructions that follow will be specific to Gingerbread, but following that will be instructions on what needs to be done differently for Ice Cream Sandwich or Jelly Bean.

    Time to make a directory to hold all the source files you're about to download. Find a location, generally in your home folder, or a subdirectory of your home folder. Here, I'm going to make a directory called 'android' in my home folder. I'll do that with the following command:
    Code:
    [COLOR=#222225]mkdir ~/android/gingerbread[/COLOR]

    Now that we've made a place to save the source, let's move to it, and use repo to download all the source code for the particular branch I'm going to build. For this first attempt, I'll try Gingerbread. The repo I'm going to use is Superior Irken Organs (thanks to Earthnfire78!). To begin, we need to setup the email address and name for git, so enter the following:
    Code:
    git config --global user.email "you@example.com"
    git config --global user.name "Your Name"

    Git is now configured, so let's download the source! Move to the directory you created for the source code, and repo init, then sync. Modify the -j option as depending on the number of cores your processor has. I've seen -j16 recommended for an 8 core processor, so you'd probably want to use a lower number if you have less cores. I went with -j16, but I'm not sure if that helped or hurt me:
    Code:
    [COLOR=#222225]cd ~/android/gingerbread
    [/COLOR][COLOR=#222225]repo init -u git://github.com/SuperiorIrkenOrgans/android.git -b gingerbread
    [/COLOR]repo sync -j6
    This is going to take a long, long time, depending on how fast your downstream transfer rate is. My cheap AT&T internet access (the only service available where I live) tops out at around 180 kB/s. It ended up taking almost 7 hours to download everything. For many of you, it won't take nearly as long. I used to have a 22 Mbps line, and it only took an hour or so to download at that speed.
    -
  • Build It!
    This it it! Time to build that ROM. This is also generally where things start to get sticky. I ran into a problem here that I hope none of you have to contend with, but with the help of the community, it was sorted out. I'll go over the required commands, and then describe the problem I encountered, and how to fix it. If anyone else has problems, post about it in this thread, and if a solution is found, I'll add it to the list of possible problems.

    So here we go. Start by ensuring you're in the directory you created to store the source:
    Code:
    cd ~/android/gingerbread

    After you're sure you're in the right directory, execute the following commands:
    Code:
    source build/envsetup.sh
    This loads all the variables and functions in the envsetup.sh script, so that they can be used to setup for executing 'make'. One of those functions is 'lunch'.


 
Last edited:

flapjack.fiasco

Well-known member
Sep 13, 2011
776
102
0
Visit site
nice xda link for up-to-date Ubuntu info.
I've only built under Debian 6 (squeeze) and Ubuntu 10.04.

I think it was Ubuntu 10.04 that I was using when I built Backside forever ago. Can't wait to see how it turns out this time. I think I'm going to try GB first, and then move up through the versions as my understanding grows.

Sent from my LG-VM670 using Tapatalk 4 Beta
 

flapjack.fiasco

Well-known member
Sep 13, 2011
776
102
0
Visit site
Sorry about no postings last night, one of my kids was sick. Should get to work on things tonight.

Sent from my LG-VM670 using Tapatalk 4 Beta
 

flapjack.fiasco

Well-known member
Sep 13, 2011
776
102
0
Visit site
Going to add a little more tonight. Sorry for the slow progress, it'll pick up a little on my days off. Long shifts with my boss on vacation and a sick kid (who is all better now).

Getting back on topic though, I need to research which repositories are available for each branch. If anyone wants to post links of any they are aware of, please do, it will be appreciated much.
 

flapjack.fiasco

Well-known member
Sep 13, 2011
776
102
0
Visit site
I added links to all the build dependencies. Hopefully this will provide a little information as to what each one does, if anyone is interested.
 

flapjack.fiasco

Well-known member
Sep 13, 2011
776
102
0
Visit site
I get the impression that all of the build dependencies I have listed are required for building Jellybean, but not all of them are needed for building the other branches. I have 47 dependencies listed above, but in the Building Your Own ROM thread, there's only 19 build dependencies listed.
 
Feb 19, 2011
1,971
284
0
Visit site
ugh, 64 bit. one of these days I'll be able to afford one of those.
For now, I have to modify the dependencies list to suit my 32 bit system.
I'd list the necessary tools, but I only get to see the changes when I reformat my system and have to reinstall everything. Hasn't happened for oh, two months or so.
straight AOSP needs modded to build on 32 bit, but CM cooperates ok in my experience.
 

flapjack.fiasco

Well-known member
Sep 13, 2011
776
102
0
Visit site
ugh, 64 bit. one of these days I'll be able to afford one of those.
For now, I have to modify the dependencies list to suit my 32 bit system.
I'd list the necessary tools, but I only get to see the changes when I reformat my system and have to reinstall everything. Hasn't happened for oh, two months or so.
straight AOSP needs modded to build on 32 bit, but CM cooperates ok in my experience.

So, are you saying that the additional dependencies are all 64-bit related? I haven't done a side-by-side comparison of the two lists yet, but I'd like to include as much useful info as possible. If I can find a list of dependencies to enable 32-bit building, I'd love to do that.
 

flapjack.fiasco

Well-known member
Sep 13, 2011
776
102
0
Visit site
Okay then, if no one else has any suggestions for repositories, I'll go with S.I.O.. I'm going to be trying this out with different branches later, so the guide will incorporate ICS, and JB as I attempt to build them. First things first though, it's Gingerbread time!
 

tvall

Well-known member
Nov 27, 2011
591
353
0
Visit site
My repo is quite outdated. Stick with sio (and maybe merge in some of my changes)

Sent from my Evo V 4G using Tapatalk 2
 

tvall

Well-known member
Nov 27, 2011
591
353
0
Visit site
ugh, 64 bit. one of these days I'll be able to afford one of those.
For now, I have to modify the dependencies list to suit my 32 bit system.
I'd list the necessary tools, but I only get to see the changes when I reformat my system and have to reinstall everything. Hasn't happened for oh, two months or so.
straight AOSP needs modded to build on 32 bit, but CM cooperates ok in my experience.

I have a spare core2duo board. Its old and slow, but its 64bit capable and dual core. If you live near me, or can afford shipping, I'll give it to you in exchange for a drink.

Sent from my Evo V 4G using Tapatalk 2
 

flapjack.fiasco

Well-known member
Sep 13, 2011
776
102
0
Visit site
Running into some problems now. My machine appears to be crashing during the execution of 'make'. The first time, I used 'make -j2 bacon', and came back to the computer a little while later to find it powered down. I did a little research, and found that it could possibly be a problem with parallel processing, so I left out the 'j' option, running 'make bacon' instead. This produced the same results.

So I'm wondering if anyone has experienced this, and if so, what approach was taken? I imagine that there's some sort of log that gets created during a crash, or that it's possible to set up a logging process. Any advice or direction would be greatly appreciated!
 

tvall

Well-known member
Nov 27, 2011
591
353
0
Visit site
I have never seen a machine power off during a compile. Only thing I can think of is overheating.

Overclock your fans. Might help.

Sent from my Evo V 4G using Tapatalk 2