[Nexus 7 (2013) General] KedarWolf:
Guide: How To Build AOSP From Source With Linux Mint 16 - Nexus 7 (2013) KVT49L

Important Note: Do NOT use Linux Mint 16 KDE to do this guide, it will seriously mess up your programs menu when you remove the old Java. This guide has been tested and is working on Linux Mint 16 Cinnamon and Linux Mint 16 MATE

Got the KVT49L repos working and guide is updated to reflect this. This build includes several bug fixes from the KOT49H build but it is NOT 4.4.3, just an updated version of 4.4.2.

I started this guide as I could not find a step by step detailed guide to build a stock AOSP from source with Linux Mint 16.

All the steps should work in Ubuntu but I haven't tried so not 100% sure of that.

All this assumes your tablet is already unlocked.

Here goes:

Important note: Anything that is bolded text other then section titles are command line entries that are done in Terminal in Linux Mint. I thought it would be simpler to do it this way then say 'in Terminal' for every entry.

First we need to remove Icedtea Java or OpenJDK.

In Terminal: sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*

Then in Terminal: sudo add-apt-repository ppa:webupd8team/java

Next: sudo apt-get update && sudo apt-get install oracle-java6-installer

Be sure to accept the licence agreement to install java when it prompts you.

Next: sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python

Follow this with: sudo apt-get install -f

This should fix any dependency errors.

Now: sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

Next download the SDK Tools For Linux x64 from this link. https://developer.android.com/sdk/index.html

Then: cd ~/Downloads

And: tar -xvf android-sdk_r22.6.2-linux.tgz

or tab the latest 'android-sdk_xxx.tgz file it they update it and it is a newer version then the one I downloaded to do this.

You can rename the android.sdk_xxx.tgz folder you extracted to SDK.

Then:

cd ~/Downloads/SDK/tools

Next: ./android sdk

It will show you the tools that can be installed, just install the highest version API of 'Platform Tools' and 'Tools' for the latest android version '4.4.x' it shows.

Make sure you install the repo tool, in Terminal:

With: mkdir ~/bin

Then: curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo

And: curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

Now: sudo chmod a+x ~/bin/repo

Now sudo nano ~/.bashrc

Add this to the bottom of the text:

export PATH=~/bin:$PATH

Then hit Ctrl-O and enter, it should say it saved the file followed by Ctrl-X to exit.

Then restart bash: source ~/.bashrc

Now lets Initialize the Repository for GIT configuration

First : git config --global user.name {Your Name}

Then: git config --global user.email {Your@Email}

If you have not registered with the GitHub website just doing these two steps works fine.

If you have registered with the GitHub website create a file called .netrc in your home directory, add your GitHub password to it with no spaces on the first line and change the permissions to '600' or you will have to continually authenticate when building the source.

In Terminal:nano ~/.netrc

Then add just your GitHub password (like I said you only need to do this if you have registered with GitHub).

Then 'Ctrl-O' and enter and it'll say it saved it, then 'Ctrl-X' to exit nano.

And then: chmod 0600 ~/.netrc

Now: mkdir ~/AOSP

Then: cd ~/AOSP

Now you get the source code etc: repo init -u https://android.googlesource.com/platform/manifest -b android-4.4.2_r2

Then do in Terminal : repo sync -j12

Use repo sync -j12 for a quad core CPU or Intel I5 or if you have say an quad core I7 with 8 threads you can use repo sync -j24 to speed things up etc.

I have a I7 3930k with 12 threads so I used repo sync -j36. This gives you three threads per logical CPU and speeds things along quite well.

It may take several hours for the sync to finish.

After the sync finishes go to https://developers.google.com/android/nexus/drivers#razorkot49h and download the drivers (binaries) for the Nexus 7 (Wi-fi). You do need to use the KOT49H binaries and they work fine with the KVT49L build.

In Terminal: cp ~/Downloads/asus-flo-kot49h-a9532596.tgz ~/AOSP

Then: cp ~/Downloads/broadcom-flo-kot49h-c33beb3d.tgz ~/AOSP

