必备:

linux(本次使用centos7)

aosp(android5.1.1)

二进制驱动(官网下载)

设备:nexus5 LMY48M

openjdk 1.7.x

centos和ubuntu基本一样,均可用一下方法来完成编译

一、编译

1.驱动下载地址:https://developers.google.com/android/drivers#hammerhead

按照你的版本号来选择对应的驱动 LMY48M,如下图;

下载完成之后的到三个压缩包

解压这三个压缩包,得到三个.sh文件

将这个三个文件放到你的源码根目录,直接运行即可

执行以下命令:

./extract-broadcom-hammerhead.sh

之后,会提示没有权限,给它权限,执行下面命令:

chmod u+x extract-broadcom-hammerhead.sh

再运行

./extract-broadcom-hammerhead.sh

执行之后会让你阅读那些协议什么的,你只管拉倒最后即可,直至看到下面这行话

你再此句话后面,输入I ACCEPT 确认即可

其他两个.sh文件执行方法和这个一样,执行完成后,源码目录下会多处一个目录:vendor

2.进入aosp源码目录,执行下面命令,意思就是给他一个写内存,保证他可以顺利编译,当然不执行下面命令也是可以的,你内存如果多的话,不妨给他,有舍有得嘛。

echo export USE_CCACHE=1 >> ~/.bashrc
prebuilts/misc/linux-x86/ccache/ccache -M 50G

3.也是在当前目录下,不用切换,执行以下命令:

source build/envsetup.sh

4.执行lunch,会出现以下列表

lunch

5.选择你的设备,我就选19了,执行命令:

19

6.开始编译(mack -jx的话,看你cup核数情况了,按照网上说的是来两倍为宜,我的配置不高,所以就-j2了)

mack -j2

编译后输出的文件都放在了源码根目录下的out文件中

二、刷机

1.将手机连接电脑,然后执行以下命令,确认已经连接上

adb devices

如图:即为连接上

如果显示以下证明已经连接上,可以进行后续操作了。

2.进入bootloader模式,执行以下命令

adb reboot bootloader

3.解锁

fastboot oem unlock

然后,按上下音量键选择YES选项,再按电源键确认就解锁成功了喽

如果提示你已经解锁,那么继续下一步

4.刷入镜像

fastboot -w flashall

然后就静静的等待,完成之后,手机会重启,这次时间会久一点,等待开机就可以了,刷机也就完成了

完成截图如下:

三.等待编译完成,编译过程中,会遇到各种各样的问题,比如

(1):这个问题具体叫啥也不好说,我就不命名了,反正也不是很清楚

ninja: build stopped: subcommand failed.
make: *** [ninja_wrapper] error 1

这个问题首先你要确定你有没有jack-server,一半你刚下载下来的源码中,是没有的,你安装就可以。

怎样确认你有没有安装呢,你可以进入你源码的这个目录

cd prebuilts/sdk/tools

然后执行,意思是停止服务

./jack-admin stop-server

如果执行后,提示你
编译的时候可能会出现这个错误,第一次编译的话,它是没有安装jack-server的

所以你就要安装它。如果安装后,还是有问题,那就看问题三了,一般都会解决的。

2.fatal: fork: Cannot allocate memory

[  4% 2326/47944] host C++: libLLVMBitRead...lvm/lib/Bitcode/Reader/BitstreamReader.cppninja: fatal: fork: Cannot allocate memory
make: *** [ninja_wrapper] 错误 1

这个的话是无法分配内存,你把你虚拟机的内存调整下,调大点,还有,你的电脑也要保持做的运存空间,运存使用最好不要超过92%。

3.安装编译需要的依赖库,这个很重要的,这个能解决大部分错误,不然会有各种错误爆出,导致编译中断

centos的话使用yum安装即可:

$ sudo yum install -y gcc make libstdc++.i686 libstdc++-devel.i686 zlib-devel openssl-devel perl cpio expat-devel gettext-devel autoconf glibc.i686 glibc-devel.i686 zlib-devel.i686 libstdc++.i686 libX11-devel.i686 ncurses-devel.i686 ncurses-libs.i686 gperf flex gcc-c++ bison patch

如果你是Ubuntu的话执行下面的,前面的sudo的话看你在什么账户下的,root账户下的话,就不用了

sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install lib32z-dev ccache
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4

4.

