[Nexus 9 Android Development] KedarWolf:
How To Build A Completely Unaltered AOSP 5.1.1_r5 From Source Using Linux Mint 17 For The Nexus 9

Updated to 5.1.1_r8

This build was done using Linux Mint 17.1 Cinnamin and should work in 17.1 Mate as well. I know I had trouble on other builds with the KDE version of Linux Mint but haven't tried this build. I changed it to build the 64 bit AOSP and use the 64 bit GAPPS. Updated to 5.1.1_r8

Here is a link to a compiled unaltered zip of AOSP 5.1.1_r5 I built using this guide.

https://www.dropbox.com/s/rdoh35pocqvellq/aosp_flounder64-ota-eng.kedarwolf.zip?dl=0

Will update the above link to the zip with 5.1.1_r8 ASAP.

You don't need to sign-up with DropBox to download the file, if the page opens to sign-up just hit 'No Thanks' or close the sign-up window then download the file. I chose this over Google Drive because the latter shows the contents of the zip rather then the entire file and is confusing how to download. :rolleyes:

Bluetooth and boot error fixed in this uploaded build.

Also, the steps to fix this are included in the build thanks to fhem!

Steps:

First in Terminal: 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

Had to add this to get 5.1.1_r5 build working:

sudo apt-get install bison build-essential curl flex \

g++-multilib gcc-multilib git-core gnupg gperf \

lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev \

libesd0-dev libncurses5-dev libsdl1.2-dev \

libwxgtk2.8-dev libxml2 libxml2-utils lzop \

openjdk-6-jdk openjdk-6-jre pngcrush schedtool \

squashfs-tools xsltproc zip zlib1g-dev

Follow this with: sudo apt-get install -f

This should fix any dependency errors.

Next: sudo apt-get update

And: sudo apt-get install openjdk-7-jdk

Next download the SDK Tools For Linux x64 from this link. http://dl.google.com/android/android-sdk_r24.1.2-linux.tgz

Then: cd ~/Downloads

And: tar -xvf android-sdk_r24.1.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 'Platform Tools' 'Tools' and 'Build Tools'.

Make sure you install the repo tool, in Terminal: 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 so do the following.

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: 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-5.1.1_r8

Followed by: 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 5930k with 12 threads so I used repo sync -j36. This gives you three threads per logical CPU and speeds things along quite well.

Last time I repo'd I kept getting 'User Is Over Quota' errors but when I did repo sync j4 instead of j36 it fixed that so if you do get 'Over Quota' errors try that.

It may take several hours for the sync to finish.

Do the next commands to add the blue-tooth and boot error commits thanks to fhem.

First: cd ~/AOSP/device/htc/flounder

Then: git fetch https://github.com/craigacgomez/device_htc_flounder.git

And: git cherry-pick 79e4966c26d65112f5109d202662d2fa389ce1d3

Next: cd ~/AOSP/frameworks/base

And: git fetch https://github.com/seanashmore/frameworks_base.git

Finally: git cherry-pick 27f5b7b3bc34ebb39e4c04b40563ae7f901ea502

Then cd ~/AOSP

Next: chmod +x build/envsetup.sh

Then: . ./build/envsetup.sh

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

Then: make -j12 otapackage or the -j36 etc. for your CPU like before.

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

You want to install a custom recovery download TWRP http://techerrata.com/browse/twrp2/flounder

Rename the file in Downloads to recovery.img

Make sure 'USB Debugging' in enabled on your tablet.

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

And: adb reboot bootloader

Then: cd ~/Downloads

And: fastboot flash recovery recovery.img

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

Alternately Wug's Nexus Root Toolkit' in Windows 8.1 or earlier is a really easy to unlock, root and install TWRP on your Nexus 9. You can do this before you install the AOSP zip on your Nexus 9. It's always worked for myself with stock Android and custom ROMs.

http://xdaforums.com/nexus-9/development/toolkit-wugs-nexus-root-toolkit-v1-9-8-t2945451

Ii installs the latest SuperSU, BusyBox and TWRP.

Hold the down volume when booting your tablet then 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. Never had this trouble with Wug's Toolkit in Windows so I highly recommend it.

I installed these GAPPS http://xdaforums.com/android/software/gapps-google-apps-minimal-edition-t2943330

I installed the ElementalX kernel using the non-encrypted device method and it ran quite well with it.

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

You also may want to install BusyBox from Google Play. It works with SuperSU and many apps require it for root as well.

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