基础环境

1.系统:ubuntu16.04(阿里云16核16G内存)
2.安卓版本: android-8.1.0_r1 
3.openjdk: 1.8
4.python版本: 2.7(系统默认)

1.设置ubuntu镜像源

/etc/apt/sources.list 追加

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

2.安装依赖库

sudo apt-get update 
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

3.安装openjdk8

安装openjdk8(这里安装jdk8) 
sudo apt-get install openjdk-8-jdk 
卸载jdk:sudo apt-get remove openjdk-8-jdk 
卸载jre: sudo apt-get remove openjdk-8-jre-headless  
安装openjdk7 
sudo add-apt-repository ppa:openjdk-r/ppa  #更新下载链接 
sudo apt-get update 
sudo apt-get install openjdk-7-jdk

4.下载repo

curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo 
chmod +x repo 
加入环境变量 
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

5.下载android源码

1)通过初始化包下载源码(这里使用方式1下载源码)
aosp-latest.tar大概110G
wget -c -t 0 https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar
tar -xvf aosp-latest.tar
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-8.1.0_r1 
repo sync 后台运行 nohup repo sync -j16 &

2)传统方式直接下载源码(大约1个多小时,android8.0源码大约60G)
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-8.1.0_r1 
repo sync 后台运行 nohup repo sync -j16 &

6.下载驱动

这里我们下载的是android-8.1.0_r1
版本代号
https://source.android.google.cn/setup/start/build-numbers#source-code-tags-and-builds
找到对应的Build: OPM1.171019.011
执行的设备: Pixel 2 XL、Pixel 2、Pixel XL、Pixel、Pixel C、Nexus 6P、Nexus 5X
驱动地址
https://developers.google.cn/android/drivers
通过OPM1.171019.011和Nexus6P找到对应的驱动

将两个驱动放在源码根目录下如: android-8.1.0_r1目录下解压执行,生成Vendor文件夹

7.设置jack服务内存

设置jack服务内存prebuilts/sdk/tools/jack-admin
android-8.1.0_r1源码修改如下:
JACK_SERVER_VM_ARGUMENTS="${JACK_SERVER_VM_ARGUMENTS:=-Dfile.encoding=UTF-8 -Xmx12g}"
注:每个版本不一样,主要添加 -Xmx12g

8.编译源码

source build/envsetup.sh
lunch 选择28 aosp_angler-userdebug
make -j32  (我的是16核心,建议2*核心+2)
或后台运行 nohup make -j32 > build.log %

9.刷机到Nexus6P

注:使用Macbook Pro刷机

1).编译完成后将目录out/target/product/angler目录下的img文件拷贝出来
boot.img 
recovery.img
system.img
userdata.img
cache.img
2).下载android-8.1.0_r1的Build(OPM1.171019.011)对应的"angler" for Nexus 6P的工厂镜像
https://developers.google.cn/android/images  
下载后文件名为:
angler-opm1.171019.011-factory-39448337.zip
3).解锁OEM(开发者选项中开启)
4).解压下载的angler-opm1.171019.011-factory-39448337.zip文件
重启进入bootloader,接着执行:
adb reboot bootloader 
./flash-base.sh
5).解压文件夹image-angler-opm1.171019.011.zip得到vernder.img
fastboot flash vendor vendor.img
6).刷入编译的镜像文件,目录: out/target/product/angler
fastboot flash boot boot.img 
#如果报错执行 fastboot flash:raw boot boot.img
fastboot flash recovery recovery.img 
fastboot flash system system.img 
fastboot flash userdata userdata.img 
fastboot flash cache cache.img
7).刷完重启
fastboot reboot 

注: 我们也可以替换image-angler-opm1.171019.011.zip中的img镜像,使用flash-all.sh一键刷机

问题1:执行fastboot flash boot boot.img 报错fastboot:error:couldn‘t parse partition size ‘0x’

将boot.img复制到sdk/platforms(/Users/hecj/profile/android-sdk-macosx/platforms)目录下,在该目录下执行
fastboot flash:raw boot boot.img

发表评论

电子邮件地址不会被公开。 必填项已用*标注