en Compiling on a Mobile Device - JackA1ltman/NonGKI_Kernel_Build_2nd GitHub Wiki

Compiling the Kernel on a Mobile Device

Compared to a PC or server, ARM-based mobile devices come with meaningful constraints — performance, thermal throttling, and memory limits all make the experience noticeably different. That said, it is entirely doable.

This guide uses an Android-based mobile device as the reference platform.

If kernel compilation is your only goal, a mobile device offers far worse cost-efficiency than even a basic entry-level server. Make sure this is what you want before proceeding.

Note: This project does not natively support compilation under ARM architecture, if you have the need, you can only realize the support by modifying the project source code.


Setting Up the Environment

Choose a Container Solution

Several options are available for running a Linux environment on Android:

Method Notes
Proot No root required, broadest compatibility, slightly lower performance
Chroot Requires root, better performance
LXC Requires root, near-native performance, good isolation
Docker Requires root, convenient, depends on kernel support

Compatible terminal apps include Termux, Droidspaces, and others.

This guide uses LXC + Droidspaces.

Prepare a Rootfs

Ubuntu 24.04 ARM64 Rootfs is the recommended choice.

You can get a Rootfs using the following project:

Build the Base Compilation Environment

After booting into the Rootfs, install the required dependencies:

apt update && apt upgrade -y
apt install gcc clang make git bison flex libssl-dev ccache cpio -y

The base environment is now ready.


Compiling the Kernel

This example uses the LineageOS OnePlus SM8250 kernel on branch lineage-23.2.

Step 1: Get the Kernel Source

git clone -b lineage-23.2 \
  https://github.com/LineageOS/android_kernel_oneplus_sm8250.git \
  kernel_sm8250 --depth 1

cd kernel_sm8250/

Step 2: Generate the .config File

make ARCH=arm64 CC="ccache clang" O=out \
  vendor/kona-perf_defconfig vendor/oplus.config

Step 3: Build

make ARCH=arm64 CC="ccache clang" O=out \
  -j$(nproc --all) 2>&1 | tee error.log

Adjust the -j value to match what your device can handle. -j$(nproc --all) uses all available cores, but mobile devices running at full load for extended periods tend to throttle due to heat — sometimes a lower value like -j4 produces a more stable build.

On a OnePlus 8, expect an initial build to take roughly 30 minutes to 1 hour.

Done

Once the build completes, look for an Image entry in the log output — that confirms a successful build. On stock-based ROM devices, the image can be flashed and booted immediately for verification.