从零开始快速构建Android GKI内核
从零开始快速构建Android GKI内核
inkOrCloud前置知识
repo
一个易于git的python脚本,可以同时管理多个git项目,批量执行git操作
开始构建
同步源代码
先创建一个空文件夹并进入再用repo初始化仓库
1
repo init -u https://android.googlesource.com/kernel/manifest
注意:对于已废弃的构建版本需要将uptream和dest-branch改为正确的分支
例如: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<manifest>
<remote name="aosp" fetch="https://android.googlesource.com/" review="https://android.googlesource.com/" />
<default upstream="master-kernel-build-2021" dest-branch="master-kernel-build-2021" remote="aosp" sync-j="4" />
<superproject name="kernel/superproject" remote="aosp" revision="common-android12-5.10-2023-05" />
<!-- other -->
<project path="common" name="kernel/common" revision="f23f00da6b8ec6e2f99cc9659912c34fdee55237" upstream="android12-5.10-2023-05" dest-branch="android12-5.10-2023-05" />
<!-- other -->
</manifest>common/android12-5.10-2023-05已废弃,所以该分支不存在,需要将upstream和dest-branch改为deprecated/android12-5.10-2023-05
修改完成后指定清单文件再次初始化 1
2repo init -m manifest.xml
manifest.xml为.repo/manifests下需要指定的清单文件的文件名
初始化完成后开始同步源代码
1 | repo sync |
构建
对于Android12以及更低的版本,使用build.go构建 1
BUILD_CONFIG=xxx build/build.sh
1
BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh
LTO=thin
1
LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh
对于Android13及以上版本可使用bazel构建 1
tools/bazel run //common:kernel_aarch64_dist

![[leetcode 3321][Go][有序集合]计算子数组的 x-sum II](https://s3.inkorcloud.top/image/2025/11/c9f55b2ecb04d16a57547b9f4de294ef.png)
![[leetcode 2589][Go][贪心]完成所有任务的最少时间](https://s3.inkorcloud.top/image/2025/11/b966fd1a91aa1ea098b86e6d778523c2.png)
![[leetcode 3234][Go]统计1显著的字符串的数量](https://s3.inkorcloud.top/image/2025/11/a72a47911de291f51cbb5902e4811c1f.png)
![[leetcode 1611][Go][位运算][记忆化搜索]使整数变为 0 的最少操作次数](https://s3.inkorcloud.top/image/2025/11/9715b5f3d8a7574ded3648767538558e.png)
![[leetcode 2528][Go][二分答案][差分数组][前缀和]最大化城市的最小电量](https://s3.inkorcloud.top/image/2025/11/fa0013722d9361b4383839722394dcf2.png)