AOSP 8.1.0_r1 Compilation: Environment Setup and Troubleshooting

Acquiring the Source Code

The Android Open Source Project (AOSP) codebase is hosted by Google. For users in regions with restricted access, domestic mirrors such as Tsinghua University (https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/) or USTC (https://mirrors.ustc.edu.cn/aosp/) are recommended alternatives.

Source retrieval requires the repo tool, which manages multiple Git repositories.

Repo Tool Installation

Create a dedicated directory for the tool and add it to the PATH.

mkdir -p /opt/aosp-tools/bin
export PATH="/opt/aosp-tools/bin:$PATH"
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o /opt/aosp-tools/bin/repo
chmod +x /opt/aosp-tools/bin/repo

Edit the repo script to point to the mirror URL. Change the REPO_URL variable to https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/.

Repository Initialization and Synchronization

Establish a working directory and initialiez the manifest.

mkdir -p /home/user/aosp-src
cd /home/user/aosp-src
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-8.1.0_r1
repo sync -j4 -c

The repo sync command downloads the source tree. Use -j to specify parallel jobs and -c for the current branch. Resume interrupted syncs with the same command.

Device-Specific Drivers

Obtain proprietary drivers for your target hardware from the official source. Extract the archives into the AOSP root and execute the included shell scripts. Agree to the licenses when prompted. This creates a vendor directory.

Common Issues During Acquisition

  • Operating System: Use a Linux distribution. Windows file system restrictions can cause failures.
  • Python Version: The repo tool may require Python 3, but the build process needs Python 2.
  • Network Configuration: In virtual machines, use bridged networking instead of NAT for stability.
  • Interruption Handling: Disable system sleep and screen savers.
  • Sync Errors: If errors like fatal: not a git repository occur, remove the problematic project directories under .repo/projects and re-run repo sync.

Configuring the Build Environment

Java Development Kit

Install OpenJDK 8. Configure JAVA_HOME and update the PATH.

sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config java

Python Symlink

Ensure /usr/bin/python points to Python 2.

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python2 /usr/bin/python

Dependencies

Install necessary packages, including 32-bit libraries.

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install bison tree libc6:i386 libncurses5:i386 libstdc++6:i386 libxml2-utils

If libncurses5:i386 fails to install, manually download and install the .deb file along with its dependencies (e.g., libtinfo5, libc6).

Hardware Requirements

Allocate at least 12GB of RAM and 400GB of disk space.

Executing the Build

Kernel Specification

Set the path to the prebuilt kernel image for the target device. This is critical for generating the boot image.

export TARGET_PREBUILT_KERNEL=device/lge/bullhead-kernel/Image.gz-dtb

Build Commands

Navigate to the source root and execute the standard build sequence.

cd /home/user/aosp-src
source build/envsetup.sh
lunch aosp_bullhead-userdebug  # Select the appropriate target
make -j$(nproc)

The output images will be located in out/target/product/bullhead/.

Build-Time Problems

  • Jack Server: If the Jack compilation server fails, modify its configuration to increase memory and adjust stack depth limits. Restart the service.
  • SSL Errors: Edit the JDK's java.security file to remove disabled TLS protocols.
  • Locale Issues: Set export LC_ALL=C to prevent locale-related crashes.
  • Digest Algorithm Error: Ensure you are using OpenJDK 8, not the JDK bundled with AOSP.
  • Memory Mapping Failure: A known issue in art/runtime/mem_map.cc may require applying a patch to use MAP_FIXED_NOREPLACE where applicable.

Tags: AOSP Android compilation Build System Linux

Posted on Wed, 30 Sep 2026 16:17:08 +0000 by ShawnD