1
Environment
Compile host should be Ubuntu 20.04; really avoid using other versions as they have too many pitfalls. If your Ubuntu is a different version, it is recommended to check the required libraries on the LineageOS official website.
The device is Flame, compiling LineageOS version 18. Other versions can also refer to this article, as it is detailed enough to document all the pitfalls encountered.
2
Steps
Install Platform-Tools
Be sure to remember the installation directory of platform-tools; the author installed it in the ~/android/platform-tools directory.
mkdir -p ~/android/platform-tools
cd ~/android/platform-tools
wget 4a1K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6V1L8q4)9J5k6h3N6G2L8$3N6D9k6g2)9J5k6h3y4G2L8g2)9J5c8X3q4F1k6s2u0G2K9h3c8Q4x3V1k6J5k6i4m8G2M7$3W2@1L8%4u0&6i4K6u0r3M7r3I4S2N6r3k6G2M7X3#2Q4x3X3c8@1L8$3!0D9M7#2)9J5k6r3I4S2N6r3g2K6N6q4)9J5k6r3I4A6L8Y4g2^5i4K6u0W2P5X3W2H3
Then add platform-tools to the environment variable; the author prefers to use vim for editing.
vim ~/.profile
Then add the following content to the bottom of ~/.profile, remembering to change it to your platform-tools path.
# add Android SDK platform tools to path
if [ -d "$HOME/platform-tools" ] ; then
PATH="$HOME/platform-tools:$PATH"
fi
After successfully adding, refresh the environment and check if adb has been successfully added to the environment variable. If not, it indicates there is an issue with the previous path.
source ~/.profile
Install Build Packages
The packages here can be tricky; the ones provided on the official website may not be suitable, so the author uses the following packages that can successfully compile.
sudo apt-get update
sudo apt-get install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git git-lfs gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev libelf-dev liblz4-tool libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev m4
JDK & Python
For version 18, use OpenJDK 11; just install it, and after installation, run java –version to check if it was installed successfully.
sudo apt update
sudo apt install openjdk-11-jdk
Python can be directly linked to the system’s python3.
sudo ln -s /usr/bin/python3 /usr/bin/python
Create Project Directory
Create the root directory for the project, preparing to pull the specified source code. ~/bin is for repo, and ~/android/lineage is for the Android source code.
mkdir -p ~/bin
mkdir -p ~/android/lineage
Install Repo and Set Environment Variables
Enter the ~/bin directory.
cd ~/bin
curl 8c3K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6K6N6r3!0J5j5h3N6W2i4K6u0W2k6$3!0G2k6$3I4W2j5i4m8A6M7#2)9J5k6h3y4G2L8g2)9J5c8X3N6A6N6q4)9J5k6s2u0W2M7r3!0Q4x3X3c8V1L8%4N6F1L8r3!0S2k6s2y4Q4x3V1k6J5k6i4m8G2i4K6t1$3L8X3u0K6M7q4)9K6b7W2)9J5y4X3N6@1i4K6y4n7i4K6t1$3L8X3u0K6M7q4)9K6b7W2)9%4c8g2)9J5c8X3u0A6L8W2)9J5c8Y4u0W2M7r3)9`.
chmod a+x ~/bin/repo
Then add the repo directory to the environment variable.
vim ~/.profile
Add the following content to the bottom of the file, ensuring it corresponds to your repo’s directory.
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Then run source ~/.profile to refresh the environment variable.
source ~/.profile
Configure Git
Fill in arbitrarily.
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
Enable Cache
Enable cache to speed up code synchronization. If your hard drive is large enough, over 500G, the size specified for ccache can be 100G; if not, specify 50G.
export USE_CCACHE=1
export CCACHE_EXEC=/usr/bin/ccache
ccache -M 100G
ccache -o compression=true
Initialize LineageOS Source Repository
cd ~/android/lineage
repo init -u 164K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6Y4K9i4c8Z5N6h3u0Q4x3X3g2U0L8$3#2Q4x3V1k6x3K9h3&6W2j5h3N6W2e0#2y4Q4x3V1k6S2L8X3c8J5L8$3W2V1i4K6u0W2k6$3W2@1i4K6t1$3L8X3u0K6M7q4)9K6b7W2)9J5k6r3u0Q4x3U0k6F1j5Y4y4H3i4K6y4n7L8r3W2F1k6h3q4Y4k6g2)9J5k6o6p5^5i4K6u0W2x3g2)9J5y4X3&6T1M7%4m8Q4x3@1u0Q4x3X3c8Q4x3X3c8Y4K9i4c8Q4x3X3c8D9k6Y4y4Q4x3U0k6F1j5Y4y4H3i4K6y4n7i4K6u0V1i4K6u0V1L8X3!0Q4x3X3c8U0L8r3!0F1k6g2)9J5k6r3u0#2L8X3c8D9k6b7.`
Executing the command below will download the source code. You can specify the number of threads based on the number of CPU cores in your current Ubuntu, generally twice the number of cores. The author’s core count is 10, so 20 threads are specified. Note that errors during synchronization are normal, as the official site limits the number of requests in a short period; just wait it out.
repo sync -j 20
After this command completes, remember to run repo status to check the current synchronization status. If you see “nothing to commit,” it indicates synchronization is complete, and you can skip the notes below. Once synchronization is complete, the source code has been successfully pulled, and you can proceed to the next step.
Note, if the above-mentioned words do not appear, it indicates failure. In case of failure, it is recommended to execute the repo sync command to complete it, but it is best not to specify multiple threads.
repo sync
Prepare Device-Specific Code
Enter the root directory of the Android source project, then run the command below to download the device-specific configurations and kernel. Here, Flame is my device code; other device codes need to be looked up and replace Flame with your device code.
cd ~/android/lineage
source build/envsetup.sh
breakfast flame
The first time you run the breakfast command, the following error will occur, which I believe is the biggest pitfall.
kerneldev@ubuntu:~/android/lineage$ breakfast flame
In file included from build/make/core/config.mk:291:
In file included from build/make/core/envsetup.mk:266:
device/google/coral/device-lineage.mk:113: error: _nic.PRODUCTS.[[device/google/coral/lineage_flame.mk]]: "vendor/google/flame/flame-vendor.mk" does not exist.
19:31:40 dumpvars failed with: exit status 1
Device flame not found. Attempting to retrieve device repository from LineageOS Github (72cK9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8X3N6A6N6r3S2#2j5W2)9J5k6h3y4G2L8g2)9J5c8X3N6A6N6q4)9J5k6s2u0Q4x3U0k6F1j5Y4y4H3i4K6y4n7L8r3W2F1k6h3q4Y4k6g2)9J5k6o6p5^5i4K6u0W2x3g2)9J5y4X3&6T1M7%4m8Q4x3@1u0Q4x3X3c8Q4x3X3c8Y4K9i4c8Q4x3X3c8D9k6Y4y4Q4x3U0k6F1j5Y4y4H3i4K6y4n7i4K6u0V1i4K6u0V1L8X3!0Q4x3X3c8U0L8r3!0F1k6g2)9J5k6r3u0#2L8X3c8D9k6b7.`
The key phrase is “vendor/google/flame/flame-vendor.mk” does not exist. The reason is that the device-specific content has not yet been pulled into the current project, causing this error when building the device image. Below is the solution.
Resolve Breakfast Error
The official website provides two solutions, but I find both inconvenient, so here I will use the solution I discovered, as it is genuinely simple.
First, create the ~/android/system_dump/ directory and enter it.
mkdir ~/android/system_dump/
cd ~/android/system_dump/
The reason for this issue is that the current project lacks the specific content for the specified device, so it cannot be built. Therefore, we can extract the existing specific content ourselves.
Extract Device-Specific Content
At this point, you need to go to: https://lineage-archive.timschumi.net/
Find the corresponding package for your model and version to download. Note that there may be multiple packages for one model and version; just download one. After downloading, extract the payload.bin file from it.
For Windows, use the tool from https://pan.quark.cn/s/bf6a4ce548aa to place the payload.bin in the tool’s directory, then double-click to open the CMD command line .bat file and press a to extract everything. The extracted images will be saved in the img directory of the current directory.
For Linux, use the tool from https://pan.quark.cn/s/318bd8bf5fe1 and execute payload-dumper-go payload.bin.
Then copy all the extracted images to the ~/android/system_dump/ directory. For LineageOS 18, you need to mount the following images; for others, refer to whether your unpacked content contains these images and mount accordingly. Higher versions will have more images, and the author cannot specifically determine which need to be mounted, but a tip is that if you do not mount enough here, you will encounter file not found issues during compilation. If you confirm that the reported files are not in the project, it indicates that you have mounted too few.
cd ~/android/system_dump/
mkdir system/
sudo mount -o ro system.img system/
sudo mount -o ro vendor.img vendor/
sudo mount -o ro product.img product/
sudo mount -o ro system_ext.img system_ext/
Next, enter your device’s specific directory and execute the command below.
cd ~/android/lineage/device/google/flame
./extract-files.sh ~/android/system_dump/
Running this command may also produce errors because the file paths recorded in the ./extract-files.sh script are incorrect. You need to modify them according to the error prompts to find the correct paths. I used the find command to locate the erroneous paths and modified them accordingly, after which running the above command successfully extracted the files.
Compile
During the compilation process, interruptions may occur. Although there are errors, they are likely due to insufficient swap space, so it is recommended to modify the swap space size to match the memory size. Below are the commands to modify the swap space.
sudo swapoff /swapfile
sudo rm /swapfile
sudo dd if=/dev/zero of=/swapfile bs=1M count=32768 status=progress # Set size to 32G
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
To automatically mount the swap space after each system reboot, execute the command below.
sudo vim /etc/fstab
# Add the following line at the bottom: /swapfile none swap sw 0 0
Then run swapon –show to verify the swap space size; if you see the specified size, it is correct.
At this point, the device-specific content has been extracted into the current project, and you can prepare for compilation. Below is the author’s own compilation method, as the author needs to use an OTA package and recommends this method.
Note that the author is compiling the user version of the image. If you do not consider the version, after running source build/envsetup.sh, you can directly run the brunch flame command, which will automatically compile the userdebug version of the image.
cd ~/android/lineage
source build/envsetup.sh
lunch lineage_flame-user # Compile user version image
m # Compile at full speed
After full-speed compilation is complete, execute the make otapackage command to generate the OTA package. The generated OTA package will have the same format as the one downloaded from the previous website, which serves as the author’s system flashing package.
make otapackage
Flashing
You can use other methods to complete the flashing, but the author prefers the method below.
After compilation is complete, you need to extract boot.img from the OTA, and both boot.img and OTA will serve as flashing materials.
Your device needs to first flash the corresponding official Google system for the Android version before following the steps below to flash.
adb reboot bootloader
fastboot flash boot boot.img
Press the volume down key to enter recovery mode. In recovery mode, first perform Factory reset -> Format data/factory reset to clear the current data.
Then return, enter Apply update -> Apply from ADB, and execute the command below to complete the flashing. This process takes a while; after flashing, you can reboot the phone, and upon startup, you will find yourself in LineageOS.
adb sideload the OTA package generated
3
Build Development Environment
Import Source Code into Android Studio
cd ~/android/lineage/
source build/envsetup.sh
mmm development/tools/idegen/
development/tools/idegen/idegen.sh
After execution, an Android.ipr file will be generated in the project root directory, which is the file to be imported.
Import Source Code into CLion
cd ~/android/lineage/
source build/envsetup.sh
export SOONG_GEN_CMAKEFILES=1
export SOONG_GEN_CMAKEFILES_DEBUG=1
lunch lineage_flame-user
m
CMakeLists.txt will be generated at out/development/ide/clion/art/runtime/libart-arm64-android/CMakeLists.txt
Open CMakeLists.txt with CLion.
Go to tools -> cmake -> Change Project Root.
Select the AOSP source root path and wait for parsing to complete.

Author ID:b1n_
https://bbs.kanxue.com/user-home-981967.htm
*This article is an excellent piece from the Kanxue Forum, authored by b1n_, please indicate the source when reprinting from the Kanxue community.
# Previous Recommendations
1、Android Shell Learning Record (Part 2) – Analysis of a Free Version of Some Protection
2、Reverse Analysis: Related Analysis of Win10 ObRegisterCallbacks
3、VMP Introduction: Analysis of VMP1.81 Demo
4、Tencent 2025 Game Security PC Direction Preliminary Contest Solutions
5、OLLVM Strategy Notes
6、Android Shell Learning Record (Part 1)


Share

Like

Watch

Click to read the original text for more.