:-D
as Google is not that easy to access, just have an copy of AOSP build ENV setup flow here for reference directly.
Establishing a Build Environment
INTHIS DOCUMENT
This sectiondescribes how to set up your local work environment to build theAndroid source files. You will need to use Linux or Mac OS. Buildingunder Windows is not currently supported.
For an overview ofthe entire code-review and code-update process, seeLifeof a Patch.
Choosinga Branch
Some of therequirements for your build environment are determined by whichversion of the source code you plan to compile. See BuildNumbers fora full listing of branches you may choose from. You may also chooseto download and build the latest source code (calledmaster),in which case you will simply omit the branch specification when youinitialize the repository.
Once you haveselected a branch, follow the appropriate instructions below to setup your build environment.
Settingup a Linux build environment
These instructionsapply to all branches, including master.
The Android build isroutinely tested in house on recent versions of Ubuntu LTS (14.04),but most distributions should have the required build toolsavailable. Reports of successes or failures on other distributionsare welcome.
For Gingerbread(2.3.x) and newer versions, including the master branch,a 64-bit environment is required. Older versions can be compiled on32-bit systems.
Note: Seethe Requirements forthe complete list of hardware and software requirements. Then followthe detailed instructions for Ubuntu and Mac OS below.
Installingthe JDK
The master branchof Android in the AndroidOpen Source Project (AOSP) requiresJava 8. On Ubuntu, useOpenJDK.
Java 8: For thelatest version of Android
ForUbuntu >= 15.04
Run the following:
$sudo apt-getupdate
$sudo apt-getinstall openjdk-8-jdk
ForUbuntu LTS 14.04
There are noavailable supported OpenJDK 8 packages for Ubuntu 14.04. The Ubuntu15.04 OpenJDK 8packageshave been used successfully with Ubuntu 14.04. Newerpackage versions (e.g. those for 15.10, 16.04) were found not to workon 14.04 using the instructions below.
-
Downloadthe .deb packagesfor your architecturefrom http://packages.ubuntu.com/vivid/openjdk-8-jdk:
Remember, you mayobtain the architecture for your machine with:
$uname -m
With x86_64 representinga 64-bit (amd64) Linux kernel architectureand i386/i486/i586/i686 representinga 32-bit (i386) system.
-
Optionally, confirmthe checksums of the downloaded files using the information foundonhttp://packages.ubuntu.com/vivid/openjdk-8-jdk.
For example with thesha256sum tool:
$sha256sum {packagefile}
-
Install thepackages:
$sudo apt-getupdate
Run dpkg for each ofthe .deb files you downloaded. It may produce errors due to missingdependencies:
$sudo dpkg -i{downloaded.debfile}
To fix missingdependencies:
$sudo apt-get-finstall
Updatethe default Java version - optional
Optionally, for theUbuntu versions above update the default Java version by running:
$sudo update-alternatives--configjava
$sudo update-alternatives--configjavac
If, during a build,you encounter version errors for Java, set its path as described inthe WrongJava Versionsection.
To develop olderversions of Android, download and install the corresponding versionof the JavaJDK:
Java7: for Lollipop through Marshmallow
Java 6: for Gingerbreadthrough KitKat
Java 5: for Cupcake through Froyo
Installingrequired packages (Ubuntu 14.04)
You will need a64-bit version of Ubuntu. Ubuntu 14.04 is recommended.
$sudo apt-getinstall git-coregnupg flex bison gperf build-essential\
zip curl zlib1g-devgcc-multilibg++-multiliblibc6-dev-i386\
lib32ncurses5-devx11proto-core-devlibx11-devlib32z-devccache \
libgl1-mesa-devlibxml2-utilsxsltproc unzip
Note: Touse SELinux tools for policy analysis, also installthe python-networkx package.
Installingrequired packages (Ubuntu 12.04)
You may use Ubuntu12.04 to build older versions of Android. Version 12.04 is notsupported on master or recent releases.
$sudo apt-getinstall git gnupg flex bison gperf build-essential\
zip curl libc6-devlibncurses5-dev:i386x11proto-core-dev\
libx11-dev:i386libreadline6-dev:i386libgl1-mesa-glx:i386\
libgl1-mesa-devg++-multilibmingw32 tofrodos \
python-markdownlibxml2-utilsxsltproc zlib1g-dev:i386
$sudo ln -s/usr/lib/i386-linux-gnu/mesa/libGL.so.1/usr/lib/i386-linux-gnu/libGL.so
Installingrequired packages (Ubuntu 10.04 -- 11.10)
Building on Ubuntu10.04-11.10 is no longer supported, but may be useful for buildingolder releases of AOSP.
$sudo apt-getinstall git gnupg flex bison gperf build-essential\
zip curl zlib1g-devlibc6-devlib32ncurses5-devia32-libs\
x11proto-core-devlibx11-devlib32readline5-devlib32z-dev\
libgl1-mesa-devg++-multilibmingw32 tofrodos python-markdown\
libxml2-utilsxsltproc
On Ubuntu 10.10:
$sudo ln -s/usr/lib32/mesa/libGL.so.1/usr/lib32/mesa/libGL.so
On Ubuntu 11.10:
$sudo apt-getinstall libx11-dev:i386
ConfiguringUSB Access
Under GNU/Linuxsystems (and specifically under Ubuntu systems), regular users can'tdirectly access USB devices by default. The system needs to beconfigured to allow such access.
The recommendedapproach is to create a fileat /etc/udev/rules.d/51-android.rules (asthe root user).
To do this, run thefollowing command to download the 51-android.rules fileattached to this site, modify it to include your username, and placeit in the correct location:
$wget -S-O-http://source.android.com/source/51-android.rules| sed "s/<username>/$USER/" | sudo tee >/dev/null/etc/udev/rules.d/51-android.rules; sudo udevadm control--reload-rules
Those new rules takeeffect the next time a device is plugged in. It might therefore benecessary to unplug the device and plug it back into the computer.
This is known to workon both Ubuntu Hardy Heron (8.04.x LTS) and Lucid Lynx (10.04.x LTS).Other versions of Ubuntu or other variants of GNU/Linux might requiredifferent configurations.
Usinga separate output directory
By default, theoutput of each build is stored in the out/ subdirectoryof the matching source tree.
On some machines withmultiple storage devices, builds are faster when storing the sourcefiles and the output on separate volumes. For additional performance,the output can be stored on a filesystem optimized for speed insteadof crash robustness, since all files can be re-generated in case offilesystem corruption.
To set this up,export the OUT_DIR_COMMON_BASE variableto point to the location where your output directories will bestored.
exportOUT_DIR_COMMON_BASE=<path-to-your-out-directory>
The output directoryfor each separate source tree will be named after the directoryholding the source tree.
For instance, if youhave source treesas /source/master1 and /source/master2 and OUT_DIR_COMMON_BASE isset to /output,the output directories will be /output/master1 and /output/master2.
It's important inthat case to not have multiple source trees stored in directoriesthat have the same name, as those would end up sharing an outputdirectory, with unpredictable results.
This is onlysupported on Jelly Bean (4.1) and newer, including the master branch.
Settingup a Mac OS build environment
In a defaultinstallation, Mac OS runs on a case-preserving but case-insensitivefilesystem. This type of filesystem is not supported by git and willcause some git commands (such as gitstatus)to behave abnormally. Because of this, we recommend that you alwayswork with the AOSP source files on a case-sensitive filesystem. Thiscan be done fairly easily using a disk image, discussed below.
Once the properfilesystem is available, building the master branchin a modern Mac OS environment is very straightforward. Earlierbranches, including ICS, require some additional tools and SDKs.
Creatinga case-sensitive disk image
You can create acase-sensitive filesystem within your existing Mac OS environmentusing a disk image. To create the image, launch Disk Utility andselect "New Image". A size of 25GB is the minimum tocomplete the build; larger numbers are more future-proof. Usingsparse images saves space while allowing to grow later as the needarises. Be sure to select "case sensitive, journaled" asthe volume format.
You can also createit from a shell with the following command:
#hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size40g ~/android.dmg
This will createa .dmg (orpossibly a .dmg.sparseimage)file which, once mounted, acts as a drive with the requiredformatting for Android development.
If you need a largervolume later, you can also resize the sparse image with the followingcommand:
#hdiutil resize -size <new-size-you-want>g~/android.dmg.sparseimage
For a disk imagenamed android.dmg storedin your home directory, you can add helper functions toyour~/.bash_profile:
-
To mount the imagewhen you execute mountAndroid:
#mount the android file image
functionmountAndroid {hdiutil attach ~/android.dmg-mountpoint /Volumes/android;}
Note: Ifyour system created a .dmg.sparseimage file,replace ~/android.dmg with~/android.dmg.sparseimage.
-
To unmount it whenyou execute umountAndroid:
#unmount the android file image
functionumountAndroid(){hdiutil detach /Volumes/android;}
Once you've mountedthe android volume,you'll do all your work there. You can eject it (unmount it) justlike you would with an external drive.
Installingthe JDK
See Requirements forthe version of Java to use when developing various versions ofAndroid.
Installingrequired packages
-
Install Xcodefrom theApple developer site.If you are not already registered as an Apple developer, you willhave to create an Apple ID in order to download.
-
Install MacPortsfrom macports.org.
Note: Makesure that /opt/local/bin appearsin your path before /usr/bin.If not, please add the following to your ~/.bash_profile file:
exportPATH=/opt/local/bin:$PATH
Note: Ifyou do not have a .bash_profile filein your home directory, create one.
-
Get make, git, andGPG packages from MacPorts:
$POSIXLY_CORRECT=1sudo port install gmake libsdl git gnupg
If using Mac OS Xv10.4, also install bison:
$POSIXLY_CORRECT=1sudo port install bison
Revertingfrom make 3.82
In Android 4.0.x (IceCream Sandwich) and earlier, a bug exists in gmake 3.82 that preventsandroid from building. You can install version 3.81 using MacPortswith these steps:
-
Edit /opt/local/etc/macports/sources.conf andadd a line that says
file:///Users/Shared/dports
above the rsync line.Then create this directory:
$mkdir /Users/Shared/dports
-
In thenew dports directory,run
$svn co --revision50980http://svn.macports.org/repository/macports/trunk/dports/devel/gmake/devel/gmake/
-
Create a port indexfor your new local repository:
$portindex /Users/Shared/dports
-
Finally, install theold version of gmake with
$sudo port install gmake @3.81
Settinga file descriptor limit
On Mac OS, thedefault limit on the number of simultaneous file descriptors open istoo low and a highly parallel build process may exceed this limit.
To increase the cap,add the following lines to your ~/.bash_profile:
#set the number of open files to be 1024
ulimit-S-n1024