Build Android 5.0 Lollipop on OSX 10.10 Yosemite

Ramin Mahmoodi
7 min readJan 16, 2015

Why have this guide?

There’s a lot of information on Google’s Android Source documentation about building Android. While their documentation is good, if you look at android-build groups on their forums, you’ll see a lot of people are having issues compiling. The information is kind of scatterred and not geared towards people with OSX Yosemite.

So, I decided to put a guide together. Something simple for people who are just getting into Android development and kernel compiling to check out. I hope to put together a series on how to build custom kernels and developing for current devices as well as building a custom Android device or porting Android to another device.

Side note: this is my first story on Medium, so they can only get better from here ;)

Let’s get to it.

What you have to have:

  1. An Apple computer with OSX 10.10 (Although this will work on other OSX versions)
  2. A minimum of 100GB of free space available (external drives are fine)
  3. Apple Developer Account (to download Xcode)
  4. A Google account (to setup repo)

What you should have:

  1. Fast internet connection (there’s a lot of stuff to download)
  2. 8/16GB RAM
  3. An idea of how Git or repositories work in general
  4. Not be afraid of using Terminal

Configuring your Mac

Getting Xcode

Open up App Store and install Xcode. The current version is 6.1.1. Even though you can’t compile Android with this Version of Xcode, I think it’s still a good idea to have the latest version.

While that’s installing, head over to the Apple Developer site and register for a developer account. You will need to use an iCloud account (you should already have one if you’re using Yosemite) and register. Registration is free, but submitting apps to the Apple App Store does have a registration fee. Search for Xcode 5.1.1 (release date April 10, 2014) and download it.

After Xcode 6.1.1 has finished installing from the App Store, go ahead and launch it, to make sure it is running and you don’t have any issues.

Now, let’s setup Xcode 5.1.1

  1. Double-click to mount XCode5.1.1.dmg
  2. Right-click on XCode and select Show Package Contents
Show package contents of Xcode 5.1.1

3. Open up Terminal and create the folder /Developer/SDK

$ sudo mkdir -p /Developer/SDK
# Enter your password (this is the password used to install Apps)

4. Copy MacOSX10.8.sdk from Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ to /Developer/SDK

Location of the 10.8 SDK we need to copy over

5. Copy from the Xcode5.1.1.dmg to /Developer

We’re done with the Xcode DMG, so you can eject and move it to the Trash

Finish setting up Xcode

  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"
Select Xcode 5.1.1 for Command Line Tools

Install MacPorts

MacPorts is similar to yum or apt. It helps install packages and all their required dependencies without you having to find and compile them yourselves. It if very well maintained and comes in handy!

  1. Get MacPorts! (Make sure to grab the correct version)
  2. Once it’s completed type in port your Terminal to make sure it’s installed.

If port does not work, then follow these steps:

1. Open Terminal and edit your bash profile

$ vim ~/.bash_profile

2. Press the letter “i” on your keyboard. You should see “—INSERT—” on the bottom left. 3. Type in

export PATH=/opt/local/bin:$PATH

4. Push Esc key 5. Push Shift key + ; (making the : symbol) 6. Type in “wq” and press enter 7. You should be back in Terminal, reload your bash profile and try port again

$ . ~/.bash_profile
$ port

If port is installed and working we need to install the required packages

$ POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg

Install the Java Development Kit

The master and 5.0.x branches of Android in the Android Open Source Project (AOSP) require Java 7. On Mac OS, use jdk-7u71-macosx-x64.dmg

Install Repo

Repo is a tool that makes it easier to work with Git in the context of Android. For more information, visit Developing in the Android Development Tutorials.

1. Make sure you have a bin/ directory in your home directory and that it is included in your path:

$ mkdir ~/bin
$ PATH=~/bin:$PATH

2. Download the Repo tool and ensure that it is executable:

$ curl > ~/bin/repo
$ chmod a+x ~/bin/repo

Setup file descriptors

On OSX, the default limit on the number of simultaneous file descriptors is too low and a highly parallel build process may exceed this limit. To increase the cap, add the following lines to your ~/.bash_profile

$ vim ~/.bash_profile
# set the number of open files to be 1024
ulimit -S -n 1024

You can add this anywhere in your ~/.bash_profile. Reload your bash profile again.

$ . ~/.bash_profile

Create a case sensitive virtual drive

The easiest way to do this is in Terminal. Note: if you are going to be building mutliple versions, replace 100g with 200g.

$ hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 100g ~/android.dmg

This will create “android.dmg.sparseimage” in your user directory. A sparseimage allows the image to grow as needed. You can put in 200g and it will only grow to a maximum of this size when needed.

To mount this drive

$ hdiutil attach ~/android.dmg -mountpoint /Volumes/android

As another method, you can create a function for this inside you ~/.bash_profile as shown below or in the Android Development documentation. Just make sure you’re using the correct path.

To create a quick mount function

$ vim ~/.bash_profile

Create a new line and put in

function mountAndroid { hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android; }

Save and exit VIM then mount your drive

$ mountAndroid

Downloading the source files

First we need to know which branch we want to download. In this tutorial we’re downloading android-5.0.0_r7.0.1

First, create a working directory on you /Volumes/android image

$ cd /Volumes/android

To grab a specific one, check out the Platform Manifest and determine which one you want to grab and repo init that branch.

$ repo init -u -b android-5.0.0_r7.0.1

Note: If prompted, configure Repo with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account. Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions.

Finally, sync the repo. This will take a long time and must be completed in one shot. You cannot pause or stop a sync without having to intiate an entirely new sync. There are other commands such as repo sync -c which will only grab a specific branch and no additional tags or history, but this isn’t recommended.

$ repo sync

This will probably take 1 to 2 hours. So go enjoy some breathing time since you’ve made it this far!

After the branch has been synced!

The part you’ve been waiting for, building the source!

Now comes one of the longest parts. You thought syncing took a long time!? This is the final step. Not much too it, except time.

First, we need to tell it what platform we’re building for, since we’re going to be doing this on an emulator, we’re going to select aosp_arm-eng. Read more about the different target options.

$ lunch

Press “1" to select aosp_arm-eng and finally make Android!

$ make -j4

Note: As this goes on your fan will speed up…a lot! Don’t worry!

Look out for #### make completed successfully (time it took) ####. This build took just under 1.5 hours. I have a Late 2013 15" Macbook Pro 2.6GHz i7 + 16GB RAM for comparison.

Build completed successfully!

Launch your hard work!

$ emulator

The emulator will take some time to initialize the first time (mine took about 10 minutes).

Emulator first run
Android Version 5.0


Thanks for reading through this. I hope it helps somebody out there who’s trying to get into Android development or Kernel building or is just having a hard time getting this setup on their Mac.

I hope to do some more of these tutorials. If you have any questions or comments please contact me. I’ll also link any new tutorials to the end of this document when I publish them.