Build Android 5.0 Lollipop on OSX 10.10 Yosemite

Ramin Mahmoodi
Jan 16, 2015 · 7 min read

Why have this guide?

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. A minimum of 100GB of free space available (external drives are fine)
  2. Apple Developer Account (to download Xcode)
  3. A Google account (to setup repo)

What you should have:

  1. 8/16GB RAM
  2. An idea of how Git or repositories work in general
  3. Not be afraid of using Terminal

Configuring your Mac

Getting Xcode

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

  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


Install Repo

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 https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

Setup file descriptors

$ 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

$ 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, create a working directory on you /Volumes/android image

$ cd /Volumes/android
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY

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 https://android.googlesource.com/platform/manifest -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!

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

Ending…

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.

Thanks!

    Ramin Mahmoodi

    Written by