Skip to content

Akitlove/Android-Kernel-Builder

 
 

Repository files navigation

banner

Build Your Own Kernel with Github Action

English | 中文

License Language Issues Pull Requests

This Github Action helps you build kernels. It reads multiple kernel sources from a configuration file and builds them using different toolchains. Additionally, it supports patching the kernel with KernelSU and uploading the built kernel image.



  Configure  

  Quick Start  

  Local testing  


Github Action

This action contains two jobs: Set-repos and Build-Kernel.

The Set-repos job reads the kernel sources from the configuration file and outputs them to the Build-Kernel job. The Build-Kernel job uses the outputted kernel sources to build the kernels and upload the built kernel images.

Trigger

Event name Description
workflow_dispatch Manually run

Workflow

Step Description
Install prerequisites Install the necessary dependencies for building the kernel
Setup Anykernel3 Clone the Anykernel3 repository to prepare for packaging the kernel
Clone kernel source Clone the kernel source code repository for the Android device
Get toolchains Obtain the required cross-compilation toolchains for building the kernel
Set args Set the necessary build parameters for the kernel
Update KernelSU Update the KernelSU tool to ensure compatibility with the new kernel
Make defconfig Generate the kernel configuration file
Build kernel Compile the kernel source code to create the kernel image
Upload Image Upload the kernel image file to a designated location
Upload Image.gz Upload the compressed kernel image file to a designated location
Upload dtb Upload the device tree blob file to a designated location
Upload dtbo.img Upload the device tree overlay image file to a designated location
Pack AnyKernel3.zip Package the kernel image and device tree files into an Anykernel3 zip file
Upload AnyKernel3 image Upload the Anykernel3 zip file to a designated location
Create GitHub Release Create a new release on GitHub to share the kernel with the community

Configuration File Syntax

