Compile kernel in Android without PC
Most of the time I use my laptop that has a dual core celeron processor, which isn’t good in kernel compilation. So, I use Google cloud to compile kernels. Google cloud provides free 50 hours/week, which is more than enough to compile multiple kernels. The only thing you need is a google account. You can use Google cloud in your phone, without PC/Laptop. One more thing, you can follow the below tutorial to build in your PC as well, just skip first step. (-;
1. Open Google Cloud Console
- Go to cloud.google.com.
- Login with your google account.
- Click on “Console” at top-right corner.
- After clicking on “Console” you’ll see a terminal icon on top-right corner. Click on that icon.
- Now, a terminal will appear on the webpage. Here we’ll do our kernel compilation.
2. Setup Build Environment
Once you get the console, install necessary packages, toolchains and kernel source. You can download the toolchains from my repo or download according to your device.
3. Download Toolchains and Kernel Source
4. Setup Exports and Aliases
The below code block is all you need if you want to compile with CLANG or GCC. I’ve created two aliases for make command. You can adjust the parameters according to your need.
If you want to compile with CLANG, use makecl
and to build with GCC, use make
command.
5. Let's Build...
6. Get the kernel and dtbs
After compilation, you can download the kernel and necessary dtbs to your local machine/phone to make boot.img.
Now download the kernel to your local by clicking on “the three dots on top right corner -> Download”
7. Create boot.img
- Clone or download Android Image Kitchen from my repo.
- Get your stock boot.img and run
./unpackimg boot.img
to unpack the stock boot image. - After that you’ll see the aik will create a directory named
split
with unpacked kernel and dtb. - Extract the downloaded
build.tgz
archive usingtar -xpf build.tgz
and replace the kernel in split directory. - Now repack the boot.img using
./repackimg
. This will create a new image in aik directory.
Now you can boot/flash your new boot image using fastboot or from recovery.
NOTE:
- Try booting before flashing the boot image.
fastboot boot new-boot.img
- if everything works as expected, then you can flash it.
fastboot flash new-boot.img
- Always backup your original/stock boot image.
- Try to avoid using multiple cores and continuous kernel compilation in google cloud otherwise google will ban cloud access to your account. Don’t worry, your gmail, drive and other apps will work.