Building and Flashing Android 8.1.0_r1 on Ubuntu for Pixel 2 XL

Environment Setup

  • Ubuntu 16.04 LTS with at least 95 GB free disk space (actual usage ~94.2 GB)
  • Pixel 2 XL device: European variant required, as it permits bootloader unlocking and flashing. US variants typically contain "v" or "version" in IMEI and cannot be unlocked.
  • Target system image: Android 8.1.0_r1 (OPM1.171019.011)

Source Code Acquisition

Git and Repo Installation

sudo apt-get install git
mkdir ~/tools && export PATH=~/tools:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/tools/repo
chmod +x ~/tools/repo

Configure Git identity:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Install OpenJDK 8:

sudo apt-get update
sudo apt-get install openjdk-8-jdk

Create working directory and adjust environment:

mkdir -p ~/src/android-8.1.0_r1 && cd ~/src/android-8.1.0_r1

Edit ~/tools/repo to use Tsinghua mirror:

REPO_URL = 'https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

Set global overrides and environment variables:

git config --global url.https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/.insteadof https://android.googlesource.com

echo 'export PATH=~/tools:$PATH' >> ~/.bashrc
echo "export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'" >> ~/.bashrc
source ~/.bashrc

Sync AOSP Source

Initialize manifest for branch android-8.1.0_r1:

python3 ~/tools/repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r1

Fetch source tree:

repo sync -j8

Retry sync if errors occur; remove -j8 to serialize operation.

Driver Binaries Preparation

Obtain driver packages for Pixel 2 XL (codename taimen) matching build OPM1.171019.011 from:

https://developers.google.com/android/drivers#taimenopm1.171019.011

Download and place these scripts into AOSP root:

  • extract-google_devices-taimen.sh
  • extract-qcom-taimen.sh

Run both and accept license terms.

Build Process

Source build environment:

source build/envsetup.sh

Select target product:

lunch
# Choose 'taimen' (usually option 27 for Pixel 2 XL)

Start full build:

time make
# Optionally use 'time make -j4' for limited parallelism

Locale-Related Failure

Error example:

Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / ...)' failed.

Fix:

export LC_ALL=C
make clean
time make

Java Heap Exhautsion

Error example:

Out of memory error GC overhead limit exceeded.

Patch /prebuilts/sdk/tools/jack-admin:

Locate JACK_SERVER_VM_ARGUMENTS and modify:

JACK_SERVER_VM_ARGUMENTS="${JACK_SERVER_VM_ARGUMENTS:=-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx2048M}"

Apply changes and rebuild:

make clean
time make

Flashing Procedure

Install ADB and Fastboot

sudo apt-get install android-tools-adb android-tools-fastboot

Unlock Bootloader

Reboot to bootloader:

adb reboot bootloader
fastboot devices

Unlock (newer devices):

fastboot flashing unlock

Use volume keys to select Yes, confirm with power key. If blocked, enable OEM Unlocking in developer options with internet access.

Flash Images

Ensure same treminal sesssion used for build or define:

export ANDROID_PRODUCT_OUT=~/src/android-8.1.0_r1/out/target/product/taimen

Flash all partitions:

fastboot flashall

Tags: Android AOSP Ubuntu Build fastboot

Posted on Fri, 29 May 2026 18:46:45 +0000 by mpower