Skip to content

funianshengsheng/Android-Kernel-Builder

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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"]
      }
    ],
    "ccache":false,
    "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"]
      }
    ],
    "ccache":true,
    "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": false,
    "toolchains": [
      {
        "repo": "https://github.com/kdrag0n/proton-clang",
        "branch": "master",
        "name": "proton-clang",
        "binPath": ["bin"]
      }
    ],
    "ccache":true,
    "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": []
    }
  ],
  "ccache": false,
  "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 was used.
toolchains An array containing information about the toolchains needed, including repository address, branch, and name.
ccache A boolean value indicating whether the ccache tool was used to speed up compile.
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.
url String Toolchain Download Url The download url of the toolchain.
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.

Therefore, you can use the following forms to obtain the compilation toolchain:

1. Use Git to pull the toolchain

"toolchains": [
  {
    "repo": "https://github.com/kdrag0n/proton-clang",
    "branch": "master",
    "name": "proton-clang",
    "binPath": ["./bin"]
  }
]

2. Use wget to download the toolchain

In this way, you can get the compiled toolchain compressed package in .zip | .tar | .tar.gz | .rar format.

"toolchains": [
  {
    "url": "https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/master-kernel-build-2022/clang-r450784d.tar.gz",
    "name": "clang",
    "binPath": ["./bin"]
  },
  {
    "url": "https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/+archive/refs/tags/android-12.1.0_r27.tar.gz",
    "name": "gcc",
    "binPath": ["bin"]
  }
]

3. Mixed mode (using Git and wget at the same time)

"toolchains": [,
  {
    "repo": "https://gitlab.com/ThankYouMario/android_prebuilts_clang-standalone/",
    "branch": "11",
    "name": "clang",
    "binPath": ["bin"]
  },
  {
    "url": "https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/+archive/refs/tags/android-12.1.0_r27.tar.gz",
    "name": "gcc",
    "binPath": ["bin"]
  }
]

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

Notice

In this step, you may encounter the following error when executing softprops/action-gh-release@v1:

πŸ‘©β€πŸ­ Creating new GitHub release for tag v20230619.7...
⚠️ GitHub release failed with status: 403
undefined
retrying... (2 retries remaining)
πŸ‘©β€πŸ­ Creating new GitHub release for tag v20230619.7...
⚠️ GitHub release failed with status: 403
undefined
retrying... (1 retries remaining)
πŸ‘©β€πŸ­ Creating new GitHub release for tag v20230619.7...
⚠️ GitHub release failed with status: 403
undefined
retrying... (0 retries remaining)
❌ Too many retries. Aborting...
Error: Too many retries.

The reason for this error is related to workflow permissions:

workflow permissions

Complete the permission settings and then you can publish your own Release normally.

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

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

  • Use MagiskBoot to generate boot.img
  • Web page for configuring profiles

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.

About

Automaticcaly build android kernel by github actions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published