可见以下博客:
http://blog.csdn.net/qq1084283172/article/details/54562606
源码下载:
请采用清华源的镜像,中科大是 SB
清华源:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
1. repo 文件同步
可参考:https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/
- 将 repo 同步到本地,并设置 path 变量
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo
PATH=/pwd/repo:$PATH
- 将 REPO_URL 添加到
~/.bashrc
环境变量内,在这个文件的最后添加。设置完成后重启终端。
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
- 初始化 .repo 本地,init
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-4.4.4_r1
- 开始下载
repo sync -f -j4
- 说明
不要采用下载 tar 包的形式下载源码,因为,那个针对的是 Android 最新的版本。在压缩包的基础上再进行同步 子 分支的话,会出现问题。
在设置好了 repo 后,直接执行 'repo sync -f -j4' 命令进行同步。
在同步的过程中会出现 ingoning 等看似是错误的字段,直接忽略。
原本硬盘 181.5 G 下载玩后还剩 72 G。
成功标识:
Fetching projects: 99% (409/413) Fetching project platform/prebuilts/gradle-plugin
remote: Counting objects: 476, done.
remote: Compressing objects: 100% (276/276), done.
remote: Total 476 (delta 229), reused 343 (delta 200)
接收对象中: 100% (476/476), 1.21 MiB | 740.00 KiB/s, done.
处理 delta 中: 100% (229/229), done.
来自 https://aosp.tuna.tsinghua.edu.cn/platform/external/llvm
adeabc1..7654d24 lldb-master-dev -> aosp/lldb-master-dev
d914c51..516dc8b upstream-master -> aosp/upstream-master
Fetching projects: 100% (413/413), done.
Syncing work tree: 100% (412/412), done.
2. 编译环境准备
安装 JDK 1.6 版本
update-alternatives --install "/usr/bin/java" "java" "/usr/java/bin/java" 1
update-alternatives --config java
3. 源码编译
对应博客:
https://blog.csdn.net/qq1084283172/article/details/54562606
官方说明:
https://source.android.google.cn/setup/building#initialize
1、驱动设备文件的下载,下载地址:
https://developers.google.com/android/drivers#hammerheadktu84p
在此处找到 Nexus 5 (GSM/LTE) binaries for Android 4.4.4 (KTU84P)
下载三个驱动文件:broadcom-hammerhead-ktu84p-5a5bf60e.tgz、lge-hammerhead-ktu84p-49419c39.tgz、qcom-hammerhead-ktu84p-f159eadf.tgz
tar zxvf ***.tgz
2、将三个文件解压在源码目录下,得到三个 .sh 文件,然后依次 ./ 执行三个文件,注意结束时要输入 'I ACCEPT'
在最后输入。
3、成功后会有vendor 文件夹,里面还有 Broadcom,lge,qcom 三个文件夹
执行完之后会在这个文件夹里面生成。
4、先 make clobber
这一步是为了删除以前编译操作的已有输出。
5、 . build/envsetup.sh 执行
这一步是为了用脚本初始化环境。
6、lunch 选择要编译成的版本
先单独执行 'lunch' 命令,然后选择运行系统编译,输入编号,点确定。
7、make –j2 两条线程开始编译
8、out 文件夹内生成 img 文件
system.img:由out/target/product/PRODUCT_OUT/system目录生成
ramdisk.img:由out/target/product/PRODUCT_OUT/root目录生成
userdata.img:由out/target/product/PRODUCT_OUT/data目录生成
boot.img:包含kernel.img和ramdisk.img
recovery.img:我们可以通过boot.img和recovery_from_boot.p文件生成一个recovery.img文件
- 成功实例
+ ENABLE_SPARSE_IMAGE=
+ '[' -s = -s ']'
+ ENABLE_SPARSE_IMAGE=-s
+ shift
+ '[' 6 -ne 5 -a 6 -ne 6 ']'
+ SRC_DIR=out/target/product/hammerhead/system
+ '[' '!' -d out/target/product/hammerhead/system ']'
+ OUTPUT_FILE=out/target/product/hammerhead/obj/PACKAGING/systemimage_intermediates/system.img
+ EXT_VARIANT=ext4
+ MOUNT_POINT=system
+ SIZE=1073741824
+ FC=out/target/product/hammerhead/root/file_contexts
+ case $EXT_VARIANT in
+ '[' -z system ']'
+ '[' -z 1073741824 ']'
+ '[' -n out/target/product/hammerhead/root/file_contexts ']'
+ FCOPT='-S out/target/product/hammerhead/root/file_contexts'
+ MAKE_EXT4FS_CMD='make_ext4fs -s -S out/target/product/hammerhead/root/file_contexts -l 1073741824 -a system out/target/product/hammerhead/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/hammerhead/system'
+ echo make_ext4fs -s -S out/target/product/hammerhead/root/file_contexts -l 1073741824 -a system out/target/product/hammerhead/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/hammerhead/system
make_ext4fs -s -S out/target/product/hammerhead/root/file_contexts -l 1073741824 -a system out/target/product/hammerhead/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/hammerhead/system
+ make_ext4fs -s -S out/target/product/hammerhead/root/file_contexts -l 1073741824 -a system out/target/product/hammerhead/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/hammerhead/system
Creating filesystem with parameters:
Size: 1073741824
Block size: 4096
Blocks per group: 32768
Inodes per group: 8192
Inode size: 256
Journal blocks: 4096
Label:
Blocks: 262144
Block groups: 8
Reserved block group size: 63
Created filesystem with 1429/65536 inodes and 76583/262144 blocks
+ '[' 0 -ne 0 ']'
Install system fs image: out/target/product/hammerhead/system.img
out/target/product/hammerhead/system.img+out/target/product/hammerhead/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p maxsize=1096212480 blocksize=135168 total=298434826 reserve=11083776
- 修改系统 api 函数
在修改了系统源码后,需要先执行make update-api
命令,然后再执行make -j4
,否则会报一下错误。
******************************
You have tried to change the API from what has been previously approved.
To make these errors go away, you have two choices:
1) You can add "@hide" javadoc comments to the methods, etc. listed
in the
errors above.
2) You can update current.xml by executing the following commands:
p4 edit frameworks/base/api/current.xml
make update-api
To check in the revised current.xml, you will need OWNERS
approval.
******************************
- 说明
编译前 72 G,完成后 45 G ,大约用时 3.5 小时。
网友评论