-We will run Ubuntu 14.04 within VirtualBox while in a Windows OS.
-Yes you could also use VMWare Player too if that is your wish. The adb/fastboot commands towards the bottom target VBox route. I guess you’ll have to compensate accordingly.
-Currently VBox runs on the following:
————————————————-Presently, VirtualBox runs on Windows, Linux, Macintosh, and Solaris hosts and supports a large number of guest operating systems including but not limited to Windows (NT 4.0, 2000, XP, Server 2003, Vista, Windows 7, Windows 8), DOS/Windows 3.x, Linux (2.4, 2.6 and 3.x), Solaris and OpenSolaris, OS/2, and OpenBSD. [ source ]
————————————————-

Grab Virtual Box, Prepare for Ubuntu 14.04.2 14.04.3 — Updated Jan/17/2016
0.) If you already have your own box(*nix) running, skip right to Stage three. Skip
1.) A copy of Ubuntu 14.04 here
2.) Get your copy of VirtualBox here
b.) Install VBox then launch it after install.
3.) Click New Button.
4.) Name your VM OS.
5.) Select Memory amount for VM, do not red-line it. Windows 7 will be fine on 4-8GB, maybe less.
6.) Create a Virtual hard drive(VHD).
7.) Choose hard drive file type.
8.) Dynamically allocated or Fixed size? I would go with Dynamic. -Do not split-
9.) Pick where you would like to save the .VMDK file. As far as size, I would recommended 300GB, even better if you can offer more.
10.) Now for the settings. Under System(left pane), Select Processor tab. You can use all green processors or limit it. Your choice.
11.) Acceleration Pane, check the two available.
12.) Under Storage, click on the CD+ icon next to Controller: IDE, find the ubuntu ISO file.
14.) It should look similar to the image below after you’ve selected the iso.
13.) Select System again, Motherboard Tab. Move CD/DVD to first on the list. Click OK to apply changes.
————————————————-

Certainly if you want an adaptive VM, where the screen changes by how you resize it in Windows then install ‘Guest Additions CD‘

-Let the OS do its thing then it will ask for you to press enter to complete the installation.
-Simply reboot the VM. Your window/vm resolution will adjust on how you scale the window.
————————————————-

[[ STAGE THREE ]]

1.) Once you land on homescreen, Open terminal. (Ctrl+Alt+t)
2.) Installing the JDK: Java 7-For the latest version of Android(6.0.1): Type the following:
b.) A list of packages will be offered. Type ‘Y‘ to install.$ sudo apt-get update
$ sudo apt-get install openjdk-7-jdk

4.) Configuring USB Access: Personally I prefer to configure that on Windows side.
b.) Grab the drivers for Nexus 5 from the ‘android sdk‘.

5.) Setup ccache. This allows us to ‘make clean‘ often if we are doing different builds.
b.) I’ve put aside about 70G for it. So I can build different flavors for the Nexus 5.
c.) We will specify that 70G after downloading the source. For now just install.$ sudo apt-get install ccache
————————————————-

[[ STAGE FOUR ]]

1.) This whole time we were working out of the home directory.
b.) On the terminal type:$ mkdir ~/bin$ PATH=~/bin:$PATH

c.) You can also add the above to your .bashrc and reload it.$ gedit .bashrc
c-1.) Paste this inside at the bottom of the file:export PATH=~/bin:$PATH
Save the file and exit.
c-2.) Reload the file.$ . ~/.bashrc

6.) *** Before you execute, know that it is going to take a while to pull 6.0.1, it is over 30GB in size. ***$ repo sync

7.) Finish setting up ccache. Type this while on ‘workingDir‘$ gedit .bashrc
b.) Put the following line at the end of the file and save. Reload bashrc.export USE_CCACHE=1

8.) Do this after the source has been synced. Pick the amount you need: 50-100GB
b.) I ‘make clean‘ quite a bit changing a few things here and there before building again.$ ccache -M 70G
c.) You can also check here for more options. [CCACHE]

6.) In the working directory, use ‘wget ‘ to grab the binaries manually. Or just use links ^^^$ wget https://dl.google.com/dl/android/aosp/broadcom-hammerhead-mmb29s-3a3c03c6.tgz$ wget https://dl.google.com/dl/android/aosp/lge-hammerhead-mmb29s-fa0209c9.tgz$ wget https://dl.google.com/dl/android/aosp/qcom-hammerhead-mmb29s-bd184be4.tgz

$ ./extract-broadcom-hammerhead.sh
-‘Press Enter to view the licence’.
– Press Ctrl+c, then type ‘I ACCEPT‘.
– Vendor files from broadcom should now be extracted inside of a newly created folder ‘vendor‘.
– Repeat the same process for the last two.$ ./extract-lge-hammerhead.sh$ ./extract-qcom-hammehead.sh

7.) In order to make sure that the newly installed binaries are properly taken into account after being extracted, the existing output of any previous build needs to be deleted with – I’ve noticed when I build different N5 versions, I do not need to issue this command over and over. Do it now.$ make clobber
————————————————-

[[ STAGE SIX ]]

1.) Looks like Google released a new 5.1 as of Mar 25, 2015 evening. A few minor updates it seems.b.) Moved from android-5.1.0_r1 –> android-5.1.0_r3 — Doesn’t matter, similar process should apply.c.) From [Nexus 5, Nexus 6, Nexus 7 (grouper), Nexus 10, Nexus Player] _r1 -> [Nexus 5, Nexus 6] _r3d.) We are standing our ground at android-5.6.0_r1 – you could redo the sync for _r3 later.
e.) Before we build, start thinking about how many CPUs you dialed in for your VM.

2.) Initialize the environment with the envsetup.sh script.
b.) This could also be issued: source build/envsetup.sh – the way below is faster.*Notice the single dot*

$ . build/envsetup.sh

3.) Choose a Target to build with ‘lunch‘.
b.) You will get a menu for your lunch. Then issue a ‘Ctrl+c‘ to terminate the prompt.$ lunch
c.) Check Google’s build guide on the image below.
c-1.) I know I want aosp for device hammerhead suited for production.
c-1b.) Technically you could use option 15. aosp_hammerhead-userdebug — Up to you on this one.
c-2.) I will issue ‘lunch aosp_hammerhead-user‘ at the terminal as my choice.

4.) Prepare yourself for a build delay. Issue this command:$ lunch aosp_hammerhead-userdebugb.) Notice the details above. Version 5.1, target aosp_hammerhead, variant user, cpu variant krait(Qualcomm Snapdragon ARM), out folder.
c.) This is going to be a bare-bones build, no Google apps to be found anywhere.
d.) Now we do ‘make -jN‘ :: N==how many cpus dialed in during VM setup. Issue:$ make -jN
e.) Now you wait until its done.
f.) Make completed fine.

6.) I’ve decided to add a way to adb/fastboot from within VirtualBox.
b.) I’m assuming you had Nexus 5 drivers installed in Windows.
c.) I am also assuming you have an UNLOCKED FASTBOOT.
d.) Install the following packages in terminal:$ sudo apt-get install android-tools-adb android-tools-fastboot

8.) Assuming the phone is on ‘USB debugging‘ mode.
b.) Go back to VM ‘Machine->Settings‘, add ‘LGE Nexus 5 [0232]‘. Click OK.
c.) Unplug then plug device again.
d.) First addition was for fastboot, second addition for adb. Look below:
e.) Everytime you boot your VM while phone is plugged in, adb/fastboot will be ready to go.
e-1.) Check the image below: First ‘lsusb‘ while in fastboot, second ‘lsusb‘ while in adb.
f.) You are ready to proceed to the next step.

————————————————-

[[ STAGE SEVEN ]]

1.) The above files are flashable via fastboot. Flash them in that particular order.

*** DO NOT interrupt any of the processes below.
PATIENCE IS KEY ***

b.) Looks like another USB device needs to be added(same Id). Check below:
c.) That should be it for basic AOSP Hammerhead build.
d.) No Google Apps but the phone is functional at bare bones.
————————————————-

[[ STAGE EIGHT ]]

some snacks for you.

0.) Technically you could do this: $ fastboot -w flashall“An entire Android system can be flashed in a single command: this writes the boot, recovery and system partitions together after verifying that the system being flashed is compatible with the installed bootloader and radio, and reboots the system. This also erases all the user data.”
1.) You can certainly ‘fastboot flash recovery twrp-2.8.7.1-hammerhead.img‘.
2.) You could, say, flash Google Apps package(opengapps.org) while in TWRP Recovery.
2a.) If you run into issues with permissions, you can swipe from top(settings->apps),
give the necessary application its permission.
3.) Definitely flash ‘BETA-SuperSU-v2.66-20160103015024.zip ‘ — for root(api/gui).
^^^ Adb shell root is live because of the buildtype(userdebug). ^^^
4.) You have the Source, reclaim your OS!! Cook it your way!

Which would you like? [aosp_arm-eng] 14
build/core/product_config.mk:227: *** _nic.PRODUCTS.[[device/lge/hammerhead/aosp_hammerhead.mk]]: “frameworks/native/build/phone-xhdpi-2048-dalvik-heap.mk” does not exist. Останов.

** Don’t have a product spec for: ‘aosp_hammerhead’
** Do you have the right repo manifest?