基础环境
1.系统:ubuntu16.04
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)通过初始化包下载源码
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
2)传统方式直接下载源码(大约1个多小时,android8.0源码大约60G)
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-8.1.0_r1
repo sync
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和Nexus5x找到对应的驱动
将两个驱动放在源码根目录下如: android-8.1.0_r1目录下解压执行,生成Vendor文件夹
7.设置jack服务内存
设置jack服务内存prebuilts/sdk/tools/jack-admin
export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx8g"
或者搜索
JACK_SERVER_VM_ARGUMENTS="${JACK_SERVER_VM_ARGUMENTS:=-Dfile.encoding=UTF-8 -XX:+TieredCompilation}"
注:每个版本不一样,主要添加 -Xmx8g
8.编译源码
source build/envsetup.sh
lunch 选择29 aosp_bullhead-userdebug
make -j10 (我的是4核心,建议2*核心+2)
注: 我MAC16G内存,4核 编译大概2个半小时
9.刷机到Nexus5x
设置环境变量/etc/profile
export ANDROID_PRODUCT_OUT=/aosp/android-8.1.0_r1/out/target/product/bullhead
生效
source /etc/profile
进入fastboot刷机模式
adb reboot bootloader
解锁手机(前提是在开发者选项中开启oem解锁)(可选:手机已经解锁,就不需要这步啦)
fastboot flashing unlock
执行刷机(在哪个目录执行均可,因为前面已经设置ANDROID_PRODUCT_OUT环境变量)
fastboot -w flashall
注:out/target/product/bullhead是编译后的img包地址