[转自:http://forum.xda-developers.com/showthread.php?t=2510898 ]
Hello everyone,
I've come across, and been asked, a lot of questions regarding how to properly setup a build environment on OS X 10.9 Mavericks. Since the release of 10.9 Mavericks, Apple deprecated some stuff from perl, which is giving people errors. I'm going to make this guide on how to setup a build environment on OS X 10.9 Mavericks.

Setting Up an Android Build Environment on OS X 10.9 Mavericks
1. Installing the necessary Applications from the Apple App Store
Android requires many packages and Command Line tools that are not native to Apple operating systems. To obtain some of the tools we will need, we will need to download and install XCode. XCode can be found on the supplementary software cd that came with your iMac or Macbook(pro), depending which type of computer you have. If you do not have access to that cd, then you can simply install it from the AppStore, or click the link below.
** 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
Once XCode is downloaded and installed, you can pretty much forget about it. Just don't uninstall it.
2. Installing Java JDK 6
A lot of people will tell you that installing Java on OS X is simple. Just open the terminal, type java, and if it's not installed, you'll be automatically prompted to install it.
STOP
By doing the above procedure, you will be installed the LATEST java release from Apple. THIS IS BAD. To build Android, you want JDK 6.
Simply click the link below, download the .dmg file, and install it.
Java for OS X 2013-005
3. Downloading and Installing the AndroidSDK
Once you have fully installed XCode, you will need to install the AndroidSDK, from Google. I am including the link to the SDK Tools Only download, since the full SDK is NOT required. IF you would like the full SDK, then by all means, please download it from the link below. The AndroidSDK can be obtained from the following link:
AndroidSDK for Mac OS X - SDK Tools Only download
AndroidSDK for Mac OS X - FULL ADT BUNDLE
Once the SDK is downloaded, follow the steps below to install it to your system for easy access in the terminal. I am writing these steps per the setup that I personally use, and have found to be simple and effective. You may change the directory that you save the SDK files to, but you will need to reflect that within your .bash_profile.
- Extract the contents of the AndroidSDK to a new folder, named 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
- Open Terminal [this is easily achieved by holding COMMAND and pressing SPACEBAR, then typing TERM and hitting ENTER
- Enter the following command into the Terminal:
Code:
nano -w ~/Users/USERNAME/.bash_profile
Code:
export PATH=${PATH}:~/android/android-sdk/tools export PATH=${PATH}:~/android/android-sdk/platform-tools export PATH=${PATH}:~/bin PATH="$HOME/android/android-sdk/tools:$HOME/android/android-sdk/platform-tools:$PATH"
Doing this will allow you to access any of the commands from within the android-sdk folder, even if you are not located in that folder with the Terminal. Basically, you can use adb and fastboot without having to navigate to the folder containing them with the Terminal

Once you have finished adding the necessary lines to .bash_profile hold COMMAND and press X. Then press Y , then ENTER to save your changes. Nano will automatically quit back to the Terminal once you have saved.
- "Right-Click on the Terminal icon and choose to Quit, the terminal must be restarted so that it picks up the changes made to .bash_profile
- Open the Terminal again
- Type "android" without quotation marks
- The AndroidSDK installer will start
- Click the checkbox next to Tools, and make sure that all sub items of Tools are checked.
- Click Install X packages to the bottom right of the window
- Click Tools in the window to the left, then click the radio button to accept the license
- Click Install, and allow it to install the SDK Tools
4. Downloading and Installing Brew, and the Required Packages to Build Android
So, now we've successfully installed XCode, the PROPER version of Java, and the AndroidSDK. Now we need to install the tools required to build Android.
Now, many of these tools are "Linux-Only" and aren't available on Mac. Big Deal. We have an awesome thing called Brew. Brew allows you to install packages "command-line-style" just like on Linux. It's basically Mac's "apt-get".
So, to install Brew, open the Terminal, and enter the following:
Code:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
Once Brew is installed, we need to add some more things to the .bash_profile, so let's open that back up using Nano. If you don't remember how to do that, please go back to Step #3 .
Once you are back into Nano and are editing the .bash_profile, enter the following on their own 2 lines:
Code:
touch ~/.bash_profile && echo "PATH=/usr/local/bin:/usr/local/sbin:$PATH:/usr/local/android-sdk/tools:/usr/local/android-sdk/platform-tools" >> ~/.bash_profile export BUILD_MAC_SDK_EXPERIMENTAL=1
Now, we need to run a few commands through Brew, just to make sure everything is installed correctly. Enter the following into the Terminal:
Code:
brew outdated
Code:
brew update
Code:
brew upgrade
Code:
brew doctor
Now to grab our necessary packages..
Code:
brew install git coreutils findutils gnu-sed gnupg pngcrush repo
Code:
ln -s /usr/local/bin/gfind /usr/local/bin/find && ln -s /usr/local/bin/gsed /usr/local/bin/sed
Enter the following command into the Terminal:
Code:
brew install git coreutils findutils gnu-sed gnupg pngcrush repo python
5. Fixing Switch.pm Issues
When upgrading to OS X Mavericks, Apple made some perl module deprecated, but we still need them to build Android!
The module in question is Switch.pm. If you follow this guide, but skip this step, you will get errors complaining about Switch.pm , and think "what is that?"
Well, it's a missing module that perl is calling on. To add it back, simply enter the following into Terminal:
Code:
brew install cpanm sudo cpanm Switch --force
6. Initializing the repo
Now that XCode, the AndroidSDK, java, and brew are installed. 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.
Code:
hdiutil create -type SPARSE -fs "Case-sensitive Journaled HFS+" -size 60g -volname "android" -attach ~/Desktop/Android
Once the command is done, you will see a new .img on your desktop, called android.sparseimage. This is the volume you just created. To mount it, you just simply double-click it.
Now, to access that volume via the Terminal, simply type:
Code:
cd /Volumes/android
Code:
cd /Volumes/android mkdir omnirom cd omnirom repo init -u https://github.com/omnirom/android.git -b android-4.3 repo sync
I did not include ROM-specific setup, since many of the ROMs that can be compiled from source maintain different processes for each. You should be able to follow this guide, and then find a guide on how to build the ROM of your choice from source, but IN THE ROM-SPECIFIC GUIDE you can skip down to "Initializing Repo"