Getting Started With Android Development - Building A Custom Kernel For Your Android Device

It's hard to get started in Android development these days, but this learning process can be made much simpler and efficient if you learn directly from those who have played the game. Kunal has had his hands dirty in the development community since years and today he is here to help you out as well. He has also started a video tutorial series on how to build and compile ROMs, kernels and scripts for Android. In the first article of this series, Kunal teaches you how to get started and build a kernel from scratch.

What is a Kernel? 

Kernel is a layer between the hardware and the software, it connects the two. Whenever the software sends a request to system libraries, kernel is responsible for making the necessary changes to the hardware. From changing the brightness settings to volume levels, kernel is the module which take care of the complete software-hardware interaction on your Android device.

What you might not know is that we can tweak the kernel settings to get an even better performance out of your device. In order to do this, we can add experimental settings to it as well as add more IO Schedulers and CPU Governors depending on the user's need. Here is what all you can do to make your kernel awesome and thus get a faster device performance:
  • Enable Experimental Features.
  • Overclock CPU.
  • Add IO Schedulers.
  • Add CPU Governors.
  • Disable Loggers For More Performance.
  • Make Several Other Tweaks to Enhance The Performance.
This is a video tutorial which will help you to get started in your aim to make your own custom kernel for your device.


1. Make sure you are running UBUNTU OS or any Linux Distribution. A server running the same will do as well.
2. Setup Environment.
3. Download Kernel Source.
4. Download Toolchain.
5. Make Changes to the kernel source.
6. Build The Kernel.

What is Kernel Source?

Well this is the repository which contains all the data needed while compiling your kernel, this kernel source is usually generated by the chip-set manufacturer and shared by the device manufacturer to the developers who are willing to pull out the performance out of it.

What is a Toolchain?

Toolchain in simple words is a set of tools which are needed for the compilation of the kernel. You might have heard about Linaro or UberTC or many others. If not, no worries, in the video tutorial above I've shown how to download the UberTC and get things running.

STEP 1: Download Required Tools / Setup Environment

Compilation needs some tools that you should have on your system, easiest way to do that is copy and paste the following code in terminal window.

         sudo apt-get install -y build-essential libncurses5-dev bzip2

STEP 2: Download kernel source:

Kernel Source is the most important source that you will need, and it's size may vary from 700MB to 2 gigs tops. This will be the repository on which we will be working. Either download it from the manufacturer website or clone it from their GitHub repository using the command shown above. Here are the links to popular repositories:

STEP 3: Download Toolchain

Download the toochain. Clone the toolchain using the command shown above. Select any of the following toolchains or compile your own toolchain as per your optimal needs.

STEP 4: Compile Time / Make a build script file (.sh file) Example - BashFile For Refernece

Have a look at this quick video tutorial below to understand how a bash file (.sh file) works. Creation of this file will help speed up the process of initialization while compiling the kernel. You can directly use the codes from HERE to start the compilation process. Enter both the initialisation and compilation commands in the terminal window after the toolchain has been downloaded. Or, you might as well use the compilation commands from the bash script.

Initialization Commands

export ARCH=arm type
export SUBARCH=arm type
export KBUILD_BUILD_USER="Username"
export KBUILD_BUILD_HOST="ServerName"
export CROSS_COMPILE="Toolchain Path"

Compilation Commands

make clean && make mrproper
make devicename_defconfig
make -j4

 Watch this video tutorial below to get a better idea on what operations these commands perform.


After the compilation work, we will get a "zImage" file, located under /arch and then under the /boot folder of the processor architecture (such as ARM), as the output. You've successfully compiled your first custom kernel. To make a flashable ZIP out of this zImage file, drag and drop this zImage file into the /tools folder of the following .zip file: FlashzImage.

Now after watching the video tutorial and reading this guide, if you still have any doubts, feel free to ask them in the comment section below and we'll make sure we get your doubts cleared as soon as possible. We'll soon be posting guides on how to add IO Schedulers and Governors to an Android kernel as well. Stay tuned!

Kailash Sudhakar
An engineering undergrad student who loves all things tech. He has a soft spot for Android.
Getting Started With Android Development - Building A Custom Kernel For Your Android Device Getting Started With Android Development - Building A Custom Kernel For Your Android Device Reviewed by Unknown on 11/26/2016 11:11:00 PM
Subscribe To Us

Get All The Latest Updates Delivered Straight To Your Inbox For Free!

Powered by Blogger.