Porting an Android Rom: Prologue

When the Essential Phone was announced I watched with a casual interest. When I found it supports Displayport Alt-mode on it's USB port I set out to port maruOS to it.

It took quite a bit to get the hang of building Android. This was compounded by the fact that there isn't much documentation outside of the AOSP build docks. The purpose of this post is to touch on some techniques I implemented or was taught in order to streamline the build process.

Using repo

In order to build Android on has to learn to use the Android Build Tools. repo is a program written at Google that facilitates the use of the many git repositories that make up the AOSP codebase. These repositories are all submodules of eachother and make up different 'trees' in the Android buildchain.

Typically rom developers split the Android source into a device tree (vendor), a kernel tree, the android source and propriatary google packages.

When you repo init you are instantiating project in that directory. This is similar to git init. The source trees are controled via manifest files, and device specific customizations are mapped in /.repo/local_manifest/. Lineage is using a roomservice.xml here.

Running repo sync will pull in all of the repositories and thus all of the source code needed to build android. This also includes necessary files to manipulate and run the Android Build system.

I was taught to use repo sync --force-sync --no-tags --no-clone-bundle -j8 -c -f to help speed up this process. This will prevent repo from pulling branches for other devices, allocates more threads to the processa and will prevent warnings from stopping the sync.

Dependencies

Because this is a documentation of differences in using up-to-date tools this will be on Ubuntu 18.04 LTS.

I needed to install all of the required dependencies listen in the LineageOS build guide

I also needed the following dependencies:

  • bc
  • flex: a lexer used in the build system
  • libssl-dev

Customizations

I appended this to the .bashrc I use when I build:

alias androidsync='repo sync --force-sync --no-tags --no-clone-bundle -j8 -c -f'
alias matalunch='lunch lineage_mata-userdebug && mka bacon'
export USE_CCACHE=1
export LC_ALL=C
export ANDROID_COMPILE_WITH_JACK=false
export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G"

I have inferred the compile with Jack statement from a stackoverflow post.

I believe that I can integrate these customizations into build/envsetup.sh so that I dont have to load this using source .bashrc before building.

Building

A traditional build goes like this:

source build/envsetup.sh
breakfast mata
brunch mata

However it I have been persuaded away from this. Instead I am building by running source ./custombashrc and then:

source build/envsetup.sh
breakfast mata
lunch linage_mata-userdebug
mka bacon