Building The Android Open Source Project – Part 4 – GIT Repositories

Before venturing any further into the land of source code changes, it is probably best to have somewhere to store your code and changes in an incremental fashion. This provides a lot of benefits and is always advisable when working with a large project like the AOSP but the main benefit for me is the ability to see which files you have edited at any given time and what changes you have made. Before I setup my own repositories I made a lot of little changes here and there and then completely forgot about what I had done a few days later.

So the two main (and free) GIT repository sites are github and Bitbucket. So go ahead and sign up for one of those; I use bitbucket as they allow you free private repos that nobody else can see and this is useful for some of my projects but the whole point of AOSP is that it’s open source so a public repo will do just fine.

Once you have signed up to one of those the process is pretty straight forward. The two sections of code we want to store for now are the frameworks/base structure and the device/htc/flounder (or whatever your specific device structure is).

Create a repo inside your account and all it ‘frameworks/base’ or something similar.

On both sites you will be given basic instructions on how to initialize and populate the GIT repo you have just created. All we want for now is the address of it I.e.

Open up a terminal and go to frameworks/base

Run the commands below to set up your repo and push your code to the remote repository. This can take quite awhile the first time depending on your internet connection but it is completely worth it.

Note: if you don’t have Git installed you can do so by running the following from a terminal:

sudo apt-get update
sudo apt-get install git

Agree to any prompts that may appear.

git init
git checkout -b master
git add --all
git commit -m "initial commit with power menu changes"
git remote add origin [address of the repo you created]
git push -u master

‘git init’ initialises that directory and everything below it as a git repo.

‘git checkout -b master’ create a local branch called master and checks it out.

‘git add –all’ stages all the changes we have made. Gets them ready to commit.

‘git commit -m …” commits are changes to the branch with a message in between the double quotes.

‘git remote add…’ adds the remote repository that you created to this repos list of remote repositories.

‘git push -u master’ pushes all of our changes and everything under the frameworks/base directory to our remote git repository.

If you run ‘git remote -v’ you will see a list of remote repos that this local repo can communicate with. Currently you should see AOSP (the official repo that you can pull from) and origin which you have just created to represent your own remote repo.

Repeat the same steps for your device branch. These are the two most common places that you will be making changes for now.

From now on, any time you make changes below the frameworks/base folder for example, you can go to the frameworks/base folder and run:

cash status

to see what files you have changed. You can then see exactly what changes you have made by running:

git diff path/to/file/filename

Once you’re happy with your changes you can add everything to your commit by running:

git add --all

Or just add some files one-by-one with:

git add path/to/file/filename

Once you are ready to commit simply run:

git commit -m "I have changed....x..y..z"

And finally push it to your remote repo with:

git push origin

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.