Example configuration file
[
  {
    "kernelSource": {
      "name": "DogDay-KernelSU-Proton-release",
      "repo": "https://codeberg.org/DogDayAndroid/android_kernel_xiaomi_thyme",
      "branch": "lineage-20.0",
      "device": "thyme",
      "defconfig": "thyme_defconfig"
    },
    "withKernelSU": true,
    "toolchains": [
      {
        "repo": "https://github.com/kdrag0n/proton-clang",
        "branch": "master",
        "name": "proton-clang",
        "binPath": ["bin"]
      }
    ],
    "params": {
      "ARCH": "arm64",
      "CC": "proton-clang/bin/clang",
      "externalCommand": {
        "CROSS_COMPILE": "proton-clang/bin/aarch64-linux-gnu-",
        "CROSS_COMPILE_ARM32": "proton-clang/bin/arm-linux-gnueabi-",
        "LD": "proton-clang/bin/ld.lld",
        "AR": "proton-clang/bin/llvm-ar",
        "NM": "proton-clang/bin/llvm-nm",
        "OBJCOPY": "proton-clang/bin/llvm-objcopy",
        "OBJDUMP": "proton-clang/bin/llvm-objdump",
        "READELF": "proton-clang/bin/llvm-readelf",
        "OBJSIZE": "proton-clang/bin/llvm-size",
        "STRIP": "proton-clang/bin/llvm-strip",
        "LDGOLD": "proton-clang/bin/aarch64-linux-gnu-ld.gold",
        "LLVM_AR": "proton-clang/bin/llvm-ar",
        "LLVM_DIS": "proton-clang/bin/llvm-dis"
      }
    },
    "AnyKernel3": {
      "use": true,
      "release": true,
      "repo": "https://github.com/easterNday/AnyKernel3/",
      "branch": "thyme"
    }
  },
  {
    "kernelSource": {
      "name": "DogDay-KernelSU-Proton-noanykernel-release",
      "repo": "https://codeberg.org/DogDayAndroid/android_kernel_xiaomi_thyme",
      "branch": "lineage-20.0",
      "device": "thyme",
      "defconfig": "thyme_defconfig"
    },
    "withKernelSU": true,
    "toolchains": [
      {
        "repo": "https://github.com/kdrag0n/proton-clang",
        "branch": "master",
        "name": "proton-clang",
        "binPath": ["bin"]
      }
    ],
    "params": {
      "ARCH": "arm64",
      "CC": "proton-clang/bin/clang",
      "externalCommand": {
        "CROSS_COMPILE": "proton-clang/bin/aarch64-linux-gnu-",
        "CROSS_COMPILE_ARM32": "proton-clang/bin/arm-linux-gnueabi-",
        "LD": "proton-clang/bin/ld.lld",
        "AR": "proton-clang/bin/llvm-ar",
        "NM": "proton-clang/bin/llvm-nm",
        "OBJCOPY": "proton-clang/bin/llvm-objcopy",
        "OBJDUMP": "proton-clang/bin/llvm-objdump",
        "READELF": "proton-clang/bin/llvm-readelf",
        "OBJSIZE": "proton-clang/bin/llvm-size",
        "STRIP": "proton-clang/bin/llvm-strip",
        "LDGOLD": "proton-clang/bin/aarch64-linux-gnu-ld.gold",
        "LLVM_AR": "proton-clang/bin/llvm-ar",
        "LLVM_DIS": "proton-clang/bin/llvm-dis"
      }
    },
    "AnyKernel3": {
      "use": false,
      "release": true,
      "repo": "https://github.com/easterNday/AnyKernel3/",
      "branch": "thyme"
    }
  },
  {
    "kernelSource": {
      "name": "DogDay-KernelSU-Proton-anykernel-norelease",
      "repo": "https://codeberg.org/DogDayAndroid/android_kernel_xiaomi_thyme",
      "branch": "lineage-20.0",
      "device": "thyme",
      "defconfig": "thyme_defconfig"
    },
    "withKernelSU": true,
    "toolchains": [
      {
        "repo": "https://github.com/kdrag0n/proton-clang",
        "branch": "master",
        "name": "proton-clang",
        "binPath": ["bin"]
      }
    ],
    "params": {
      "ARCH": "arm64",
      "CC": "proton-clang/bin/clang",
      "externalCommand": {
        "CROSS_COMPILE": "proton-clang/bin/aarch64-linux-gnu-",
        "CROSS_COMPILE_ARM32": "proton-clang/bin/arm-linux-gnueabi-",
        "LD": "proton-clang/bin/ld.lld",
        "AR": "proton-clang/bin/llvm-ar",
        "NM": "proton-clang/bin/llvm-nm",
        "OBJCOPY": "proton-clang/bin/llvm-objcopy",
        "OBJDUMP": "proton-clang/bin/llvm-objdump",
        "READELF": "proton-clang/bin/llvm-readelf",
        "OBJSIZE": "proton-clang/bin/llvm-size",
        "STRIP": "proton-clang/bin/llvm-strip",
        "LDGOLD": "proton-clang/bin/aarch64-linux-gnu-ld.gold",
        "LLVM_AR": "proton-clang/bin/llvm-ar",
        "LLVM_DIS": "proton-clang/bin/llvm-dis"
      }
    },
    "AnyKernel3": {
      "use": true,
      "release": false,
      "repo": "https://github.com/easterNday/AnyKernel3/",
      "branch": "thyme"
    }
  }
]
Individual Configuration Template
{
  "kernelSource": {
    "name": "",
    "repo": "",
    "branch": "",
    "device": "",
    "defconfig": ""
  },
  "withKernelSU": false,
  "toolchains": [
    {
      "repo": "",
      "branch": "",
      "name": "",
      "binPath": []
    }
  ],
  "params": {
    "ARCH": "",
    "CC": "",
    "externalCommand": {}
  },
  "AnyKernel3": {
    "use": false,
    "release": false,
    "repo": "",
    "branch": ""
  }
}

Parameter Parsing

In general, there are the following fields:

Field Name Description
kernelSource Information about the kernel source code, including name, repository address, branch, and device type.
withKernelSU A boolean value indicating whether the KernelSU kernel patch tool was used.
toolchains An array containing information about the toolchains needed, including repository address, branch, and name.
params An object containing information about the build parameters, including architecture type, cross-compiler, compiler, etc.
AnyKernel3 An object containing information about building the kernel flash package, including the AnyKernel3 repository address, branch, etc.

Kernel Source Configuration (kernelSource)

