Well, we're not really going to build a robot, but we will build the software the you could install on a robot, and that same software has a robot as the logo! I'm sure you've probably guessed what we're going to do, but I'll type it anyway: We are going to compile an Android distribution.
In this post we're gonna build the gingerbread version of android on a ubuntu 10.04 dev box. The outline is as follows:
- Installing prerequisite pakages
- Downloading and updating the repo tool
- Downloading the source
- Setting environment variables
- Compiling the source
- Running the emulator (DROID!)
Installing Prereqs
# apt-get install bison flex gperf git-core gnupg zip tofrodos \
> build-essential g++-multilib libc6-dev libc6-dev-i386 ia32-libs mingw32 \
> zlib1g-dev lib32z1-dev x11proto-core-dev libx11-dev \
> lib32readline5-dev libgl1-mesa-dev lib32ncurses5-dev
Any packages already installed will be skipped, and some existing packages might be upgraded.
Next comes good old Java, which personally can be a thorn in my side, esp. on windows, and this was no different, but I digress. It appears that the Sun Java packages have been removed from the canonical archive, so we will have to add them from a different repository. add this repository if you don't already have it, then we'll update the package database, and finally install java (thnx to dipin @ Happy Coding for that one :-) )
# add-apt-repository ppa:ferramroberto/java
# apt-get update
# apt-get install sun-java6-jdk
And in case your wondering, yes you need Sun's Java 6 JDK, OpenJDK won't work.
That's it for prereqs, on to the repo tool!
Repo
No, repo doesn't tell the bank where your car is so they can reclaim it, but it is a script tool used for making it easier to work with git when working with the AOSP.
At this point, you should be inside the directory where you would like the source code downloaded to, your working directory. mine is ~/android/gingerbread. We will download the repo tool using curl and set it to be executable as follows
# curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > /bin/repo
# chmod a+x /bin/repo
Note: I didn't include curl in the prereqs b/c technically it isn't a prereq for building the AOSP,and the Ubuntu 10.04 I downloaded came w/ curl. Nonetheless, you can install it with
# apt-get curl
Downloading The Source
We are making progress! Now that repo is downloaded, we will update with repo init and download a copy of the manifest:
# repo init -u https://android.googlesource.com/platform/manifest -b gingerbread
the -b switch is to tell repo that we only want the gingerbread branch, not the top (or "master") branch, which may not compile. You will likely be prompted for a name and email address, google recommends your real name and email address, so if you make contributions you can be credited for your work, and you need a real email address to use the code-review tool as well. The choice is yours.
Now you should have seen a confirmation msg about repo being initialized to whatever directory you're currently in. The next step is to sync the branch of the repository with the local directory you just made. If any of that sounds confusing, google 'git basics' to learn more on how the git utility works.
Before we sync our repository, however, we will do a quick nslookup on a couple of addresses. When syncing the repository, I repeatedly ran into errors about the tool not being able to resolve several addresses, including googlesource.com, which was insane b/c I was on that very webpage at the same time!
The proposed cause for my symptoms was that the sync did so many dns queries that my dns server couldn't handle it. My DNS was set to my m0n0wall box, running on Soekris hardware, so while it likely wouldn't be problem for my ISP that the m0n0wall forwards it's external dns queries to, it had to go through the m0n0wall, which did in fact choke out :-).
To work around that, I did what they suggested and ran an nslookup for two address:
# nslookup googlesource.com
# nslookup android.googlesource.com
After that, the repo synced w/out a hitch:
# repo sync
The gingerbread branch is pretty big, so this could take a few minutes depending on your internet connection.
Setting Environment Variables
Now you have the source! Take a look, see it, hear it, smell it! Only a few more steps before you are up and running. Next, we must set the environment variables for 'making' or compiling the source, and running the emulator. From your same working directory
# . build/envsetup.sh
# lunch
Whoa! we have a menu!
Compiling The Source
This one is short and sweet, using everyone's favorite command:
# make -j8
The -j switch specifies how many jobs to run in parallel. I have an older Centrino Duo, so 8 compiled it pretty fast (relatively speaking), but rendered that machine useless while it was compiling. Your results may vary. I think it took a little less than an hour, so I'll see you then :-)
Running The Emulator
Okay, the moment of truth! One simple command will take us to Android Gingerbread in all of it's glory!
# emulator &
I'm pretty sure the ampersand means accept all defaults. There are tons of switches, and since this is a wrapper for qemu, you can pass flags directly to qemu using the -qemu switch. Alright if all goes well you should see