- 07-13-2012, 03:08 PM
Thread Author #1
[GUIDE][Ubuntu] Compiling Android from Source
Android is known for its ability to be customized by the end user. The typical way to do this is to flash a rom, which is essentially an "image" of the operating system plus other goodies that can give you entirely new look and a host of neat features to play with. But rom developers usually start at one point--"source."
Source is essentially the raw code of Android. Let's put it this way--if you want to make an omelete, you're going to have get some eggs, cheese, spices, etc. Those ingredients are source. You put those ingredients together and you get an omelet, or at least get you something close enough. Here's how we get to that point.
This guide is primarily for users of Ubuntu, particularly 64 bit. I will frequently use and mention several other guides that can help you if you are on other operating systems, particularly Mac OSX (check out the AOSP one first). If you are unfamiliar with Ubuntu/Linux, I advise you to read up a bit and become at least "moderately" familiar with how it works, particularly terminal and sudo/"root" permission commands.
Further, make sure you have enough space and adequate hardware to do this. I've seen recommendations of having at least a dualcore machine, with 2+ gb of RAM and at least 25-30 gigs of harddrive space free. Builds take up quite a lot of space, so you want to play it safe!
The first step in compiling Android is to create what's called a "build environment." Essentially, you're installing a bunch of software that will enable you to both sync up ("download") the source and to actually put together either flashable images or a flashable zip.
#1 Install the Android SDK
It is always best to have the Android SDK installed on your machine. Go to download the SDK package, extract it, and put it in your "home" directory. Be sure to follow the instructions and ensure everything is working properly. It's also good to triple-check that fastboot and ADB are both functional and usable.
.
#2 Install the Java Development Kit (JDK/Java 6)
Now let's get to to installing more important stuff. The first thing on the list is the JDK (Java 6), since that's the JDK required for compiling Gingerbread and all of the Android versions after. Obviously most of you will want to compile Jelly Bean, so this is crucial.
The recommended way to do this is to open up the terminal and type in these commands. Note, you can copy and paste the command (copy from "sudo" until the end) and make sure hit enter after each command!
If for some reasons that does not work, there are some alternatives, notably this:
If that does not work, and it may not due to licensing and support issues, either (1) Google search the issue by copying/pasting the command line error into Google (wrap it in quotes!), or (2) try to search for other alternatives repositories to add. We have several options in the fourth post (troubleshooting/fixes) as well as a few that have been mentioned throughout this guide. This is a bit of a wonky step, so don't let it get you down! Not your fault, just blame Google/Sun$ sudo apt-get install openjdk-6-jdk
.
#3 Install Python
Once the JDK is installed, you need to install Python. In some versions of Ubuntu (and I believe 12.04 is one of those versions, Python is already installed. Still, it doesn't hurt to double check!
Simply enter this command:
$ sudo apt-get install python#4 Install Git
Git is one of the coolest, yet most confusing things, about Android/Linux. Think of it this way--it's a place where all of the revisions to the code go to be approved and get incorporated so that you have a solid piece of working software.
For git, enter this:
$ sudo apt-get install git-core#5 Install the Required Packages
Once the JDK, python, and git are installed, you're ready to start installing some more "specific" packages required to compile Android.
If you're running Ubuntu (remember, 64 bit), and your version of Ubuntu is between 10.04 and 11.10, simply input this entire thing and hit enter:
If you're on Ubuntu 10.10, also input this:$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc
If you're on Ubuntu 11.10, you want to input this:$ sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so
You may also need this if you're on 11.10, so I'd recommend installing it anyway (and this may be duplicative, but don't worry, Ubuntu's smarter than she may sometime act!)$ sudo apt-get install libx11-dev:i386
If you're like me and you're on Ubuntu 12.04 (again, 64 bit!), there are two warnings that Google/Android gives us: (1) building on 12.04 is experimental, and (2) it's not guaranteed to work for any branch of the repository other than the master branch.$ sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
That being said, here are your packages:
And don't forget this...$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so#6 Configure USB Access
This step is important because it will enable to access pretty much any Android device by using your USB port (and your USB cable). First, let's bring up the file you'll need to "edit":
This will open up a text file. In that file, simply copy and paste this big ole list right into it, save it, and then close the file.$ gksudo gedit /etc/udev/rules.d/51-android.rules
Remember, be sure to save it and close it. Once closed, enter this command:#Acer
SUBSYSTEM=="usb", ATTR{idVendor}=="0502", MODE="0666"
#ASUS
SUBSYSTEM=="usb", ATTR{idVendor}=="0b05", MODE="0666"
#Dell
SUBSYSTEM=="usb", ATTR{idVendor}=="413c", MODE="0666"
#Foxconn
SUBSYSTEM=="usb", ATTR{idVendor}=="0489", MODE="0666"
#Garmin-Asus
SUBSYSTEM=="usb", ATTR{idVendor}=="091E", MODE="0666"
#Google
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666"
#HTC
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666"
#Huawei
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", MODE="0666"
#K-Touch
SUBSYSTEM=="usb", ATTR{idVendor}=="24e3", MODE="0666"
#KT Tech
SUBSYSTEM=="usb", ATTR{idVendor}=="2116", MODE="0666"
#Kyocera
SUBSYSTEM=="usb", ATTR{idVendor}=="0482", MODE="0666"
#Lenevo
SUBSYSTEM=="usb", ATTR{idVendor}=="17EF", MODE="0666"
#LG
SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666"
#Motorola
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666"
#NEC
SUBSYSTEM=="usb", ATTR{idVendor}=="0409", MODE="0666"
#Nook
SUBSYSTEM=="usb", ATTR{idVendor}=="2080", MODE="0666"
#Nvidia
SUBSYSTEM=="usb", ATTR{idVendor}=="0955", MODE="0666"
#OTGV
SUBSYSTEM=="usb", ATTR{idVendor}=="2257", MODE="0666"
#Pantech
SUBSYSTEM=="usb", ATTR{idVendor}=="10A9", MODE="0666"
#Philips
SUBSYSTEM=="usb", ATTR{idVendor}=="0471", MODE="0666"
#PMC-Sierra
SUBSYSTEM=="usb", ATTR{idVendor}=="04da", MODE="0666"
#Qualcomm
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666"
#SK Telesys
SUBSYSTEM=="usb", ATTR{idVendor}=="1f53", MODE="0666"
#Samsung
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666"
#Sharp
SUBSYSTEM=="usb", ATTR{idVendor}=="04dd", MODE="0666"
#Sony Ericsson
SUBSYSTEM=="usb", ATTR{idVendor}=="0fce", MODE="0666"
#Toshiba
SUBSYSTEM=="usb", ATTR{idVendor}=="0930", MODE="0666"
#ZTE
SUBSYSTEM=="usb", ATTR{idVendor}=="19D2", MODE="0666"
Now your build environment is complete and you're ready to download the repo/source and get crackin'. If you have any issues, I suggest checking out my sources as well as simply asking me/our community or Googling the issue. The best way to search for an error (that I have found) is to simply copy and paste the "error" from your terminal into Google and seeing what comes out. Adding in extra terms like "Android" "source" "compile" and "build" may also help.$ sudo chmod a+r /etc/udev/rules.d/51-android.rules
Last edited by dmmarck; 07-16-2012 at 11:39 AM.
Former moderator & advisor.
HTC - the One to rule them all.
Thanked by 48:+ Show/Hide list of the thanked -
2defmouze, adambpsu, ancorare, auburngirl, blz2, broadwayblues, chriscw81, chubb, Cory Streater, davidnc, deadmantfa, digitalslacker, DolfanCole, Droidintorrance, eclapham, fue9o, hedwig34, Jeff43, Jerry Hildenbrand, jjhiza, JkdJedi, Johnly, jstntp, Kevin Michaluk, KWKSLVR, networkproblems, Neutrino, nmyeti, NotJustAPhone, oxymoron, Paul627g, Phil Nickinson, phoenix_911, Promoman89, pxmm, redstar427, Roy J, rwong48, shimp208, Silent1, Skunkape60, svfd757, tmerril7, tonynotalk, Wicket, XANAX, XxPyromaniacXx, zero neck
- 07-13-2012, 03:09 PM
Thread Author #2
Re: [GUIDE] Compiling Android from Source for the Galaxy Nexus
The next "big" step once your build environment is "created" (installed) is to download the Android source code. This isn't necessarily difficult, it's just time consuming, sometimes taking 3 hours for everything to download. I recommend doing this when you know you have enough time to "babysit" it, because errors may creep up and you'll want to address those ASAP.
#1 Making the Repo
First, we want to make sure that you have a path for the repo to install to. Input these commands in terminal, just like you did with the prior steps.
Now, once that's finished, you download the repo script and ensure that it works (i.e. it's executable). Use these commands:$ mkdir ~/bin
$ PATH=~/bin:$PATH
Please make sure you copy and paste the whole thing. Ignore the fact that the link is live on here, treat it as if it's simply plain old text.
#2 Create your "Working Directory"
Once the above is finished, you'll want to create the directory that everything is going to download to and where your "rom" will eventually pop out after it is built.
First, enter this command.
$ mkdir WORKING_DIRECTORY
Note that you can make your "WORKING_DIRECTORY" whatever name you please. Some suggestions include "JB_SOURCE," "SOURCE_DIRECTORY," "ANDROID_AWESOME," etc. Simply substitute your chosen name for "WORKING_DIRECTORY" in the above command.
Then, you'll want to "change directory" to that directory you just created. Remember, if your directory is something other than "WORKING_DIRECTORY," use that name!
Simply input this command to change directory (go to that directory):
$ cd WORKING_DIRECTORY#3 Downloading the Source - The Long Haul
This step may take forever or it may take just an hour. Regardless, schedule your time appropriately!
Generally, you'll have two options--downloading the "master" branch of Android (it's basically everything), or downloading a specific branch. Now if you're on Ubuntu 12.04 like I am, remember that warning Google gave us--only the master directory is guaranteed!
To sync with/install the master source directory, input the following command:
If you wish to download a specific directory, say for this purpose Jelly Bean 4.1.1, use the following command:
Now, a prompt will come up asking for your real name and your address. Please use your real name and your real email address. If you ever take this hobby further and wish to submit code revisions to the AOSP, it would behoove you to stand by your name (so to speak
).
If you have already done a repo init and simply want Jelly Bean 4.1.1, try using these commands instead:
$ repo init -b android-4.1.1_r1
$ repo sync
Now, it's time to actually sync up with the source and grab a snack, a meal, or The Lord of the Rings Extended Blu-Ray Trilogy. Input the following command:
Sit back and relax and wait. If a fetch error comes up, I have found that the best way to get around it is to simply enter:$ repo sync
I will be troubleshooting other errors a bit later on.$ repo sync -f
#4 Verifying Git
Another good thing to do is verify the git tags. This is fairly simple.
First, enter this command:
Then, without closing a window or terminal, copy and paste the following into the terminal window.$ gpg --import
Hit control + D after you pasted and all is done. If you want to verify individual tags, simply use this command:-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
mQGiBEnnWD4RBACt9/h4v9xnnGDou13y3dvOx6/t43LPPIxeJ8eX9WB+8LLuROSV
lFhpHawsVAcFlmi7f7jdSRF+OvtZL9ShPKdLfwBJMNkU66/TZmPewS4m782ndtw7
8tR1cXb197Ob8kOfQB3A9yk2XZ4ei4ZC3i6wVdqHLRxABdncwu5hOF9KXwCgkxMD
u4PVgChaAJzTYJ1EG+UYBIUEAJmfearb0qRAN7dEoff0FeXsEaUA6U90sEoVks0Z
wNj96SA8BL+a1OoEUUfpMhiHyLuQSftxisJxTh+2QclzDviDyaTrkANjdYY7p2cq
/HMdOY7LJlHaqtXmZxXjjtw5Uc2QG8UY8aziU3IE9nTjSwCXeJnuyvoizl9/I1S5
jU5SA/9WwIps4SC84ielIXiGWEqq6i6/sk4I9q1YemZF2XVVKnmI1F4iCMtNKsR4
MGSa1gA8s4iQbsKNWPgp7M3a51JCVCu6l/8zTpA+uUGapw4tWCp4o0dpIvDPBEa9
b/aF/ygcR8mh5hgUfpF9IpXdknOsbKCvM9lSSfRciETykZc4wrRCVGhlIEFuZHJv
aWQgT3BlbiBTb3VyY2UgUHJvamVjdCA8aW5pdGlhbC1jb250cmlidXRpb25AYW5k
cm9pZC5jb20+iGAEExECACAFAknnWD4CGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIX
gAAKCRDorT+BmrEOeNr+AJ42Xy6tEW7r3KzrJxnRX8mij9z8tgCdFfQYiHpYngkI
2t09Ed+9Bm4gmEO5Ag0ESedYRBAIAKVW1JcMBWvV/0Bo9WiByJ9WJ5swMN36/vAl
QN4mWRhfzDOk/Rosdb0csAO/l8Kz0gKQPOfObtyYjvI8JMC3rmi+LIvSUT9806Up
hisyEmmHv6U8gUb/xHLIanXGxwhYzjgeuAXVCsv+EvoPIHbY4L/KvP5x+oCJIDbk
C2b1TvVk9PryzmE4BPIQL/NtgR1oLWm/uWR9zRUFtBnE411aMAN3qnAHBBMZzKMX
LWBGWE0znfRrnczI5p49i2YZJAjyX1P2WzmScK49CV82dzLo71MnrF6fj+Udtb5+
OgTg7Cow+8PRaTkJEW5Y2JIZpnRUq0CYxAmHYX79EMKHDSThf/8AAwUIAJPWsB/M
pK+KMs/s3r6nJrnYLTfdZhtmQXimpoDMJg1zxmL8UfNUKiQZ6esoAWtDgpqt7Y7s
KZ8laHRARonte394hidZzM5nb6hQvpPjt2OlPRsyqVxw4c/KsjADtAuKW9/d8phb
N8bTyOJo856qg4oOEzKG9eeF7oaZTYBy33BTL0408sEBxiMior6b8LrZrAhkqDjA
vUXRwm/fFKgpsOysxC6xi553CxBUCH2omNV6Ka1LNMwzSp9ILz8jEGqmUtkBszwo
G1S8fXgE0Lq3cdDM/GJ4QXP/p6LiwNF99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQ
hN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0l
EXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM=
=Wi5D
-----END PGP PUBLIC KEY BLOCK-----
Once finished, you will have all of Android on your harddrive. For me, that totalled 15.1 gigs, so like I said, be sure you have space! (...and time) (...or a TARDIS?)$ git tag -v TAG_NAME
Last edited by dmmarck; 07-14-2012 at 05:58 PM.
Former moderator & advisor.
HTC - the One to rule them all.
Thanked by 27:+ Show/Hide list of the thanked
- 07-13-2012, 03:09 PM
Thread Author #3
- 07-13-2012, 03:09 PM
Thread Author #4
Re: [GUIDE] Compiling Android from Source for the Galaxy Nexus
I will be putting in common questions/problems once they arise. For now, please reference the credited guides for any immediate support, or simply post up in here for help
.
Fixes/Tricks
Java6/JDK Issues:
Java6 sometimes does not play nice, even with the AOSP-given commands to get it. Here are some resources that may help you out in resolving any Java issues, may it be installation or making sure OpenJava works.
For installing the JDK ==>
- ;
- ;
- You can also try this method found here.
For any read/version errors (thanks khalid!) ==>
A version error looks like this:
Your version is: java version "1.6.0_24".
The correct version is: Java SE 1.6.
"Make"/find: 'src' Errors
To solve this, you can try updating your dependencies, or you can try . You'll want to install . Also see this post. Thanks ancorare and ewinkley!
Compiling CyanogenMod
Thanks to 2defmouze for the hat tip!
Last edited by dmmarck; 07-16-2012 at 07:13 PM.
Former moderator & advisor.
HTC - the One to rule them all.
Thanked by 11:+ Show/Hide list of the thanked
- 07-13-2012, 05:31 PM
Thread Author #5
Re: [GUIDE][Ubuntu] Compiling Android from Source
Feel free to post up in here with questions/comments!
- DFormer moderator & advisor.
HTC - the One to rule them all.
Thanked by 6: - 07-13-2012, 05:45 PM #6
- 07-13-2012, 05:53 PM #7
Re: [GUIDE][Ubuntu] Compiling Android from Source
You promised and you delivered. I love you bro!
It is better to be pissed off than to be pissed on! - 07-13-2012, 06:04 PM #8
Re: [GUIDE][Ubuntu] Compiling Android from Source
Wow. Simplistic. This is beautiful. I tried to read what I needed to do on AOSP site, and my eyes bled. This, once I get linux up, actually makes me think I might be able to do something. Thank you.
- 07-13-2012, 06:10 PM
Thread Author #9
Re: [GUIDE][Ubuntu] Compiling Android from Source
It's very simple, although if something goes awry it make took some improvisation. I essentially did it twice (aside from building the environment), so I got to run into a load of issues. I'll be adding some tricks to the troubleshooting section, as well as some other links to help out.
One thing I want to make clear though: this isn't necessarily complicated, it just takes time. But once you put in that time, there's nothing like seeing your name right there in the "About Phone." Trust me on that
.
Former moderator & advisor.
HTC - the One to rule them all.
- 07-13-2012, 07:34 PM #10
Re: [GUIDE][Ubuntu] Compiling Android from Source
Slick. Need ubunto.

*INCREDIBLE*MECHA*TORO*GROUPER* GALAXY S3 *
* [TORO RADIOS] * [NEXUS WALLS] * [GROUPER GUIDE] * [CHATTER] * - 07-13-2012, 09:00 PM #11
Thanks! I agree that other walkthroughs I have read just made my head hurt. This one seems like something I can handle. It will keep my inner geek satisfied for a bit. Next up? How to get started building apps. I know there was something about that a bit back.
For anyone looking to put Ubuntu on your Windows machine...
https://help.ubuntu.com/community/HowtoPartition
Sent from my ASUS Transformer Pad TF300TLast edited by auburngirl; 07-13-2012 at 09:05 PM.
- 07-13-2012, 09:03 PM #12
- 07-13-2012, 10:33 PM
Thread Author #13
Former moderator & advisor.
HTC - the One to rule them all.
- 07-13-2012, 10:51 PM #14
- 07-13-2012, 11:04 PM
Thread Author #15
Former moderator & advisor.
HTC - the One to rule them all.
- 07-14-2012, 12:50 AM #16
Re: [GUIDE][Ubuntu] Compiling Android from Source
/WORKING_DIRECTORY: should that go in /~ or /home or what?
(in my case I have /home mounted to a spinning hdd with / mounted to 64 gb ssd)
Do we need to flash a jelly bean bootloader?
Will building this make a rom that will rewrite the recovery upon reboot like some factory images do?
Can someone point to the best method for rooting this after installation? - 07-14-2012, 01:28 AM
Thread Author #17
Mine is in my home directory. You can really put in anywhere so long as you cd to it, although home directory is usually the standard place. I've seen and know of folks with different partitions and such for it, but that's a bit outside the scope of this guide.
No, you do not need to flash or use Jelly Bean bootloader but I do use it myself. It's recommended right now in most circles (please see the JB threads for more JB specific discussion), but I'd hesitate to use it if you plan on going back to ICS at any point.
Yes, it will replace recovery. Simply remove the recovery folder and two lines of code in the updater script that mention recovery, save, and it will not. Also, IIRC, there is also a file you need to remove or rename in /system to make a custom recovery stick. One of the credited guides mention the post compilation stuff with far more detail or expertise than I can, so I suggest browsing those as well. Alternatively, you may fastboot the custom recovery back.
Rooting is fairly straight forward - simply flash the appropriate superuser zip. If you want to make it stick and flashable by others, open up the superuser zip and take the app and place it into /system/app and take the binary and place it in /system/xbin. I prefer to rename the old su binary to "su old".
I will add a bit more explanation to the post rooting stuff after I go along and figure more out on my own. It's fun but tricky and it makes me appreciate the hard work that our devs do.
Also, thank God for SwiftKey.
Sent from my Galaxy Nexus using Xparent Cyan Tapatalk 2 - 07-14-2012, 02:40 AM #18
Re: [GUIDE][Ubuntu] Compiling Android from Source
Note: had to change "$ source build/envsetup.sh" to "# source build/envsetup.sh" because of "permission denied"
Also, ended up having to install sun java 6 from "bin", "jre", and "jdk" .deb packages pulled from a website called "debian snapshots". - 07-14-2012, 02:49 AM #19
- 07-14-2012, 09:03 AM #20
Re: [GUIDE][Ubuntu] Compiling Android from Source
man this is a nice guide. i'm going to have to boot over in to ubuntu and give this a shot...
- 07-14-2012, 09:19 AM #21
Re: [GUIDE][Ubuntu] Compiling Android from Source
thanks! i needed something to do on a rainy saturday morning
- 07-14-2012, 11:15 AM
Thread Author #22
Former moderator & advisor.
HTC - the One to rule them all.
- 07-14-2012, 02:13 PM #23
Re: [GUIDE][Ubuntu] Compiling Android from Source
First things first, thanks for the awesome guide.
When I use either of the make commands I get an error stating that I am "attempting to build with the incorrect version of java." It states that my version is 1.6.0_24 and the correct version is just 1.6. I followed the guide 100% and just copied and pasted the commands as you wrote them. Any ideas on the error? I am running Ubuntu 12.04 64-bit.
Thanks - 07-14-2012, 02:55 PM
Thread Author #24
Check this link if you're having java issues. Have you tried installing it again?
For whatever reason getting the JDK is the hardest part of this procedure. The open one should work, but right now the AOSP supplied method is...wonky.
I'd suggest reinstalling it and seeing if that helps. You synced with source right, that went by smoothly?
I'll look up your specific issue a bit later, but unfortunately I don't have personal experience with that problem
.
EDIT: check this link as well for troubleshooting/getting around Java 6/JDK issues!
Sent from my Galaxy Nexus using Xparent Cyan Tapatalk 2Last edited by dmmarck; 07-14-2012 at 03:01 PM.
- 07-14-2012, 05:10 PM #25
Re: [GUIDE][Ubuntu] Compiling Android from Source
Thanks for the guide!
I am using this guide and trying to build for the nexus 7 (grouper) with the nexus 7 drivers instead of the tuna drivers listed in this post. When I get to the lunch command and make my selection, i get a bunch of permission denied errors. I re-did this section of the guide, but did a sudo su command first to see if that cured the issues and it appears that it has. Android is building at the moment, so we'll see if it works.
Any ideas why i would have to be logged in as full root?



Reply




































