Assembling the kernel Android is a key step for developers who want to optimize device performance, add support for new hardware, or fix critical bugs in standard firmware. This process requires not only technical knowledge, but also attentiveness: one error in the configuration can lead to "brick" (total inoperability) of the gadget. Unlike assembling custom firmware (for example, LineageOS), kernel compilation affects low-level system components that directly interact with the hardware.
In this guide, we will analyze the entire process - from preparing the working environment to the final kernel firmware on the device. We will pay special attention to the typical mistakes of beginners: incorrect choice of source branch, dependency conflicts and problems with drivers. The material is aimed at users with basic knowledge Linux i Git, but even if you have never compiled a kernel, you can achieve results step by step. For clarity, we give examples of commands and configurations for popular devices on chips Qualcomm Snapdragon i Mediatek.
1. Preparing the working environment
Before you start assembling, you need to configure the system. The best option is Ubuntu 22.04 LTS or Debian 11 with a minimal graphical shell (for example, Xfce). Virtual machines are suitable for testing, but for the final build it is recommended to use hardware: compiling the kernel can take several hours and require up to 16 GB of RAM.
Install the required packages:
sudo apt update && sudo apt install -y \git build-essential bc bison flex libssl-dev \
libelf-dev python3 python3-pip ccache
To speed up the build, configure ccache (caching intermediate files). If the repositories have an outdated version, install it manually:
export USE_CCACHE=1export CCACHE_DIR=~/.ccache
prebuilts/misc/linux-x86/ccache/ccache -M 50G
If you are using SSD, place the folder ccache on it - this will reduce compilation time by 20-30%.
Check version GCC - required for modern kernels version 9.3 or later. If the repositories have an outdated version, install it manually:
sudo add-apt-repository ppa:ubuntu-toolchain-r/testsudo apt install gcc-12 g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100
2. Selecting kernel sources
The source code of the Android kernel is stored in the repositories of chipset manufacturers or on GitHub in custom firmware projects. The main rule: the kernel version must exactly match the device model and version of Android. For example, a kernel for Samsung Galaxy S21 on Android 13 is not suitable for Xiaomi Redmi Note 10 even with the same OS version.
Main source sources:
- ๐น Official repositories: Qualcomm (
CodeAurora), Mediatek, Samsung Open Source. Typically contain basic drivers, but may lack proprietary components. - ๐น Custom projects: LineageOS, ArrowOS, Pixel Experience. Often include patches to improve performance and compatibility.
- ๐น Forks for specific devices: search by model on XDA Developers or 4PDA. For example, kernel
Kirisakurafor Google Pixel.
Clone the repository (example for Qualcomm SM8250):
git clone --depth=1 https://github.com/LineageOS/android_kernel_qualcomm_sm8250 -b lineage-20
How to find the correct kernel branch?
To determine the desired branch, check the current version of the kernel on the device via command uname -a or in the application CPU-Z. Then compare it with the tags in the repository. For example, if the output of the command contains 4.19.157, look for a branch with the same number or higher, but not lower!
3. Setting up the kernel configuration
After downloading the sources, you need to generate a configuration file (.config). To do this, use the standard kernel configurator menuconfig or download a ready-made file for your device (usually called vendor/device_defconfig).
Basic commands:
# Loading default configurationmake ARCH=arm64 vendor/device_defconfig
Launch the graphical configurator
make ARCH=arm64 menuconfig
In menuconfig pay attention to the following options:
- ๐ง CPU Frequency scaling: enable governors (
ondemand,performance) to control the clock frequency. - ๐ง Device Drivers โ GPU: check your GPU support (for example
Adreno 650for Snapdragon 865). - ๐ง File systems: add support
F2FSorEXT4depending on the partition/data. - ๐ง Power management: disable unnecessary options to save battery (for example,
CONFIG_SUSPEND).
After configuration, save the configuration and check it for errors:
make ARCH=arm64 savedefconfig
scripts/kconfig/merge_config.sh -m .config vendor/device_defconfig
4. Compilation kernel
The compilation process depends on the power of your PC. On Ryzen 7 5800X s 32 GB RAM the assembly takes ~30-40 minutes, on weak machines - up to 2-3 hours. Use the flag -j for parallel compilation (recommended number of CPU cores + 1).
Basic command:
make -j$(nproc --all) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
If the build was interrupted with an error, check:
- โ ๏ธ Out of memory: add a swap file (
sudo fallocate -l 8G /swapfile). - โ ๏ธ Lack of dependencies: install missing packages using error logs.
- โ ๏ธ Conflicts in .config: run
make oldconfigand answer the questions.
After successful compilation, a file arch/arm64/boot the file will appear Image.gz-dtb (or Image.lz4-dtb for some devices) will appear in the folder. This is your new kernel. You may also need a module dtbo.img (for devices with dynamic ones). sections).
The file Image.gz-dtb has been compiled|There is a backup copy of the current kernel|The battery is โฅ50% charged|The factory antivirus is disabled|MD5 hashes of the files have been checked-->
5. Firmware of the kernel on the device
There are several ways to install the kernel: via fastboot, TWRP or specialized applications like Kernel Flashifier. The first method is the most reliable, but requires an unlocked bootloader. The second is suitable for devices with custom recovery.
Method 1: Via fastboot
- Reboot the device. mode
fastboot(adb reboot bootloader). - Flash the kernel and (if necessary)
dtbo:fastboot flash boot Image.gz-dtbfastboot flash dtbo dtbo.img - Reboot the device:
fastboot reboot.
Method 2: Via TWRP
- Copy
Image.gz-dtbto the device. - In TWRP select
Install โ Install Image โ select file โ Boot. - Flash
dtbo.imgsimilarly, if required.
After The first startup of the firmware may take up to 10 minutes - do not interrupt the process!
If the device does not boot:
โ ๏ธ Attention: When "bootloop" (cyclic reboot), try flashing the original kernel via fastbootIf the screen is black, check the compatibility of the kernel with the version. bootloader โ sometimes a rollback to an older firmware is required.
6. Optimization and debugging
After successful loading, check the functionality of the kernel:
- ๐ฑ Performance: run AnTuTu or Geekbench for comparison with the original core.
- ๐ Autonomy: track battery consumption in
Settings โ Battery. - ๐ก๏ธ Temperature: use CPU Monitor to check overheating.
To troubleshoot problems:
- ๐ Kernel logs: get them through
adb shell dmesg > kernel_log.txt. - ๐ง Setting governors: change the frequency control policy c Kernel Adiutor.
- ๐ก Wi-Fi/Bluetooth: if they donโt work, check the enabled modules in
.config.
Typical errors and solutions:
| Problem | Possible cause | Solution |
|---|---|---|
| The device does not turn on | Incompatible kernel with bootloader | Flash the original kernel + update firmware |
| Constant reboots | Error c RAMdisk or SELinux |
Check the logs for avc: denied |
| The camera does not work | The driver is missing msm_camera |
Add the module to the kernel configuration |
| Overheating processor | Incorrect settings thermal-engine |
Edit thermal-zones in DTS |
7. Build automation (CI/CD)
To regularly update the kernel, set up automatic build using GitHub Actions or GitLab CI. This will allow you to test changes without manual compilation. Example configuration for GitHub Actions:
name: Kernel Buildon: [push]
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- run: |
sudo apt update
sudo apt install -y gcc-12 aarch64-linux-gnu
make ARCH=arm64 vendor/device_defconfig
make -j$(nproc) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
For notifications about build results, integrate Telegram-bot or Discord-webhook. This is especially useful for team development or support of custom firmware.
โ ๏ธ Attention: CI/CD setup details may vary depending on the repository's security policy. For example, Qualcomm requires signed images for some chipsets - in this case, you will need to add a signature step to the pipeline.
8. Modern trends in the development of Android kernels
In 2026โ2026, key changes in the development of kernels for Android are associated with:
- ๐ค Android 15: support for new
Android Runtime (ART)and optimization forARMv9. - ๐ Security: mandatory enable
Kernel Address Space Layout Randomization (KASLR). - โก Performance: integration
Schedutilinstead ofondemandto control the CPU. - ๐ฑ Foldable devices: support for dynamically changing screen resolution.
To experiment with new features, it is recommended to use Google Pixel or devices on Snapdragon 8 Gen 3 โthey are the first to receive updates from Qualcomm and Google.
Follow the updates in repositories Android Common Kernel (https://android.googlesource.com/kernel/common) - patches for new versions of the OS are published there.
FAQ: Frequently asked questions about building the Android kernel
Is it possible to build the kernel on Windows?
Technically, yes, but this is highly not recommended. For Windows you will need WSL2 (Windows Subsystem for Linux) installed Ubuntu 22.04, however, problems may arise with USB drivers when flashing the firmware. The best option is a separate PC or a virtual machine with a full-fledged Linux.
How to find out which kernel is installed on my device?
Use the command adb shell cat /proc/version or application CPU-Z (section Kernel). The command uname -ais also useful, which will show the kernel version, architecture and build date.
Do I need to sign the kernel for firmware?
For most devices with an unlocked bootloader, signing is not required. However, some manufacturers (for example Samsung or Huawei) use AVB 2.0 (Android Verified Boot), which verifies the kernel signature. In this case, you will need to disable verity or use tools like Magisk to bypass the check.
What to do if the Magisk module stops working after updating the kernel?
Update Magisk to the latest version and reinstall it via fastboot or TWRP. If the problem persists, check whether the option CONFIG_OVERLAY_FS is enabled in the kernel configuration - it is necessary for the modules to work.
How to return the original kernel?
Download the stock firmware for your device (for example, from the site Xiaomi or Samsung) and flash the file boot.img via fastboot flash boot boot.img. Alternatively, you can use a backup copy made in TWRP before the experiments.