https://source.android.com/source/initializing
ubuntu开发环境
建议按照官方推荐的来,之前折腾centos,各种依赖,版本原因耗费大量时间。实体机安装ubuntu14.04server版。
1、安装依赖
$ sudo apt-get install git-core gnupg flex bison gperf build-essential \ zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \ lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \ libgl1-mesa-dev libxml2-utils xsltproc unzip
2、安装openjdk,openjdk版本与你要编译的版本相关,在官网上有介绍。我要编译android 6,使用openjdk7
$ sudo apt-get install openjdk-7-jdk
下载aosp
这里要用到清华的镜像https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
1、准备repo工具
mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo
编辑~/bin/repo文件,将REPO_URL修改为https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
2、配置git
git config --global user.name "Your Name" git config --global user.email "you@example.com" git config --global http.postBuffer 24288000
3、下载源码
- https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/ 下载源码包
aosp-latest.tar
,建议windows迅雷下载 - 解压源码包并同步到你想编译的源码版本,这里编译的是:
MDA89D android-6.0.0_r11 Marshmallow Nexus 6P
$ tar xf aosp-latest.tar $ cd aosp $ repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-6.0.0_r11 $ repo sync
- 开始编译
$ . build/envsetup.sh $ lunch aosp_angler-userdebug $ make -jN
内核编译
1.下载内核源码
$ git clone https://aosp.tuna.tsinghua.edu.cn/kernel/msm
$ cd msm
$ git branch -a
$ git checkout origin/android-msm-angler-3.10-marshmallow-mr1
2.下载arm64工具链aarch64-linux-android-4.9
$ git clone https://aosp.tuna.tsinghua.edu.cn/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
3.配置环境变量
$ export PATH=$PWD/aarch64-linux-android-4.9/bin:$PATH $ export ARCH=arm64 $ export SUBARCH=arm64 $ export CROSS_COMPILE=aarch64-linux-android-
4.编译
$ make angler_defconfig # make
打包boot.img
上一步编译生成的内核镜像,需要打包成boot.img。boot.img通常由以下三部分构成:
- A kernel image
- A ramdisk image
- A kernel command-line
这里我们使用官方的boot.image,将之前编译生成的kernel替换原有的。官方Factory image https://developers.google.com/android/images
对应之前的MDA89D,选择下载:
angler-mda89d-factory-9f001626.zip
从官方的boot.img中提取出bootimg.cfg zImage initrd.img
$ unzip angler-mda89d-factory-9f001626.zip $ cd angler-mda89d $ unzip image-angler-mda89d.zip boot.img $ abootimg -x boot.img
bootimg.cfg
: configuration with addresses, sizes and the kernel commandline.zImage
: the stock kernelinitrd.img
: the stock ramdisk
我们编译的内核大小和提取出来的不一样,需要修改bootimg.cfg,删掉bootsize那项
sed -i '/bootsize =/d' bootimg.cfg
接下来便可以生成自定义的boot镜像,这里命名为newboot.img
abootimg --create newboot.img -f bootimg.cfg -k your_kernel_path/msm/arch/arm64/boot/Image.gz-dtb -r initrd.img