1.下载kernel
由于访问不了Google,使用中科大的镜像源,模拟器对应的是金鱼内核
git clone https://mirrors.ustc.edu.cn/aosp/kernel/goldfish.git
git branch -a
git chechout 你模拟器对应的版本
2.配置gcc工具环境变量和目标arch
cd 到aosp源码根目录
export PATH=$PATH/aosp/aosp-9-r46/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin
export ARCH=x86_64
export CROSS_COMPILE=x86_64-linux-android-
最后一项解释一下,就是交叉编译工具链的指定,就是上面PATH路径的bin下工具,只配置到android-
3.编译kernel
1.在编译kernel前先执行如下命令,要不然会报make找不到的错误
cd 到源码根目录
source source build/envsetup.sh
lunch
2.执行kernel make命令
cd 到kernel根目录
make x86_64_ranchu_defconfig
make
3.等待一会就可以看到编译成功,输出路径是 Kernel: arch/x86/boot/bzImage
4.模拟器跑一下看看内核变了没
emulator -kernel /home/wang/aosp/aosp-9-r46/aosp-kernel/goldfish/arch/x86/boot/bzImage
5. 编译中出现的错误
编译错误 error New address family defined, please update secclass_map.解决
In file included from scripts/selinux/genheaders/genheaders.c:19:
./security/selinux/include/classmap.h:245:2: error: #error New address family defined, please update secclass_map. #error New address family defined, please update secclass_map. -git a/scripts/selinux/mdp/mdp.c b/scripts/selinux/mdp/mdp.c: xxxxxxxxxxxxxxxxxx
1.找到错误中提示的.c文件,genheader.c文件和mdp.c文件 编辑,去掉两个文件的头部引用中的
#include <sys/socket.h>
2.找到错误提示中的classmap.h文件 a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h 编辑classmap.h,在头文件中添加
#include <linux/socket.h>
重新编译即可