Android Kernel Compilation Guide

Android phones run on a modified Linux kernel with a modified FHS.

To Compile an android kernel,
You need :-

The kernel source (custom preferably as stock can fuck up things)
A toolchain ( depending on the kernel version)
A Linux system ( on android chroot env works)

Always remember for kernels newer than 3.xx use O=out at every compilation command

Also remember to do a test build first (without any additional stuffs) and if it works then modify and make 2nd build. For 2nd build use ccache to low down compilation time.

Once you cloned the kernel and the toolchain

move the toolchain inside the kernel dir

Then export the things below (edit as u wish)

export ARCH=arm64
export SUBARCH=arm64
export CONFIG=name_defconfig
export CURRENTDIR=$(pwd)
export CROSS_COMPILE=$CURRENTDIR/path/to/toolchain
export CROSS_COMPILE_ARM32=$CURRENTDIR/path/to/toolchain
export CLANG_TOOLCHAIN=/path/to/clang

make O=out $CONFIG
make O=out menuconfig

For test build just hit save and exit
For next build modify stuffs for ur needs

cp -rf out/.config arch/$ARCH/configs/$CONFIG

Then comes the main part

make O=out CC=clang $CONFIG
make O=out CC=clang

After compilation done go to out/arch/$ARCH/boot/

And see if image.gz is there. If it is there then use it to make a and flash it. If it boots then voila, you have compiled ur own android kernel.

Thatโ€™s all for now.

Stay tuned for more interesting Content!

:o: Know more about us
Telegram: Contact @vyuhainfinity | Telegram: Contact @cybernityorg


hi cyber good article :grinning:

Idk why guides look hell morr easy than actual process

because it is easy if one has interest :smiley:

1 Like

Sometimes stupidity defies interest โ€ฆxd


compiling a kernel is easy. maintaining it, making it stable, fixing errors, fixing merge conflicts, fixing weird bugs on the other hand isnโ€™t easy.

Hey knight, I have a micromax mobile which is dumped into my drawer and it is very old it is 4g 4gb ram and maybe less space. That phone hangs alot gives errors which arenโ€™t errors it shows bluetooth not working and shit. So can I play with it and make it work cause deep down in my mind I want that for myself xD. Can I do something with it?

You can. Try to find more about the device on XDA. If you get any kernel source, itโ€™ll be noice. Or just try to find a way to unlock the bootloader and flash magisk. Rest probably would be easy.

Hmm xda is new to me Iโ€™ll check and try to fix this mobile

When BT wonโ€™t work, check if the MAC Adress does still existing. If not, you have a semi-bricked phone :I

Hmm Iโ€™ll check how to check that xD