I've come across, and been asked, a lot of questions regarding how to properly setup a build environment on OS X, so I'm going to make this guide on how to setup a build environment on OS X 10.9 Mavericks.
this is only for setting up the build environment, and since most ROMs use different configurations, you will need to refer to your specific ROM for how to initialize their source and build
Setting Up an Android Build Environment on OS X 10.9 Mavericks
A Word To The Wise
/** * if you don't follow my instructions exactly as they are written, several things will happen: * 1 - If you don't know what you're doing, it won't work * 2 - I won't respond with help, since everything you need IS RIGHT HERE **/
What You Will Be Installing:
- XCode 5
- Android SDK (includes ADB and Fastboot)
- Many, many packages required for building Android
XCode is roughly a 4 GB download from the AppStore. Once it is downloaded, it will start an installation process, where it will download more software and install XCode on your system. Depending on your hardware, and your internet speeds, this could take a long time.
Apple XCode 5 for OS X 10.9 Mavericks
Or just search for "XCode" in the App Store
Once XCode is downloaded and installed, you can pretty much forget about it. Just don't uninstall it.
- Extract the contents of the Android SDK download archive to a new folder and name it android-sdk
- Create a new folder in your HOME directory ( ~/ ) named android [your home directory can be found by opening Finder, and clicking on your username in the column to the left]
- Move the android-sdk folder INTO the android folder you just made in your Home directory ( it will be ~/android/android-sdk )
- Using Finder, navigate to the android/android-sdk/tools folder.
- Double-click the "android" file and go through the installer for Android SDK
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
This will begin the download and installation of Brew.
Depending on your hardware and internet connection, this could take a bit.
Now, we need to run a few commands through Brew, just to make sure everything is installed correctly. Enter the following into the Terminal:
brew outdated && brew update && brew upgrade && brew doctor
After running brew doctor, you should receive a message saying the follow: Your system is ready to brew.
Now, we can install the packages required to build Android.
Required Packages For Compiling Android
Enter the following command into the Terminal:
brew install git coreutils findutils gnu-sed gnupg pngcrush python
This WILL take a while.
Open Terminal and enter the following:
mkdir -p ~/.bin curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo
Creating A Case-Sensitive Volume
We need to create a CASE-SENSITIVE image for our development. Android cannot be build on case-insensitive images, so we need to make one.
Enter the following into the Terminal.
hdiutil create -type SPARSE -fs "Case-sensitive Journaled HFS+" -size 60g -volname "android" -attach ~/Desktop/Android
I have it set to be 60 GB here, but you can increase or decrease the size to whatever you choose, simply change the "60" to any number of GB you want it to be. I generally use 100 GB.
Once the command is done, you will see a new .img on your desktop, called android.sparseimage. This is the volume you just created that will store your source. To mount it, you just simply double-click it.
Setting Up bash_profile
Enter the following into Terminal:
Now copy / paste this into the terminal, so it's in the bash_profile you're creating:
export PATH=~/bin:$PATH export PATH=~/android/android-sdk/sdk/platform-tools:$PATH export PATH=/usr/local/bin:$PATH export BUILD_MAC_SDK_EXPERIMENTAL=1 export LC_CTYPE=C export LANG=C
Save it by pressing Ctrl + X , then Ctrl + Y
Once back at the command line in Terminal, enter the following:
Necessary cherry-picks for OS X compatibility
That's it. Refer to your individual ROM source for how to sync the manifests and get builds going. Happy building!Here is a list of commits, organized alphabetically by repository, that you will need to cherry-pick in order to ensure the best compatibility for building on OS X:
If you come across other commits related to building on OS X that I have not listed, PLEASE respond to the thread and mention me. I'll get them added!
openssl / sha1sum errors?
readink -f errors?
sed/gsed errors that is NOT "sed: RE error: illegal byte sequence"?
errors with the zip creation?
JNI errors in /external/chromium_org ?