Building The Android Open Source Project – Part 3 – Flashing

Now that we’ve made some changes, it’d be nice to try them out on a real device. By the end of this tutorial you will have an AOSP rom running on your device and you’ll be able to see the changes made in part 2.

Quick note up front: The Nexus 9 (and possibly the Nexus 5X and Nexus 6P) have a ‘vendor’ partition. This makes life a lot easier and removes some steps involving proprietary ‘blobs’ (drivers) that you would need to carry out for devices such as the Nexus 4/5. If anyone would like a tutorial on this I can post one but as I am using the Nexus 9, the steps below will reflect this.

Another warning, AOSP ROMs do not contain Google apps and they must be manually flashed. I’ll upload a post about this very soon, but for now your rom will be pure, non-google-ised AOSP!

Tools & Setup

If you haven’t already got the fastboot and adb tools set up on your machine, you can follow the steps at:

Once that’s dealt with, create a directory somewhere convenient where we are going to store a script which will automate the flashing process for us.

I’ve tried flashing AOSP builds numerous different ways but have found the method I’m going to describe to be the most successful and stable for me.

Stock ROMs

As I’m using a Nexus device, I have access to the Google-made stock ROMs at this location:

I am using the latest Marshmallow build ‘MRA58N’ so my download link is:

I make a folder in my documents, copy this tgz file to it and run the following command to untar it:

tar -zxvf filename

This will give you a bunch of files including a .zip file starting with ‘image’. We want to unzip that file too so run:

unzip imageFilename

Zip & Flash

What we want from the top level folder is the bootloader.img file, and from the image* folder we want the android-info.txt file. Copy both of these files into your ‘out’ folder, for me it’s at /AOSP/target/product/flounder.

The following script zip up all of the appropriate .img files, the android-info.txt and bootloader.img file that you copied over, wipe your device and then flash the build.

Warning: Just in case I haven’t been clear enough, this will wipe everything on your device!!! So backup anything that is important enough to you! I personally use my tablet for browsing, reading and media so I don’t have much to lose.

So, make a bash script file in your documents folder or somewhere else convenient. For example:


Then open the file and paste in the following script, putting your paths and/or filenames in as required:

cd [Your 'out' folder]

#Zip them up into one file (ive chosen as my filename)
#Your device may not have vendor.img - The Nexus 9 does. Simply remove this if you don't need it.
zip [Your chosen filename].zip boot.img cache.img recovery.img system.img android-info.txt vendor.img

adb reboot bootloader
sleep 10

fastboot erase system
fastboot erase recovery
fastboot erase cache
fastboot erase boot
fastboot erase userdata

#Delete the line below if you don't have a vendor.img file
fastboot erase vendor
fastboot flash system system.img
fastboot flash recovery recovery.img
fastboot flash cache cache.img
fastboot flash boot boot.img

#Delete the line below if you don't have a vendor.img file
fastboot flash vendor vendor.img

#Reboot device to start it up - be patient!
fastboot reboot

Save this file somewhere convenient and not your ‘out’ folder.

Make the script executable

chmod +x

Warning: before running this script you need to enable some options in the ‘Developer Options’ menu.

To enable the developer options menu, go to Settings -> About (or about tablet) -> Tap the Build number entry until you see a message telling you that you’re a developer.

Once these are enabled, go back to settings and you will see an extra menu ‘developer options’. Tap it. Once inside, you want to enable both ‘USB Debugging’ and ‘OEM Unlocking’. The ‘OEM Unlocking’ is extremely important and if it is not enabled and left enabled there is a chance you could permanently brick your device. Without this option enabled you will not be able to flash anything.

With that said, plug your device into your computer and run:

adb devices

You should see output like the following:

alittlelost@alittlelost-samsung:~$ adb devices
List of devices attached
HT4CAJT02477    device

Now it’s time to run the script you made:


Once this is finished your device will restart. The first start may take about 10-15 minutes to finish.

That’s it; You should now have your own AOSP rom running on your device. When it starts up you can hold in the power button to see the changes that were made in part 2:



You will also see a warning when you startup your device like the below. This is nothing to worry about and I’ll show how to remove it in a future post.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s