Compiling AOSP for your Nexus device on Mac OSX

  4 mins read

Requirements

  • 8GB of RAM, recommended 16GB
  • 100 gb of free space on your drive

Preparing the environment

First we need a case-sensistive file system, so we need to create a sparseimage because by default the OSX system is not case-sensitive

If we want to resize this image later we can do it by executing (just in case):

Install the following:

JDK7 (last revision) and MacPorts from macports.org
When Macports is installed, run the following in order to install the dependencies to compile AOSP:

Now we have to add some variables and some of them add to the PATH, so edit bash_profile:

And paste the following code:

Please note the 2 last lines, and replace the jdk1.7.0_79.jdk with the version of your installed version, if not the path will not be found.

To load the previous changes without re-run a terminal, run the following command:

You need Xcode 5.1.1 to compile AOSP, the latest one don’t works at least to build Lollipop (5.1), so go to the Developer center and download Xcode 5.1.1 image.

  1. Mount downloaded XCode5.1.1.dmg
  2. Right click on XCode and select Show Package Contents
  3. Create the folder /Developer/SDK
  4. Copy MacOSX10.8.sdk from Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ to /Developer/SDK
  5. Copy Xcode.app from the Xcode5.1.1.dmg to /Developer
  6. Eject & delete the .dmg

Let’s setup Xcode to use the old command line tools that we’ve downloaded in the previous step:

  1. Open up Xcode 6
  2. From the menu, select XCode -> Preferences…
  3. Click on the Location tab
  4. The last option, “Command Line Tools”, select “Xcode 5.1.1″

Downloading the source code

First, we are going to download “Repo”, is a tool to manage the source code from git developed by Google specially mind for AOSP. To do that run the following commands:

Mount the previous android image that we’ve created with the function that we installed in the bash_profile, you can also double click the sparseimage we created before.

Get inside the image with:

Create a working directory and enter inside:

Initialize the manifest (It has nothing to do with AndroidManifest.xml) repository with:

Checkout the desired branch, for the example I’m going to checkout “android-5.1.0_r5” but you can checkout whatever you want, here is a link of all branches created.

After download the code, initialize the Compiler Cache with:

Building Android

Initialize the environment with:

Note: if you close the terminal and enter later, you’ll need to do this command again because it sets some variables, etc.

If you are creating this AOSP for a device, you’ll need to embed the drivers for this device, Im building for a Nexus 4 so downlaod the drivers from the Google driver page uncompress the tgz files and you’ll find a .sh script. Execute both 3 accept the license, and you’ll have a “vendor” directory, copy to the root of previous created folder “WORKING_DIRECTORY”.

Now, you need to choose a target, launch the command:

And select the target you want, I’m building a Nexus4 rom, so mine is: full_mako-eng. You can also do lunch full_mako-eng if you know the target you want to point. note the suffix of the target, userdebug or eng for production.

Build the source with:

Where -jX is the number of parallel tasks you want to execute.

Run AOSP

If all the steps are ok, you have now an image of AOSP! You have 2 options now, execute in a emulator (coward) and flash to a device.

Let’s enter the result directory, in my case:

Replace “mako” with the codename of your device.

If you want to use the emulator, just run the command:

And you are done, if you want to flash a device, put it in fastboot mode and run:

The final -w will wipe all previous data you had in your device.

And you’re done, at this point you’ll have a system ready and booting like mine:

Screenshot_2015-07-29-17-38-38

Documentation I used to create this post:
Build Android 5.0 os OSX 10.10 from @raminmahmoodi
Official documentation from Google
Missing symbols building android
Make your own aosp system nexus4



Did you like this post? You can support my work and help me writting more useful posts:

BTC address: 3Az7sgCW4VaNqxmTpWcZvoFDDEkqJnv8ba