4 warnings generated.
[ 86% 41442/47944] host C: libext2_qu...fsprogs/lib/quota/../../e2fsck/dict.c
external/e2fsprogs/lib/quota/../../e2fsck/dict.c:21:9: warning: 'NDEBUG' macro redefined [-Wmacro-redefined]
#define NDEBUG^
<command line>:6:9: note: previous definition is here
#define NDEBUG 1^
1 warning generated.
[ 86% 41543/47944] Target cache fs im...out/target/product/flounder/cache.img
Running:  mkuserimg.sh -s out/target/product/flounder/cache out/target/product/flounder/cache.img ext4 cache 268435456 -D out/target/product/flounder/system -L cache out/target/product/flounder/root/file_contexts.bin
make_ext4fs -s -T -1 -S out/target/product/flounder/root/file_contexts.bin -L cache -l 268435456 -a cache out/target/product/flounder/cache.img out/target/product/flounder/cache out/target/product/flounder/system
Creating filesystem with parameters:Size: 268435456Block size: 4096Blocks per group: 32768Inodes per group: 8192Inode size: 256Journal blocks: 1024Label: cacheBlocks: 65536Block groups: 2Reserved block group size: 15
Created filesystem with 11/16384 inodes and 2089/65536 blocks
out/target/product/flounder/cache.img maxsize=274053120 blocksize=4224 total=6398184 reserve=2770944
[ 86% 41549/47944] Construct recovery from boot
failed to reconstruct target deflate chunk 1 [(null)]; treating as normal
chunk 0: type 0 start 0 len 7262218
chunk 1: type 2 start 7262218 len 3961856
chunk 2: type 0 start 8940357 len 1211
Construct patches for 3 chunks...
patch   0 is 201 bytes (of 7262218)
patch   1 is 2148722 bytes (of 1678139)
patch   2 is 158 bytes (of 1211)
chunk   0: normal   (         0,    7262218)         201
chunk   1: deflate  (   7262218,    4308074)     2148722  (null)
chunk   2: normal   (  11570292,        908)         158
[ 86% 41609/47944] Target system fs i.../systemimage_intermediates/system.img
FAILED: /bin/bash -c "(if [ -d out/target/product/flounder/system/vendor ] && [ ! -h out/target/product/flounder/system/vendor ]; then echo 'Non-symlink out/target/product/flounder/system/vendor detected!' 1>&2; echo 'You cannot install files to out/target/product/flounder/system/vendor while building a separate vendor.img!' 1>&2; exit 1; fi ) && (ln -sf /vendor out/target/product/flounder/system/vendor ) && (mkdir -p out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/ out/target/product/flounder/obj/PACKAGING/systemimage_intermediates && rm -rf out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"fs_type=ext4\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"system_size=2782920704\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"userdata_fs_type=f2fs\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"cache_fs_type=ext4\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"cache_size=268435456\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"extfs_sparse_flag=-s\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"squashfs_sparse_flag=-s\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"selinux_fc=out/target/product/flounder/root/file_contexts.bin\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"boot_signer=false\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"verity=true\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"verity_key=build/target/product/security/verity\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"verity_signer_cmd=verity_signer\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"verity_fec=true\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"system_verity_block_device=/dev/block/platform/sdhci-tegra.3/by-name/APP\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"vendor_verity_block_device=/dev/block/platform/sdhci-tegra.3/by-name/VNR\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (echo \"skip_fsck=true\" >>  out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt ) && (PATH=out/host/linux-x86/bin/:\$PATH ./build/tools/releasetools/build_image.py out/target/product/flounder/system out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system_image_info.txt out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/flounder/system || ( echo \"Out of space? the tree size of out/target/product/flounder/system is (MB): \" 1>&2 ; du -sm out/target/product/flounder/system 1>&2; if [ \"ext4\" == \"ext4\" ]; then maxsize=2782920704; if [ \"\" == \"true\" ]; then maxsize=\$((maxsize - 4096 * 4096)); fi; echo \"The max is \$(( maxsize / 1048576 )) MB.\" 1>&2 ; else echo \"The max is \$(( 2782920704 / 1048576 )) MB.\" 1>&2 ; fi; mkdir -p out/dist; cp out/target/product/flounder/installed-files.txt out/dist/installed-files-rescued.txt; exit 1 ) )"
error: failed to build out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system.img from out/target/product/flounder/system
Running:  mkuserimg.sh -s out/target/product/flounder/system out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system.img ext4 system 2739474432 -D out/target/product/flounder/system -L system out/target/product/flounder/root/file_contexts.bin
make_ext4fs -s -T -1 -S out/target/product/flounder/root/file_contexts.bin -L system -l 2739474432 -a system out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/flounder/system out/target/product/flounder/system
Creating filesystem with parameters:Size: 2739474432Block size: 4096Blocks per group: 32768Inodes per group: 7968Inode size: 256Journal blocks: 10450Label: systemBlocks: 668817Block groups: 21Reserved block group size: 167
Created filesystem with 1911/167328 inodes and 195994/668817 blocks
build_verity_tree -A aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpYToHEX_verity_images/verity.img
system/extras/verity/build_verity_metadata.py 2739474432 /tmp/tmpYToHEX_verity_images/verity_metadata.img 76b36e3a43c9ddfeab604f2266914bd929210830193de3d5caafa58df2384df7 aee087a5be3b982978c923f566a94613496b417f2af592639bc80d141e34dfe7 /dev/block/platform/sdhci-tegra.3/by-name/APP verity_signer build/target/product/security/verity.pk8
cat /tmp/tmpYToHEX_verity_images/verity_metadata.img >> /tmp/tmpYToHEX_verity_images/verity.img
fec -e out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpYToHEX_verity_images/verity.img /tmp/tmpYToHEX_verity_images/verity_fec.img
Could not build FEC data! Error: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
sh: 行 1: 53725 已放弃               (吐核)fec -e out/target/product/flounder/obj/PACKAGING/systemimage_intermediates/system.img /tmp/tmpYToHEX_verity_images/verity.img /tmp/tmpYToHEX_verity_images/verity_fec.img
Out of space? the tree size of out/target/product/flounder/system is (MB):
680 out/target/product/flounder/system
The max is 2654 MB.
[ 86% 41609/47944] Building with Jack...testrunner_intermediates/classes.jack
ninja: build stopped: subcommand failed.
make: *** [ninja_wrapper] 错误 1

,这个问题因为已经到了86%了,处理问题一次,就需要好几小时时间,所以很坑。

最后:

Android AOSP 源码 编译 android5.1.1,并刷入手机相关推荐

  1. Android aosp源码阅读

    前言 最近因为找工作,需要频繁查阅Android源码.因此,打算在本地硬盘上下载Android源码,通过Android Studio来阅读. Android 源码构建:https://source.a ...

  2. 【流媒体开发】VLC Media Player - Android 平台源码编译 与 二次开发详解 (提供详细800M下载好的编译源码及eclipse可调试播放器源码下载)

    作者 : 韩曙亮  博客地址 : http://blog.csdn.net/shulianghan/article/details/42707293 转载请注明出处 : http://blog.csd ...

  3. Android 内核源码编译记录

    注:此处内容总结自google官网:AOSP 编译内核.编译完成后刷机部分参考自其他大佬的文章.文中末尾提供了上传至CSDN的msm内核和Aarch64gcc工具 的下载链接,不想从官网下载的可以直接 ...

  4. android 12 源码编译与虚拟机调试

    android 12 源码编译与虚拟机调试 android 12编译环境搭建 安装android 12环境依赖 android 12源码下载 下载repo工具 repo工具下载 国内repo工具修改 ...

  5. kali系统AOSP源码编译

    kali系统AOSP源码编译 文章目录 kali系统AOSP源码编译 前言 一.编译准备 1.修改`zsh`为bash 2.安装`openjdk-8-jdk` 3.修改默认Python版本 4.添加环 ...

  6. 02 A33 Android系统源码编译

    下载源码包,解包后进入Android-SDK/tools目录. 1 先安装dtc-master和fakeroot工具. dtc-master安装方法: 解包后,在源码目录下: make &&a ...

  7. Pixel 4 AOSP源码编译及刷机

    先吐槽,Google的代码和文档写的是真烂.完全根据他的文档来操作是完不成Pixel 4 AOSP源码编译和刷机这个事情的.经过痛苦的挣扎,最后终于刷机成功了. 代码下载 代码下载的流程在这,http ...

  8. 下载AOSP源码编译、调试、刷机

    一.准备工作 系统最好是Linux或者mac OS(本文基于Ubuntu). Ubuntu设置永不休眠,在setting中搜索power.blank-screen选择never. 一块大一点儿的硬盘, ...

  9. Android 12源码编译报错:FAILED: out/soong/build.ninja

    Android 12源码编译报错:FAILED: out/soong/build.ninja android12源码编译中报如下错误: 网上查了比较多资料发现是swap分区不够导致的,报错时使用fre ...

最新文章

  1. weakself的一种写法
  2. VS2013中提示:没有可放置在工具箱上的组件
  3. 【Qt】创建线程程序示例
  4. springboot 获取application参数_LOOK ! SpringBoot的外部化配置最全解析
  5. 录制电脑屏幕的软件_电脑屏幕录制操作方法,太实用了!
  6. jqgrid for asp.net 遍历所有列rowObject时不用输入编号
  7. php-fpm安装包_linux下安装php php-fpm(转载)
  8. QuickTime Player 如何开启倍速播放?
  9. 解决办法:configure后,没有更新Makefile
  10. 介绍一下小规模纳税人如何开具增值税专用发票的流程
  11. String常用方法
  12. 电路交换,分组交换,报文交换
  13. 1.21 同级比较 倒装句 否定Neither
  14. ESP32基于arduino开发的心跳体温检测系统(四)本地端系统整合
  15. 四川一度智信|小白卖家不懂选品?
  16. VBA小程序_遍历所有工作表_复制粘贴为数值
  17. android 点击变色的两种情况、textview点击变色以及自定义checkbox
  18. acwing349 黑暗城堡 ——最短路径生成树
  19. P2P流媒体开源项目汇总与简述
  20. 年度回忆录(2011.01----2011.07)

热门文章

  1. windows 云服务器计算器,windows7 云主机
  2. Android调用系统相机拍照
  3. 嵌入式学习⑤——STM32嵌入式应用系统设计
  4. markdown 合并单元格、表格内换行
  5. 算术编码、译码以及matlab实现
  6. Python实现一个简单课堂点名器
  7. 发邮件怎么把附件内容直接显示_优德分享:如何发邮件会让人觉得你更靠谱?...
  8. Java根据子节点查找父节点
  9. 计算机考研复试面试问题总结和回答
  10. 极简文艺的浏览器主页推荐,无广告,文艺又清新的网址导航