In this guide, we are going to show you how to build an Android kernel on Windows 10 – yes, we will still be using a Linux build environment, but it will be a Linux subsystem within Windows 10. So if you are a Windows 10 user interested in developing for Android, follow our guide carefully. In this guide, we will specifically be learning how to build a kernel for ARM and MediaTek devices, adding features, and a basic overview of using Git.

Requirements

Setting up the Linux Environment

For ARM Devices

We will be using GCC 4.7 for this.

For ARM 64 Devices

You need a 64-bit kernel compiler for ARM 64 devices, for example aarch64.

Getting the Source Files for your Device

This is a tricky part, as you need to find a GitHub repo that hosts your kernel source. You will of course need to search for it, most likely it can be found on XDA forums. Here is an example kernel source Git. On the upper left side, you should see “Branch: Completed by xxxx”. There are different versions of a kernel / project, usually separated by “Testing”, “Beta”, “Final Release”, etc. The kernel folders are typically as follows:

/arch/arm/configs: This contains various config files for the device, such as governors, etc./output/arch/arm/boot/: This is where the zimage will be stored.build.sh: A script that will simplify the building process./arm-cortex-linux-gnueabi-linaro_5.2-2015.11-2: This is typically a toolchain placed in the kernel source, thus making it easier to find.

You are going to need to download your kernel source. Open the Linux terminal and make sure that you are in the kernel folder you previously created (cd kernel). Then type in terminal: “git clone “URL of the github kernel” -b “name of the branch” For Example: “git clone https://github.com/atxoxx/android_ke…amsung_msm8974 -b xenomTW”

Building 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.

For ARM Devices

In a terminal, type the following commands: Here is an overview of what these commands do, to make this easier in the future. Another example:

For ARM 64 Devices

For Mediatek (MTK) Devices

When you have completed the steps necessary to your kernel architecture, you can type in the terminal: sudo bash build.sh You will then enter your user password, and the compiling process will begin. It may take a while but typically not very long, compiling a kernel is not like compiling an entire Android ROM. This is really 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 should notify you with a message like “zimage is ready”.

ARM and ARM64 Devices

Go to “/Output/arch/arm/boot/” to find your zimage.

Mediatek Devices

Go to “/arch/arm/boot/” to find your zimage. Not all kernel builds will result in a Zimage file, it can sometimes be built as other image formats. Important: If you are going to compile again, it is recommended that you enter the commands make clean and make mrproper before you begin the compile process again.

Making the Kernel Boot

There are two options for you to choose. You can either use the anykernel method (as defined by XDA user @osm0sis in this XDA thread). You should read the entire tutorial, but a summary of the steps is as follows: The other method you have available is unpacking the boot.img from the same ROM (such as CM, TouchWiz, EMUI, etc.) and the same Android version. You would then swap the Zimage. Again, this is a really complicated process and you should read the exact tutorial, but a summary of the steps is: Before you flash your kernel, you should create a backup of your stock boot.img, and then flash your kernel to see if it allows your Android system to boot.

Adding Features to Your Kernel

Adding features to your kernel is a great way to spice it up. There are a lot of things you can tweak, such as CPU governors, IO schedulers, overclocking the GPU, audio enhancements, etc. An example for adding a governor is here (this governor is codenamed Intellimm). We can see in the first 2 text boxes that in “arch/arm/configs/” “msm8974_sec_defconfig” and “cm_msm8974_sec_defconfig” have been modified. Between the lines 140 and 141 of this files this text has been added : “CONFIG_CPU_FREQ_GOV_INTELLIMM=y” (This line is for enabling Intellimm when you’re compiling your kernel) Same technique applies to the other text boxes (what has been added and deleted and it’s location) Depending on the features you add, more or less files can be modified, added or deleted. So to sum it up, a Commit let’s you see all the changes which have been made and everything else!

General Tips and Tricks

How to change the kernel name and version: The simple method: Edit this line in your defconfig file: Example: CONFIG_LOCALVERSION=”-XenomTW-3.2.6″

The advanced methods:

Navigate to the Makefile in the root folder of your kernel source. Add these lines: DO NOT modify the lines Version, PatchLevel, Sublevel, or Extraversion. Alternative method: Go to scripts/mkcompile_h and add these lines: Solving PATH problems: If you encounter the error “Is your path correct?”, try this in the Linux terminal:

Accessing your Ubuntu folders from Windows 10

Your path to Ubuntu should typically 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 typically break the permissions on them – you would then need to reset the permissions from within Linux terminal.

How to Build a Custom Android KernelHow to Update your Android Kernel to Latest Linux StableNew Windows 11 Preview Build Features Deeper Android Integration with Your Phone…How to Build a Custom ROM from Android Open Source Project