And: cp ~/Downloads/qcom-flo-kot49h-f92d75b1.tgz ~/AOSP

In Terminal: tar -xvf asus-flo-kot49h-a9532596.tgz

And: tar -xvf broadcom-flo-kot49h-c33beb3d.tgz

Then: tar -xvf qcom-flo-kot49h-f92d75b1.tgz

If you have closed the Terminal after the sync remember to do: cd ~/AOSP

when you open Terminal again before doing the tar commands.

They should be the file names of the binaries for KOT49H that you are extracting but if for any reason the file names are different use the Tab key and tab the correct names in after 'tar -xvf'.

If the names ARE different I'd really check to make sure you downloaded the correct flo binaries.

Then: ./extract-asus-flo.sh

Now also in Terminal: ./extract-broadcom-flo.sh

And: ./extract-qcom-flo.sh

Hint: It will show you a really long licence agreement for each binary that you scroll by hitting the Enter key that takes forever to scroll one line at a time, it has 8 sections and several subsections. Hold the Enter key until you just get past Part 8, section D of the licence and stop there. Now hit enter a few more time one key stroke at a time until you finish Part 8 section E and see the 'Type 'I ACCEPT' to agree to the licence.' and type I ACCEPT If you just scroll by holding the Enter key all the way to the bottom of the licence you'll get an error you never accepted the licence. Then close Terminal.

Building the Sources

Now open Terminal: cd ~/AOSP

Then: . ./build/envsetup.sh

Now to select the type of device we give the following command: lunch

Choose:

11. aosp_flo-userdebug

by entering '11' or whatever number aosp_flo is after your enter the 'lunch' command (it was number 11 on mine).

Now: make -j12 for a quad core cpu or I5 or make -j24 for an I7 etc.

With your tablet connected to your USB cable and the PC: adb root

Then: adb reboot bootloader

And: cd out/target/product/flo

Lastly: fastboot -w flashall

If you get an error on the 'adb' and 'fastboot' commands do these first:

sudo apt-get install android-tools-adb

and: sudo apt-get install android-tools-fastboot

If you get an error when you fastboot -w flashall to do with a '-p' flag needed or 'android-info.txt' is missing it means you forgot to to the 'lunch' command before building the source. Go back to the '

Building The Sources

' section.

If you already have a custom recovery installed like TWRP and would rather build a zip file to install with the recovery rather then flash it in adb instead of make -j12 do: make -j12 otapackage

In the /home/"yourusername"/AOSP/out/target/product/flo you have an aosp_flo-ota-eng.___.zip file to flash in your custom recovery.

You will need to wipe/reset data your in recovery before flashing it and re-install all your apps etc.

Installing Custom Recovery, Rooting and Google Apps

If you want to install a custom recovery download TWRP http://techerrata.com/browse/twrp2/flo

Rename the file in Downloads to recovery.img

Then in Terminal with your tablet connected by USB to your PC: adb root

And: adb reboot bootloader

Then: cd ~/Downloads

And: fastboot flash recovery recovery.img

Use the volume buttons on your phone to scroll onto "Restart Bootloader" and hit the powerbutton to select it. After the bootloader reloads, use the volume buttons to scroll to "Recovery Mode" and hit power button again to select it. You should then be in your custom recovery.

If for any reason you get a red android and no recovery just boot into fastboot mode again and reinstall the recovery.img.

And finally, to root your tablet download SuperSu http://download.chainfire.eu/supersu and install the supersu.zip in recovery mode.

Download PA GAPPS from here http://xdaforums.com/showthread.php?t=2397942 if you want the zip to install Google Apps in recovery.

You now have your own rooted vanilla AOSP you compiled yourself, congrats! :D

P.S. Very likely a good idea wipe/reset data in recovery and start with a clean install, you'll need to install all your programs and stuff anyways I'm sure.

P.P.S.I did download and install the XPOSED Framework apk http://xdaforums.com/showthread.php?t=1574401 after I put AOSP on my tablet so I could install Advanced Power Menu and some other add-ons like Boot Manager and Greenify. As well I installed a custom kernel with Faux Sound and Faux Kernel enhancements.