If you’ve been building Android for a while, or even if you’re into the custom-ROM scene, it’s likely you’ve heard of LineageOS. If you’re looking for the device tree for a specific device, the project’s Github should be your first stop. If you’re building Lineage by itself or another ROM based off of it, you don’t usually need to do anything with the device tree after cloning it. Just get the rest of the necessary files for your target device in place and build away!
But what if you want to build a ROM that’s not based off of Lineage? (i.e. plain AOSP, AOSP Extended, or the like)? If you try to use a Lineage device tree when building a non-Lineage ROM, it won’t get as far as allowing you to run ‘lunch’ successfully. To get it to compile, we’ll need to change some things around. From here on in, we’ll assume you already know the basics of building ROMs. (Setting up the environment, downloading source code, the proper commands to build a ROM, and whatnot.) We’ll be using AOSP Extended as the ROM we’re building, and the Xiaomi Mi Mix 2S (polaris) as our guide.
First order of business is to get the device we want to show up as an option on the ‘lunch’ menu. In a terminal, use the text editor of your choice to create a file in the device tree you’re adapting for AOSP. (For example: “device/oem/codename”. This will vary for you, depending on the OEM and the device’s codename.)
Put the following text into it (without quotes, replace “[codename]” with the device’s actual codename): “add_lunch_combo aosp_[codename]-userdebug” It should look like this:
Save the file and exit. Run “. build/envsetup.sh” to see if it’s worked. If you see a line containing “including device device/oem/codename”, then you’re done with the first step.
Though you can now run ‘lunch’ for the device successfully, any build you start will still fail. To get around this, we need to remove any mention of Lineage’s files from the build tree. To start, cd into your device tree. (device/oem/codename)
First, delete the file “lineage.dependencies” and the folder “overlay-lineage”. Next, rename the file “lineage_codename” to “aosp_codename” and open it in a text editor.
Under the comment “Inherit some common Lineage stuff,” change the file path to “vendor/aosp/common.mk”. (Note – this may vary depending on the ROM you’re building, but usually the path remains similar. If in doubt, start your search in the vendor/ directory.
After “PRODUCT_NAME”, change “lineage_codename” to “aosp_codename”. You’re done with this file. Save and exit.
Next, we’ll edit the common files for the device’s chipset. (examples: sdm845, msm8996, path should be “device/oem/chipset-common”) This is where we’ll be doing most of our work. cd over to its directory and open the makefile for the chipset (sdm845.mk, msm8996.mk, etc.) in a text editor.
Next, find two entries. They should be under the comments “Trust HAL” and “LiveDisplay”.
Erase the entire blocks, starting with “PRODUCT_PACKAGES” and ending with the package names themselves. If you want, you can also delete the comments above the package names being removed, but it’s your choice. Save and exit.
Once you’re back in the directory, remove the “overlay-lineage” and “livedisplay” folders and the “lineage.dependencies” file. Afterwards, cd into the directory “sepolicy/private”.
Remove the files “hal_lineage_trust_default.te” and “hal_livedisplay_default.te”. Open “file_contexts” in a text editor.
Remove anything under the headings “LiveDisplay HAL” and “Trust HAL”. Save the file and exit.
And you’re done! You should be able to build AOSP and ROMs based on it successfully with your newly-edited device trees. There may be a few minor edits needed depending on the ROM being built and what version of Lineage the device tree corresponds to (anything pre-15.1 may not have the Trust entries, for example), but this should be a good starting point. If you need a reference, I’ll have the device trees used in this tutorial up on my Github, so you can see for yourself what it looks like. Thanks for reading, and if you have further questions about the guide, feel free to ask!