LineageOS Compilation Guide
A complete step-by-step guide to compiling your own LineageOS and AOSP-based custom ROMs from source on a Linux virtual machine.
Note:
This guide will walk you through the entire process of setting up a build environment, syncing the source code, and compiling a custom Android ROM.
Requirements
- Linux 64-bit Virtual Machine: A powerful VM is recommended. The system used for this guide is Ubuntu 18.04 LTS on Microsoft Azure with 16GB RAM, 4 vCPUs, and a 330GB SSD.
- SSH Client: A program to connect to your VM (e.g., PuTTY, MobaXterm).
- Akhilnarang's Scripts: For easy build environment setup.
- ROM Source Code: The manifest for the ROM you want to build (e.g., LineageOS, AOSP).
- Device Source Code: The device tree, vendor tree, and kernel for your specific device.
- Sourceforge Account: For uploading your final ROM zip file.
Part 1: Compiling LineageOS
Step 1: Set up the Linux Virtual Machine
Due to the large download size (over 200GB) and high RAM usage, running your build machine on a cloud server is highly recommended.
Note:
If you have a university email address, you can get a $100 credit for free from Microsoft Azure.
Step 2: Connect to the Virtual Machine
Use your SSH client to connect to your server's IP address with your username and password.
Step 3: Install Build Environment Scripts
These scripts from Akhilnarang will automatically install all the necessary packages and dependencies for building Android.
# Clone the scripts repository
git clone https://github.com/akhilnarang/scripts.git
# Enter the scripts directory
cd scripts
# Run the setup script
. setup/android*.sh
Near the end of the installation, you will be prompted to enter your name and email address for git configuration.
Step 4: Download the ROM Source Code
First, let's create a directory for our project. We'll call it lin for LineageOS.
mkdir lin
cd lin
Now, we'll initialize the LineageOS 17.1 repository and sync the source code.
# Initialize the repository, specifying the LineageOS 17.1 branch
repo init -u git://github.com/LineageOS/android.git -b lineage-17.1
# Sync the source code. This will take a long time (1 hour+ on a fast connection)
repo sync
You may be asked if you want to enable color display; type y and press enter.
Step 5: Sync Device Source Code
Now, we need to download the source code specific to the device we're building for. In this example, we're using a Xiaomi device with the codename davinci. These git clone commands should be run from the root of your source directory (~/lin).
# Clone the hardware-specific common repository
git clone https://github.com/LineageOS/android_hardware_xiaomi.git hardware/xiaomi
# Clone the kernel source
git clone https://github.com/sm6150-dev/android_kernel_xiaomi_sm6150.git kernel/xiaomi/sm6150
# Clone the proprietary vendor files
git clone https://gitlab.com/pig.priv/proprietary_vendor_xiaomi.git vendor/xiaomi
# Clone the common device tree
git clone https://github.com/sm6150-dev/android_device_xiaomi_sm6150-common.git device/xiaomi/sm6150-common
# Clone the specific device tree
git clone https://github.com/sm6150-dev/android_device_xiaomi_davinci.git device/xiaomi/davinci
Step 6: Start the Build Process
# Set up the build environment
. build/envsetup.sh
# Start the build for your device (replace 'davinci' with your device's codename)
brunch davinci
The build process can take anywhere from a few hours to 10+ hours depending on your server's performance. The final ROM zip file will be located in the out/target/products/davinci/ directory.
Step 7: Upload the ROM to Sourceforge
First, create an account and a project on Sourceforge. Note your project name.
Navigate to the directory where your ROM zip is located (out/target/products/your_device_codename). Then use the scp command to upload.
# scp <your_rom_name>.zip <your_sf_username>@frs.sourceforge.net:/home/frs/project/<your_project_name>/
scp lineage-17.1-....zip your_username@frs.sourceforge.net:/home/frs/project/my-rom-project/
You will be prompted for your Sourceforge password, and the upload will begin.
Part 2: Compiling an AOSP-Based ROM
Steps 1-3:
Follow steps 1, 2, and 3 from the LineageOS guide above to set up your build environment.
Step 4: Download the ROM Source Code
For an AOSP-based ROM, you will use a different manifest. Go to the ROM's GitHub page to find the correct repo init command. Here is an example for ionOS:
repo init -u https://github.com/i-o-n/manifest -b ten
repo sync -c -j$(nproc --all) --force-sync --no-clone-bundle --no-tags
Step 5: Sync Device Source Code
The device sources for AOSP-based ROMs are often different from LineageOS. Find the correct repositories for your device and ROM.
# Example sources for an AOSP build
git clone https://github.com/vantoman/kernel_xiaomi_davinci.git kernel/xiaomi/davinci
git clone https://gitlab.com/pig.priv/proprietary_vendor_xiaomi.git vendor/xiaomi
git clone https://github.com/drasonn/device_xiaomi_davinci.git device/xiaomi/davinci
# Example for a custom camera
git clone https://github.com/DarkDampSquib/vendor_MiuiCamera.git vendor/ANXCamera
Step 6: File Modifications
Navigate to your device tree (device/xiaomi/davinci) and edit the makefiles to match the ROM you are building. For example, using nano AndroidProducts.mk, you might change ion_davinci.mk to havoc_davinci.mk and ion_davinci-userdebug to havoc_davinci-userdebug. You would also rename the ion_davinci.mk file to havoc_davinci.mk and edit its contents to replace references of ion with havoc. This step is highly specific to the ROM and device.
Step 7: Start the Build
The build commands for AOSP ROMs are slightly different. You typically need to run lunch before the final build command.
. build/envsetup.sh
lunch havoc_davinci-userdebug
brunch davinci
# Note: The final command can vary. Check your ROM's documentation.