Android AOSP 源码 编译 android5.1.1,并刷入手机

8 篇文章 0 订阅
8 篇文章 0 订阅

必备:

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: 268435456
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8192
    Inode size: 256
    Journal blocks: 1024
    Label: cache
    Blocks: 65536
    Block groups: 2
    Reserved 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: 2739474432
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7968
    Inode size: 256
    Journal blocks: 10450
    Label: system
    Blocks: 668817
    Block groups: 21
    Reserved 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%了,处理问题一次,就需要好几小时时间,所以很坑。

最后:

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值