UncategorizedAndroidHow ToPCTutorials

How To Build Android Kernel On Windows 10 | Linux – Easy Method

Android Kernel Development: In this guide, we are going to explain to you how to build an Android kernel on Windows 10 – yes, we will still be using a Linux build environment, however, it will be a Linux subsystem inside Windows 10. So if you are a Windows 10 user interested in developing for Android, follow our guide carefully. This guide will help you to compile a custom kernel for any device owning a kernel source provided by OEM.

how to build android kernel on windows 10
How to build Android Kernel on Windows

What is Kernel?

A kernel is a system software of an operating system that carries out I/O tasks and produces an interface between hardware and software. Android kernel uses a modified Linux kernel which is documented under GNU GPL.

How to Compile Android Kernel For Specific Device:

A kernel source is provided by OEM itself which can be found at their Git-hub Repository. Note that a Kernel compiled for a particular device cannot be flashed on other devices.

Requirements (Build Kernel Android)

  • A PC with Windows 10 x64 or Linux Installed
  • Familiar with basic Linux Commands

Setting up the Linux Environment

  1. On Windows 10, go to Settings > Update and Security > For Developers > enable Developers Mode.
  2. Now go to Control Panel > Programs > Turn Windows Features On or Off > enable Windows Subsystem for Linux.
  3. Reboot your PC.
  4. Now go to the Windows app store, and download Ubuntu.
  5. Launch Ubuntu on the Windows 10 desktop, and it will request a username and password.
  6. In Ubuntu, launch the native terminal and type the following command: apt-get update
  7. This will proceed to update all repos for apps and dependencies.
  8. Next in the terminal type: sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
  9. In order to check if all dependencies were correctly installed, type ‘gcc’ in the terminal (no quotes).
  10. If “gcc” is already installed, you should see “gcc : fatal error : no input file”
  11. Now you can type ‘make’ in the terminal. If “make” is already installed, you should see “make: *** no target specified and no makefile found. stop.”
  12. Next type ‘git’, and if “git” is already installed, you should see a bunch of basic git commands.
  13. Now we need some toolchains (there are several types, including GCC, Linaro, and a few custom ones). Some devices may require different toolchains, for example, not all device kernels will boot or compile with GCC.

Accessing your Ubuntu folders from Windows 10

Your path to Ubuntu should be:

C:\Users”NAME”\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState \rootfs\home

But you should not edit files directly from Windows, as this will break the permissions on them – you would then need to reset the permissions from within the Linux terminal otherwise you will never be able to use that file again.

Setting Linux sub-system on windows finally ends here. From now a Linux user can also follow the steps. Let’s start our guide on how to build an android kernel on Windows or Linux.

For ARM Devices

We will be using GCC 4.9 for this.

  1. Open the Linux terminal and type: mkdir kernel
  2. Now type: cd mykernel
  3. (it doesn’t have to be ‘mykernel’, this is for simplicity’s sake, you can name it whatever you want.)
  4. Now type: git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.9 toolchain

For ARM 64 Devices

You need a 64-bit kernel compiler for ARM 64 devices

Download a compatible CLANG toolchain. From here AOSP Clang. Move the downloaded file in my kernel folder and then extract using the following command:

tar zxvf linux-x86-android-9.0.0_r48-clang-4691093.tar.gz

Download Kernel Source:

You are going to need to download your kernel source. Open the Linux terminal and make sure that you are in the same folder you previously created. If not then use this “cd your-folder-name” just replace the name with ur folder’s name.

Now type in terminal: “git clone “link of your device kernel source on GitHub” -b “name of the branch”

For Example: “git clone https://github.com/atxoxx/android_ke…amsung_msm8974 -b stable”

We are now done with download and installations part.

Now you have to find your defconfig. It will be named the same as your device-codename_defconfig. For Android One: sprout_defconfig or for Redmi Note 5 Pro whose codename is whyred it will be named as whyred_defconfig.

The kernel folders are typical as follows:

  • /arch/arm/configs: This contains various defconfig files for the devices.
  • /output/arch/arm/boot/: This is where the zimage will be stored. The final kernel file.

Compiling the Kernel

To make it easier, you can navigate to the location in the file explorer. It should be /home/user ID/kernel (or whatever you named the kernel folder).

You should see two folders inside, for the toolchain and the kernel source. Go inside the kernel source folder. By using “cd folder-name”

How to build Android kernel on Windows/Linux

Follow the below steps for compiling your custom Android kernel. Read all the steps carefully otherwise you may end up with an error. Cause compiling a kernel is a little complicated for newbies.

Compiling The Kernel (Build Kernel Android Arm64)

Open a terminal and use the following commands for specific device ARM/ARM64.

ARM Devices

  • cd mykernel (name of your kernel folder)
  • rm -rf out
  • mkdir out
  • export ARCH=arm
  • export SUBARCH=arm
  • export DTC_EXT=dtc
  • make O=out ARCH=arm device-code_defconfig (replace device-code with yours)
  • PATH="$(pwd)/bin:toolchain/bin:$PATH"
  • make -j$(nproc --all) O=out ARCH=arm CC-clang CLANG_TRIPLE=arm-linux-gnueabi- CROSS_COMPILE=arm-linux-androideabi-

ARM64 Devices

  • cd mykernel (name of your kernel folder)
  • rm -rf out
  • mkdir out
  • export ARCH=arm64
  • export SUBARCH=arm64
  • export DTC_EXT=dtc
  • make O=out ARCH=arm64 device-code_defconfig (replace device-code with your device)
  • PATH="$(pwd)/bin:toolchain/bin:$PATH"
  • make -j$(nproc --all) O=out ARCH=arm64 CC-clang CLANG_TRIPLE=aarch64-linux-gnu- CROSS_COMPILE=aarch64-linux-android-

Now your kernel compilation will start. It may take a while but typically not very long, compiling a kernel is not like compiling an entire Android ROM. This is CPU-dependent – for example, an AMD Phenom X4 3.4GHz with 8GB of RAM should take around 10 minutes to compile from start to finish.

When it finishes, it will notify you with a message like “zimage is ready”.

Booting The Compiled Kernel:

  • Browse to /out/arch/arm64/boot or /out/arch/arm/boot and find the (compiled zImage) and copy the file.
  • Download Android Image Kitchen and decompile your stock boot image. Once you decompile it you’ll find the stock zImage in the decompiled folder. Replace it with the one you copied earlier and recompile the boot image.
  • Flash via fastboot using the following command:
  • fastboot flash boot your-filename.img

Well, that’s it! Our guide on how to build Android kernel on Windows or Linux finally ends here. You just compiled your first kernel for your android device. This will be the basic kernel, more features can be added once your device successfully boots the kernel. In case you face any problems with kernel compilation kindly use the comment box below. Thank you!

Related Articles

Leave a Reply

Back to top button