[GUIDE] Build Your Own Android Kernel{Easiest and Fastest Way] [Using The NDK]

Search This thread

TheWizardOfROMs

Senior Member
Nov 29, 2012
124
274
Prilep
This is the quickest and easiest way to build your own Kernel using the Android NDK

Note:I will be reffering to the following
yourusername=the username that you are logged in to
devicecode=The codename for the device you are building a kernel for(Google it on what is the code name

Note:I am only showing you how to make it to be flashed via CWM. If you wan't a tuttorial on how to make a boot.img comment and i will make it.

What you will need
Ubuntu 12.04 or newer
A lot of patience

Step 1:Installing the required files

Open a terminal and type the following (copy-paste)
Code:
sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
This will install the packages you need

Download the kernel source code for your device (This is important. We are going to build the kernel from this)
Find your device and click Download

Download The NDK

Move the NDK and your device Kernel source code in your home folder
Extract both the NDK and your kernel source code
Rename the folder were you have the NDK installed to NDK. And rename the folder where you have the kernel installed to Kernel

Now we are ready to build.

Step 2:Tweaking the kernel

Navigate to the kernel folder
Code:
cd /home/[COLOR="red"]yourusername[/COLOR]/Kernel

Next we need to point the NDK tools to the kernel folder
Code:
export CROSS_COMPILE=/home/[COLOR="red"]yourusername[/COLOR]/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-

We've pointed the NDK tolls and now we can use the NDK to tweak the kernel

Next we need to clean the previous work just incase:
Code:
make clean && make mrproper

If everything goes well you are good to go. If you have an Error(s) then something is wrong.

Now we are ready.
Next we need to add the kernel features to the NDK so we can modife them
Firs open your kernel source code folder go to arch/arm/configs
Here you will all the configs.
We need only one. Find that. It is called:Yourdevicecode_somethingbalblabla.defconfig
Rename it to maker.defconfig
Now type this in your terminal
Code:
make maker.defconfig

Now we need to tweak those configs.
Code:
make menuconfig
A user interface will pop out showing you all the tweaks you can do. I am not going to show you whow to use it. Google it(Sorry don't have that enough space)
When you are ready close the UI and click SAVE

Step 3 Building
So we tweaked the Kernel and we are ready to build.
make -j# ARCH=arm
Note:The # means the number of CPU cores +1. For example my device has a quad core CPU and I will type
Code:
make -j5 ARCH=arm
This will build the Kernel. It will take about 10 minutes.

Step 4: Finalizing
Now that kernel is ready you will need to find a kernel flashable zip for your device(Just google it)
Download the zip file and leave it in your home folder.

Now got to your kernel source and go to arch/arm/boot and copy zImage
Paste your Zimage to the zip file and replace it.

Now we need the WI-FI modules otherwise your WI-FI will not be working
Go to the Kernel source code folder and go to driver/net/wireless/bcm4329_204 and copy bcm4329.ko
Got the zip file go to the System folder and replace it's bcm4329.ko with your bcm4329.ko

You are ready all you need to do is flash it.
 
Last edited:

sert00

Senior Member
May 28, 2011
1,091
496
cesena,IT
mmm..interesting...i always build without the ndk,but simpy sdk.what's the advantages?
and i usually do the git clone to download all the sources,in my case nexus7 and maguro.
thanks for this!
 
  • Like
Reactions: AllanDenis
Z

zylor

Guest
Well i am just waiting for Samsung to release JB sources for N7000 to start learning on how to create my own kernel :D

This is a pretty good base! Thanks
 

HTCDreamOn

Senior Member
Jun 17, 2012
1,069
1,351
Sorry if this is a stupid question but do we need 64 bit like we do for ROM compiling, or will this work fine for 32 bit (I'm running Ubuntu 12.10 32 bit). Also, roughly how much is there to download? Thanks :)
 

thewadegeek

Senior Member
Mar 20, 2011
696
868
Cedar Rapids
mmm..interesting...i always build without the ndk,but simpy sdk.what's the advantages?
and i usually do the git clone to download all the sources,in my case nexus7 and maguro.
thanks for this!

What are you building? If a whole ROM like AOSP,AOKP,PA or CM then they typically bundle the toolchain/kernel with the source, making this totally unneeded.

---------- Post added at 12:18 PM ---------- Previous post was at 12:17 PM ----------

Sorry if this is a stupid question but do we need 64 bit like we do for ROM compiling, or will this work fine for 32 bit (I'm running Ubuntu 12.10 32 bit). Also, roughly how much is there to download? Thanks :)

No 32-bit is fine, just install the right libraries. I actually believe that you can compile a ROM on 32-bit as well.

Self-Plug http://forum.xda-developers.com/showthread.php?t=1748297
 
Last edited:

thewadegeek

Senior Member
Mar 20, 2011
696
868
Cedar Rapids
Also just to warn users, the above defconfig convention is just that, a convention. The author of a kernel can name the defconfig whatever they want, so it is something to keep in mind.

Sent from my SCH-R950 using Tapatalk 2
 
  • Like
Reactions: HTCDreamOn

sert00

Senior Member
May 28, 2011
1,091
496
cesena,IT
What are you building? If a whole ROM like AOSP,AOKP,PA or CM then they typically bundle the toolchain/kernel with the source, making this totally unneeded.

---------- Post added at 12:18 PM ---------- Previous post was at 12:17 PM ----------



No 32-bit is fine, just install the right libraries. I actually believe that you can compile a ROM on 32-bit as well.

Self-Plug http://forum.xda-developers.com/showthread.php?t=1748297

i builded some kang rom for personal use,but lately only kernels (for my nexus devices and 2 emebedded system board like in my sig.
 

HTCDreamOn

Senior Member
Jun 17, 2012
1,069
1,351
Thanks for the guide, but unfortunately I am getting errors during compilation:

Code:
make -j3 ARCH=arm
  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/bin2c
  CC      scripts/mod/empty.o
arm-eabi-gcc: No such file or directory
Is your PATH set correctly?
make[2]: *** [scripts/mod/empty.o] Error 2
make[1]: *** [scripts/mod] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [scripts] Error 2

I am trying to compile the Andromadus 3.0 kernel for HTC Vision, I'd really appreciate some help. I'm using Ubuntu 12.10 32 bit and the Android NDK.
 

persano

Senior Member
Nov 25, 2012
1,612
263
22
Buenos Aires
This is the quickest and easiest way to build your own Kernel using the Android NDK

Note:I will be reffering to the following


Note:I am only showing you how to make it to be flashed via CWM. If you wan't a tuttorial on how to make a boot.img comment and i will make it.

What you will need


Step 1:Installing the required files

Open a terminal and type the following (copy-paste)
Code:
sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
This will install the packages you need

Download the kernel source code for your device (This is important. We are going to build the kernel from this)

Find your device and click Download

Download The NDK

Move the NDK and your device Kernel source code in your home folder
Extract both the NDK and your kernel source code
Rename the folder were you have the NDK installed to NDK. And rename the folder where you have the kernel installed to Kernel

Now we are ready to build.

Step 2:Tweaking the kernel

Navigate to the kernel folder
Code:
cd /home/yourusername/Kernel

Next we need to point the NDK tools to the kernel folder
Code:
export CROSS_COMPILE=/home/yourusername/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-

We've pointed the NDK tolls and now we can use the NDK to tweak the kernel

Next we need to clean the previous work just incase:
Code:
make clean && make mrproper

If everything goes well you are good to go. If you have an Error(s) then something is wrong.

Now we are ready.
Next we need to add the kernel features to the NDK so we can modife them
Firs open your kernel source code folder go to arch/arm/configs
Here you will all the configs.
We need only one. Find that. It is called:Yourdevicecode_somethingbalblabla.defconfig
Rename it to maker.defconfig
Now type this in your terminal
Code:
make maker.defconfig

Now we need to tweak those configs.
Code:
make menuconfig
A user interface will pop out showing you all the tweaks you can do. I am not going to show you whow to use it. Google it(Sorry don't have that enough space)
When you are ready close the UI and click SAVE

Step 3 Building
So we tweaked the Kernel and we are ready to build.

Note:The # means the number of CPU cores +1. For example my device has a quad core CPU and I will type
Code:
make -j5 ARCH=arm
This will build the Kernel. It will take about 10 minutes.

Step 4: Finalizing
Now that kernel is ready you will need to find a kernel flashable zip for your device(Just google it)
Download the zip file and leave it in your home folder.

Now got to your kernel source and go to arch/arm/boot and copy zImage
Paste your Zimage to the zip file and replace it.

Now we need the WI-FI modules otherwise your WI-FI will not be working
Go to the Kernel source code folder and go to driver/net/wireless/bcm4329_204 and copy bcm4329.ko
Got the zip file go to the System folder and replace it's bcm4329.ko with your bcm4329.ko

You are ready all you need to do is flash it.

will work with an ics device like amazon kindle fire?

Sent from my KFTT using xda app-developers app
 

thewadegeek

Senior Member
Mar 20, 2011
696
868
Cedar Rapids
Thanks for the guide, but unfortunately I am getting errors during compilation:

Code:
make -j3 ARCH=arm
  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/bin2c
  CC      scripts/mod/empty.o
arm-eabi-gcc: No such file or directory
Is your PATH set correctly?
make[2]: *** [scripts/mod/empty.o] Error 2
make[1]: *** [scripts/mod] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [scripts] Error 2

I am trying to compile the Andromadus 3.0 kernel for HTC Vision, I'd really appreciate some help. I'm using Ubuntu 12.10 32 bit and the Android NDK.

Check your toolchain definition, looks like your path is wrong.
 
  • Like
Reactions: HTCDreamOn

HTCDreamOn

Senior Member
Jun 17, 2012
1,069
1,351
Try building it again. Be sure to clean the source folder before you start

Thanks very much, I'd been recommended using Linaro tool chain instead and it works perfectly now, booting and WiFi and all. If I can learn some more advanced modding stuff to do to it then I'll release it in the Vision forums and I'll make sure to link to this guide :)
 

rp56

Senior Member
Feb 8, 2013
379
22
I installed Ubuntu on my windows laptop.my computer stars are 3Gigs of memory with 140 Gigs of available free space.Do I have enough space and is my laptop good enough to build kernels on.and I do use Ubuntu 12.04 to build kernels correct.I'm sorry I'm all new to this I just would like to be able to build a kernel for my sensation and HTC one which I will have next week.thanks very much for your time and expertise. :)

Sent from my HTC Sensation using xda app-developers app
 

HTCDreamOn

Senior Member
Jun 17, 2012
1,069
1,351
I installed Ubuntu on my windows laptop.my computer stars are 3Gigs of memory with 140 Gigs of available free space.Do I have enough space and is my laptop good enough to build kernels on.and I do use Ubuntu 12.04 to build kernels correct.I'm sorry I'm all new to this I just would like to be able to build a kernel for my sensation and HTC one which I will have next week.thanks very much for your time and expertise. :)

Sent from my HTC Sensation using xda app-developers app

I compiled with Ubuntu 12.10 and only 2 GB of RAM, and only 30GB free space. The tool chain and kernel really doesn't use up much room at all. As long as you don't go OTT on the -jx bit (I do -j3 as I've got a lowly core 2 duo) you should be fine. By the way if you get errors and you're path is definitely correct, then try with the Linaro tool chain instead.
 
  • Like
Reactions: rp56

Top Liked Posts

  • There are no posts matching your filters.
  • 78
    This is the quickest and easiest way to build your own Kernel using the Android NDK

    Note:I will be reffering to the following
    yourusername=the username that you are logged in to
    devicecode=The codename for the device you are building a kernel for(Google it on what is the code name

    Note:I am only showing you how to make it to be flashed via CWM. If you wan't a tuttorial on how to make a boot.img comment and i will make it.

    What you will need
    Ubuntu 12.04 or newer
    A lot of patience

    Step 1:Installing the required files

    Open a terminal and type the following (copy-paste)
    Code:
    sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
    This will install the packages you need

    Download the kernel source code for your device (This is important. We are going to build the kernel from this)
    Find your device and click Download

    Download The NDK

    Move the NDK and your device Kernel source code in your home folder
    Extract both the NDK and your kernel source code
    Rename the folder were you have the NDK installed to NDK. And rename the folder where you have the kernel installed to Kernel

    Now we are ready to build.

    Step 2:Tweaking the kernel

    Navigate to the kernel folder
    Code:
    cd /home/[COLOR="red"]yourusername[/COLOR]/Kernel

    Next we need to point the NDK tools to the kernel folder
    Code:
    export CROSS_COMPILE=/home/[COLOR="red"]yourusername[/COLOR]/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-

    We've pointed the NDK tolls and now we can use the NDK to tweak the kernel

    Next we need to clean the previous work just incase:
    Code:
    make clean && make mrproper

    If everything goes well you are good to go. If you have an Error(s) then something is wrong.

    Now we are ready.
    Next we need to add the kernel features to the NDK so we can modife them
    Firs open your kernel source code folder go to arch/arm/configs
    Here you will all the configs.
    We need only one. Find that. It is called:Yourdevicecode_somethingbalblabla.defconfig
    Rename it to maker.defconfig
    Now type this in your terminal
    Code:
    make maker.defconfig

    Now we need to tweak those configs.
    Code:
    make menuconfig
    A user interface will pop out showing you all the tweaks you can do. I am not going to show you whow to use it. Google it(Sorry don't have that enough space)
    When you are ready close the UI and click SAVE

    Step 3 Building
    So we tweaked the Kernel and we are ready to build.
    make -j# ARCH=arm
    Note:The # means the number of CPU cores +1. For example my device has a quad core CPU and I will type
    Code:
    make -j5 ARCH=arm
    This will build the Kernel. It will take about 10 minutes.

    Step 4: Finalizing
    Now that kernel is ready you will need to find a kernel flashable zip for your device(Just google it)
    Download the zip file and leave it in your home folder.

    Now got to your kernel source and go to arch/arm/boot and copy zImage
    Paste your Zimage to the zip file and replace it.

    Now we need the WI-FI modules otherwise your WI-FI will not be working
    Go to the Kernel source code folder and go to driver/net/wireless/bcm4329_204 and copy bcm4329.ko
    Got the zip file go to the System folder and replace it's bcm4329.ko with your bcm4329.ko

    You are ready all you need to do is flash it.
    3
    mmm..interesting...i always build without the ndk,but simpy sdk.what's the advantages?
    and i usually do the git clone to download all the sources,in my case nexus7 and maguro.
    thanks for this!

    What are you building? If a whole ROM like AOSP,AOKP,PA or CM then they typically bundle the toolchain/kernel with the source, making this totally unneeded.

    ---------- Post added at 12:18 PM ---------- Previous post was at 12:17 PM ----------

    Sorry if this is a stupid question but do we need 64 bit like we do for ROM compiling, or will this work fine for 32 bit (I'm running Ubuntu 12.10 32 bit). Also, roughly how much is there to download? Thanks :)

    No 32-bit is fine, just install the right libraries. I actually believe that you can compile a ROM on 32-bit as well.

    Self-Plug http://forum.xda-developers.com/showthread.php?t=1748297
    2
    Thanks, do you know how large all the files are once installed on the system (you might have guessed I'm slightly short of space atm)
    About 700 MB
    1
    mmm..interesting...i always build without the ndk,but simpy sdk.what's the advantages?
    and i usually do the git clone to download all the sources,in my case nexus7 and maguro.
    thanks for this!
    1
    :good: Thanks! I'm use Ubuntu 10.04 64 bit don't know if can?
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone