08-24-2013 03:43 PM
32 12
  1. flapjack.fiasco's Avatar
    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.


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


    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.

    1. 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.
      Boot off of the flash drive/DVD-ROM.
      Follow the on-screen instructions to install Ubuntu alongside Windows.
    2. 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:
      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:
      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:
      java -version
      This was the output I got from the command:
      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:

      sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
    3. Install the Build Dependencies
      You can copy and paste the following long command into the terminal and then press enter:
      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:
      sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
    4. 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:
      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:
      sudo nano ~/.bashrc
      To do it in a GUI editor, do the following instead:
      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:
      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:
      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:
      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:
      mkdir ~/android/gingerbread

      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:
      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:
      cd ~/android/gingerbread
      repo init -u git://github.com/SuperiorIrkenOrgans/android.git -b gingerbread
      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.
    5. 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:
      cd ~/android/gingerbread
      After you're sure you're in the right directory, execute the following commands:
      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'.

    07-31-2013 11:43 PM
  2. flapjack.fiasco's Avatar
    I'm going to sleep after the install completes. I'll continue where I left off tomorrow evening. Night all!
    07-31-2013 11:50 PM
  3. upconvert's Avatar
    Very cool project. Keep us posted.
    flapjack.fiasco likes this.
    08-01-2013 09:12 AM
  4. bigsupersquid's Avatar
    nice xda link for up-to-date Ubuntu info.
    I've only built under Debian 6 (squeeze) and Ubuntu 10.04.
    flapjack.fiasco likes this.
    08-01-2013 11:28 AM
  5. flapjack.fiasco's Avatar
    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
    bigsupersquid likes this.
    08-01-2013 12:25 PM
  6. flapjack.fiasco's Avatar
    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
    08-02-2013 07:58 AM
  7. flapjack.fiasco's Avatar
    Little bit more added.
    upconvert likes this.
    08-03-2013 01:07 AM
  8. flapjack.fiasco's Avatar
    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.
    08-03-2013 10:27 PM
  9. flapjack.fiasco's Avatar
    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.
    badblue1__ and upconvert like this.
    08-06-2013 12:21 AM
  10. flapjack.fiasco's Avatar
    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.
    08-06-2013 10:22 AM
  11. bigsupersquid's Avatar
    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.
    08-06-2013 10:31 AM
  12. flapjack.fiasco's Avatar
    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.
    08-06-2013 12:03 PM
  13. bigsupersquid's Avatar
    not all of em, but everything with a '32' in it needs changed. Maybe others.
    flapjack.fiasco likes this.
    08-06-2013 01:06 PM
  14. flapjack.fiasco's Avatar
    Are there any VM670 GB repositories I need to consider looking into? This is what I've found so far:

    Superior Irken Organs
    Tvall (Magpie)

    I understand that the IHO repo is broken, and would need some modifications to build properly? Going to look into TheKraven's repos and see what he's got.
    08-06-2013 09:50 PM
  15. AndyOpie150's Avatar
    Superior Irken Organs is straight from the CM7 source code, not a fork of.
    flapjack.fiasco likes this.
    08-07-2013 06:43 AM
  16. flapjack.fiasco's Avatar
    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!
    upconvert and badblue1__ like this.
    08-08-2013 08:59 PM
  17. tvall's Avatar
    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
    08-09-2013 08:42 PM
  18. tvall's Avatar
    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
    08-09-2013 08:44 PM
  19. flapjack.fiasco's Avatar
    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!
    08-14-2013 10:17 PM
  20. tvall's Avatar
    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
    flapjack.fiasco likes this.
    08-15-2013 07:33 AM
  21. flapjack.fiasco's Avatar
    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
    Next time I try to build, I'll monitor the CPU temp while it's building to see if there's an unsafe increase. Thanks!
    08-15-2013 10:25 PM
  22. flapjack.fiasco's Avatar
    TheKraven and Bigsupersquid have both made suggestions that will help me to nail down the problem. Bigsupersquid suggested that I log the output from the terminal by adding a "> output.txt" to the end of the make command. Both said that they have had crashes during a build, one from hard drive issues, the other from RAM getting too full. TheKraven suggested that I increase the size of my swap partition to accommodate the needs of the build process. I'm going to do both of these things and see what happens. Thanks to everyone for all their help!
    upconvert and bigsupersquid like this.
    08-15-2013 10:30 PM
  23. flapjack.fiasco's Avatar
    So, because I didn't setup discrete partitions for all the system folders (i.e. just an ext4 / partition, and a swap), I had to reinstall Ubuntu to get an increased swap size. It's probable that there was a way to do it without reinstalling, but I tried Gparted, and it gave me a warning that moving the partition could cause boot issues. At any rate, my system is back up, with an increased swap partition, and I'm ready to start from scratch. No big deal, I just hope I've got a minute here or there to get everything ready for an overnight repo sync.
    badblue1__ and upconvert like this.
    08-16-2013 02:50 PM
  24. flapjack.fiasco's Avatar
    Even with the increased swap partition, it still crashed, although it seemed that it took a lot longer to crash. This is the last line of output it recorded:

    [33mtarget Dex:[0m FrameworksCoreTests
    Unless anyone has any ideas, I guess I'm gonna try again overnight and see if it stops at the same line or not. I can't imagine that the swap is not large enough, as I've got 4Gbs of RAM, and a 10 Gb swap partition. If anyone at all has any suggestions, I'm willing to give it a try. Or if anyone needs to see more of the output, I'll upload it somewhere (1.6 Mb txt file).
    08-17-2013 08:35 PM
  25. flapjack.fiasco's Avatar
    Thanks to TheKraven for fixing me on the real cause of my problem: heat. My little laptop was suffering without A/C in the Florida summer, and as it tried to do some of the more demanding parts of the build process, it simply overheated and shutdown. I had to put it on a cookie sheet, with a box fan in front of it, with an ice-pack situated wherever it seemed to be heating up.

    And that did it! Keeping it cool allowed it to finish building. I'm going to add all the details later today to the OP so hopefully no one else has to go through a similar process. But hey, it's done now! Time to start tweaking it and making it my own!
    08-20-2013 09:33 AM
32 12

Similar Threads

  1. Replies: 7
    Last Post: 08-06-2013, 03:54 AM
  2. how do you download a old version of android?
    By Zay92 in forum Android 4.1 / 4.2 / 4.3 Jelly Bean
    Replies: 1
    Last Post: 08-01-2013, 03:42 PM
  3. Replies: 2
    Last Post: 08-01-2013, 12:45 AM
  4. How are you supposed to crop a picture on facebook using nexus7
    By buryman in forum Google Nexus 7 Tablet (2012)
    Replies: 1
    Last Post: 07-31-2013, 08:15 PM