Build Android 5.0 Lollipop on OSX 10.10 Yosemite
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:
- An Apple computer with OSX 10.10 (Although this will work on other OSX versions)
- A minimum of 100GB of free space available (external drives are fine)
- Apple Developer Account (to download Xcode)
- A Google account (to setup repo)
What you should have:
- Fast internet connection (there’s a lot of stuff to download)
- 8/16GB RAM
- An idea of how Git or repositories work in general
- 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
- Double-click to mount XCode5.1.1.dmg
- Right-click on XCode and select Show Package Contents
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
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
- Open up Xcode 6
- From the menu, select XCode -> Preferences…
- Click on the Location tab
- The last option, “Command Line Tools”, select “Xcode 5.1.1"
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!
- Get MacPorts! (Make sure to grab the correct version)
- 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 https://storage.googleapis.com/git-repo-downloads/repo > ~/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
$ 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!
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.
Launch your hard work!
$ emulator
The emulator will take some time to initialize the first time (mine took about 10 minutes).
Ending…
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.
Thanks!