sodcalculator

10 Tech How-To

Build Android Kernel on Windows 10: Step-by-Step

Guide 10-60696 · Updated · Step by step

Building an Android kernel on Windows 10 is possible using the Windows Subsystem for Linux (WSL) or a virtual machine. This guide walks you through the entire process, from setting up the environment to compiling a bootable kernel image. You’ll need a 64-bit Windows 10 PC, a decent internet connection, and about 20 GB of free disk space.

What You’ll Need

  • Windows 10 (64-bit) with administrator access
  • At least 20 GB of free disk space (more recommended)
  • An Android device (for testing the kernel, optional but recommended)
  • Basic familiarity with command-line tools

Step-by-Step

  1. Enable Windows Subsystem for Linux (WSL)
    Open PowerShell as Administrator and run: wsl --install. Reboot when prompted. This installs WSL2 and a default Linux distribution (usually Ubuntu).
  2. Install a Linux distribution
    After reboot, launch the installed Linux distribution from the Start menu. Complete the initial setup (create a username and password). If you prefer a different distro, use wsl --install -d Ubuntu-22.04.
  3. Update the Linux environment
    Inside WSL, run: sudo apt update && sudo apt upgrade -y. This ensures you have the latest packages.
  4. Install essential build tools
    Run: sudo apt install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig -y. These are required to compile the kernel.
  5. Install a compatible Java version (if needed)
    Some kernel builds require Java for tools like mkbootimg. Install OpenJDK 8 or 11: sudo apt install openjdk-8-jdk (or openjdk-11-jdk).
  6. Set up a working directory
    Create a directory for your kernel source: mkdir ~/kernel && cd ~/kernel.
  7. Download the kernel source
    You need the correct kernel source for your device. For example, for a Pixel device: git clone https://android.googlesource.com/kernel/msm (or the specific branch for your device). Check your device’s kernel version and branch on the Android Open Source Project (AOSP) website.
  8. Checkout the correct branch
    Navigate into the kernel directory (cd msm) and list branches: git branch -a. Checkout the branch that matches your device’s kernel version, e.g., git checkout android-msm-crosshatch-4.9-pie.
  9. Install the cross-compiler toolchain
    You need a toolchain to compile for ARM or ARM64. Download the prebuilt toolchain from AOSP: git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 (for 64-bit). For 32-bit, use arm-linux-androideabi-4.9.
  10. Set up environment variables
    Export the toolchain path and architecture variables. For 64-bit:
    export ARCH=arm64
    export CROSS_COMPILE=aarch64-linux-android-

    Then add the toolchain to your PATH: export PATH=$PATH:~/kernel/aarch64-linux-android-4.9/bin.

  11. Configure the kernel
    You need a defconfig file for your device. Find it in arch/arm64/configs/ (or arch/arm/configs/). For example: make crosshatch_defconfig.
  12. Build the kernel
    Run make -j$(nproc) to start the compilation. The -j flag speeds up the build by using multiple cores. This can take from 20 minutes to several hours depending on your CPU.
  13. Locate the compiled kernel image
    After a successful build, the kernel image is usually at arch/arm64/boot/Image.gz-dtb (or Image for older devices). This is the file you’ll flash.
  14. Copy the kernel to Windows
    To access the file from Windows, copy it to the Windows filesystem: cp arch/arm64/boot/Image.gz-dtb /mnt/c/Users/YourUsername/Desktop/.
  15. Flash the kernel (optional)
    To test, you’ll need to unlock your bootloader, boot into fastboot mode, and run: fastboot flash boot Image.gz-dtb. This is device-specific and may void your warranty.

Common Mistakes

  • Using the wrong toolchain – Ensure the toolchain matches your device’s architecture (arm vs arm64).
  • Incorrect defconfig – Using a defconfig from a different device will likely result in a boot loop or non-booting kernel.
  • Missing dependencies – Forgetting to install packages like libncurses5-dev (for menuconfig) can cause errors.
  • Outdated source – Always fetch the latest source and use the correct branch for your device’s Android version.
  • Not cleaning the build – If you change defconfig, run make clean first to avoid stale object files.

Tips

  • Use make menuconfig to customize kernel options before building.
  • Save your build configuration: make savedefconfig to create a minimal defconfig.
  • Build with CCACHE to speed up subsequent builds: export CCACHE=ccache and install ccache.
  • Keep your kernel source in WSL, not on the Windows filesystem, to avoid performance issues.
  • Join XDA-Developers forums for device-specific guidance.

Troubleshooting

  • Build fails with “No rule to make target” – This usually means you haven’t set the ARCH or CROSS_COMPILE variables correctly. Re-check your exports.
  • Out of memory during build – Reduce the number of parallel jobs: make -j2. Also close other applications.
  • WSL is slow – Ensure you’re using WSL2 (check with wsl -l -v). If not, upgrade: wsl --set-version <distro> 2.
  • Missing “flex” or “bison” errors – Install them: sudo apt install flex bison.
  • Kernel boots but Wi-Fi doesn’t work – You likely need to include the correct firmware or drivers in the kernel config. Check the defconfig for your device.
  • Device stuck at boot logo – This is often due to a mismatch between the kernel and the device’s ramdisk. Ensure you’re using the correct DTBs and ramdisk.

Frequently Asked Questions

Can I build the kernel directly on Windows without WSL?

It’s possible using Cygwin or MSYS2, but it’s much more complex and prone to errors. WSL is the recommended method because it provides a native Linux environment.

How long does the build take?

On a modern quad-core CPU with 8 GB RAM, it typically takes 30–60 minutes. With more cores, it can be faster.

Do I need to unlock my bootloader to flash the kernel?

Yes, most devices require an unlocked bootloader to flash a custom kernel. This usually voids your warranty and may wipe your data.

What is a defconfig file?

A defconfig file contains the default configuration for a specific device, specifying which drivers and features are enabled. You can generate one with make defconfig.

Can I use the same kernel for different Android versions?

No, kernel versions are tied to the Android version. Using a kernel built for Android 9 on Android 10 will likely cause issues.

What if my device isn’t listed in the AOSP kernel repository?

You may need to get the kernel source from the device manufacturer’s website or from a custom ROM community like LineageOS.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →