How to build
First, you should read the official Android documentation for kernel build:
WARNING
This page is for GKI devices, if you use an old kernel, please referIntergrate for non-GKI devices.
Build kernel
Sync the kernel source code
repo init -u https://android.googlesource.com/kernel/manifestmv <kernel_manifest.xml> .repo/manifestsrepo init -m manifest.xmlrepo sync
The<kernel_manifest.xml>
file is a manifest that uniquely identifies a build, allowing you to make it reproducible. To do this, you should download the manifest file fromGKI release builds.
Build
Please check theBuilding kernels first.
For example, to build anaarch64
kernel image:
LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh
Don't forget to add theLTO=thin
flag; otherwise, the build may fail if your computer has less than 24 GB of memory.
Starting from Android 13, the kernel is built bybazel
:
tools/bazel build --config=fast //common:kernel_aarch64_dist
INFO
For some Android 14 kernels, to make Wi-Fi/Bluetooth work, it might be necessary to remove all GKI protected exports:
rm common/android/abi_gki_protected_exports_*
Build kernel with KernelSU
If you can successfully build the kernel, adding support for KernelSU will be relatively easy. In the root of kernel source directory, run any of the options listed below:
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s main
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s v0.5.2
Then, rebuild the kernel and you will get a kernel image with KernelSU!