Kernel Source Parameter Type Description Explanation
name String Kernel Name Customized, will be used in the release.
repo String Kernel Source Repository Address The git repository address of the kernel source code.
branch String Kernel Source Branch The specified branch of the repository.
device String Device Code The device code or name to be compiled, will be used in the release.
defconfig String Kernel Configuration File Name The prefix of the corresponding defconfig file to be compiled, for example, if the defconfig file is thyme_defconfig, fill in thyme.

Toolchain Configuration (toolchains)

This is an array that contains many repository objects of cross-compilation toolchains, and the parameter description of each configuration object is as follows:

Toolchain Parameter Type Description Explanation
repo String Toolchain Repository Address The git repository address of the toolchain.
branch String Toolchain Branch The specified branch of the repository.
name String Toolchain Name The name of the folder cloned locally, customized.
binPath Array Toolchain Binary File Path The path of the bin file used during compilation (relative to the path of the cloned folder). It will be converted to an absolute path during parameter setting when compiling.

Compilation Parameters (params)

Compilation Parameter Type Description Explanation
ARCH String Architecture The architecture of the device, which can be queried using uname -m.
CC String C Compiler Path The compiler used, usually clang or gcc.
externalCommand Object External Command Path Additional parameter settings required for compilation.

For the externalCommand part, here is an example of the command that may be used during compilation:

make -j$(nproc --all) \
      O=out \
      ARCH=arm64 \
      CC=clang \
      CLANG_TRIPLE=aarch64-linux-gnu- \
      CROSS_COMPILE=aarch64-linux-gnu- \
      CROSS_COMPILE_ARM32=arm-linux-gnueabi-

The -j and O=out parts will be automatically configured by the compilation script, and the ARCH and CC parts correspond to the above configuration. The other parts correspond to the externalCommand part, so the corresponding configuration for the toolchains part should be:

"params": {
  "ARCH": "arm64",
  "CC": "clang",
  "externalCommand": {
    "CLANG_TRIPLE": "aarch64-linux-gnu-",
    "CROSS_COMPILE": "proton-clang/bin/aarch64-linux-gnu-",
    "CROSS_COMPILE_ARM32": "proton-clang/bin/arm-linux-gnueabi-"
  }
}

Kernel Flashing Package Configuration(AnyKernel3)

AnyKernel3 Parameter Type Description Explanation
use Boolean Whether to use AnyKernel3 If set to false, the corresponding kernel flashing package will not be packaged
release Boolean Whether it is a release version Only effective when use is set to true. If set to false, the corresponding kernel flashing package will not be released
repo String AnyKernel3 repository address The repository address of the Anykernel3 used
branch String AnyKernel3 branch The specified branch of the corresponding repository

How to use

This project's basic usage is as follows:

  1. Fork this project on GitHub.

  2. Modify the repos.json file through the Github website or pull it to your local machine and commit the changes.

  3. Go to the Action page on Github and find Build kernels, then Run workflow.

  4. Wait for the compilation to finish, then download the compiled product from the corresponding page.

  5. Use your preferred packaging software to package the kernel (AnyKernel3, Android-Image-Kitchen, MagiskBoot, etc.)

Artifacts

Local testing

If you don't want to run the action on Github, you can use nektos/act to test this workflow locally and output the files.

Normal local build (kernel source code is fetched using Git)

This is the recommended local testing process. Simply install nektos/act and run the following command:

# Collect artifacts to /tmp/artifacts folder:
act --artifact-server-path /tmp/artifacts

If you want to store the artifacts in a different location, change /tmp/artifacts to your preferred directory.

If there are errors, use the -v flag to generate an error report and submit an issue. Here's the command:

# Collect artifacts to /tmp/artifacts folder:
act --artifact-server-path /tmp/artifacts -v

Full local build (kernel source code is stored locally)

If you need to perform a completely local build, consider building as follows:

  1. Set up a local Gitea or Gitlab Git service and modify the configuration file address to point to the local service address.

  2. Use git daemon to create a secondary image locally.

This is just a suggestion, and we do not provide a specific guide.

TODO list

  • Add .tar.gz files via wget for third-party compilers (use git for toolchain now).
  • Added relative path support for third-party compilers (absolute paths are now used).
  • Use ccache to speed up compilation.

Acknowledgments

Contributor

contributors

Star history

Star History

License

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.