Setting Up A Build Environment on OS X 10.9 Mavericks

[转自: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 A Build Environment on OS X 10.9 Mavericks_第1张图片

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
This will open the .bash_profile file from you home directory in the Nano editor. Enter the following into Nano:
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"
Notice that the /bash_profile will now point to ~/ android / android-sdk . IF you decided to store your android-sdk folder somewhere else, this where you need to modify it, so that it reflects where exactly your android-sdk folder is located.

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)"
This will begin the download and installation of Brew. Again, depending on your hardware and internet connection, this could take a bit.

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
Once those lines are entered, save changes and exit Nano by pressing COMMAND and X , then Y, then ENTER.

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
After running brew doctor, you should receive a message saying the follow: Your system is ready to brew.

Now to grab our necessary packages..
Code:
brew install git coreutils findutils gnu-sed gnupg pngcrush repo
Simply enter the following into the Terminal to create some symlinks. This may be unnecessary as of OS X 10.9, but I still do it just to be safe.
Code:
ln -s /usr/local/bin/gfind /usr/local/bin/find && ln -s /usr/local/bin/gsed /usr/local/bin/sed
Now, we can install the packages required to build Android.

Enter the following command into the Terminal:
Code:
brew install git coreutils findutils gnu-sed gnupg pngcrush repo python
This WILL take a while. Once complete, go ahead and move on to Step #5.

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
And you'll be good to go

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
I have it set to be 60 GB with that specific line, 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 120+ 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. To mount it, you just simply double-click it.



Now, to access that volume via the Terminal, simply type:
Code:
cd /Volumes/android
and now you will be able to do something like, say, initialize the OmniROM Source:

Code:
cd /Volumes/android
mkdir omnirom
cd omnirom
repo init -u https://github.com/omnirom/android.git -b android-4.3
repo sync
And there ya go! This guide should have gotten you from a regular installation of Mac OS X 10.9 Mavericks, to one that can build Android ROMs from source!

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"

你可能感兴趣的:(android,mac)