Android源代码下载与编译 - 2019 (基于Ubuntu 18.10,适用于国内环境)
下载repo工具
如果没有下载repo脚本工具,请到清华mirror下载
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/'
下载Android
因为Android的源码越来越大,repo sync失败的概率也越来越高。
所以我们可以避开使用repo sync的方式,而采用下载预下载包的方式来实现:
wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下载初始化包
tar xf aosp-latest.tar
cd AOSP # 解压得到的 AOSP 工程目录
repo sync # 正常同步一遍即可得到完整目录
下载厂商代码
例,我们用hikey960的代码:
wget https://dl.google.com/dl/android/aosp/hisilicon-hikey960-OPR-3c243263.tgz
tar xf hisilicon-hikey960-OPR-3c243263.tgz
解压之后会生成extract-hisilicon-hikey960.sh,运行这个文件:
./extract-hisilicon-hikey960.sh
接受协议输入I ACCEPT,然后就可以顺利解压运行。
会解压出下面的一些文件和目录:
vendor/
vendor/linaro/
vendor/linaro/hikey960/
vendor/linaro/hikey960/hisilicon/
vendor/linaro/hikey960/hisilicon/device-partial.mk
vendor/linaro/hikey960/hisilicon/BoardConfigPartial.mk
vendor/linaro/hikey960/hisilicon/proprietary/
vendor/linaro/hikey960/hisilicon/proprietary/libOMX.hisi.vdec.core.so
vendor/linaro/hikey960/hisilicon/proprietary/libc_secshared.so
vendor/linaro/hikey960/hisilicon/proprietary/libhilog.so
vendor/linaro/hikey960/hisilicon/proprietary/libOMX_Core.so
vendor/linaro/hikey960/hisilicon/proprietary/lib64/
vendor/linaro/hikey960/hisilicon/proprietary/lib64/libOMX.hisi.vdec.core.so
vendor/linaro/hikey960/hisilicon/proprietary/lib64/libc_secshared.so
vendor/linaro/hikey960/hisilicon/proprietary/lib64/libhilog.so
vendor/linaro/hikey960/hisilicon/proprietary/lib64/libOMX_Core.so
vendor/linaro/hikey960/hisilicon/proprietary/lib64/libstagefrighthw.so
vendor/linaro/hikey960/hisilicon/proprietary/lib64/libhiion.so
vendor/linaro/hikey960/hisilicon/proprietary/lib64/libOMX.hisi.video.decoder.so
vendor/linaro/hikey960/hisilicon/proprietary/libstagefrighthw.so
vendor/linaro/hikey960/hisilicon/proprietary/libhiion.so
vendor/linaro/hikey960/hisilicon/proprietary/libOMX.hisi.video.decoder.so
vendor/linaro/hikey960/device-vendor.mk
vendor/linaro/hikey960/BoardConfigVendor.mk
配置编译环境
其它基本上开发环境上大家都会配,就不多说了。
在Ubuntu 18.10上需要注意的是,ncurses默认安装的是版本6,而2019年3月的Android版本仍然需要ncurses5.
例:
sudo apt install libncurses5-dev
编译
我们仍以Android目前(2019年3月)推荐的hikey960硬件为目标,编译命令如下:
. ./build/envsetup.sh
lunch hikey960-userdebug
make -j32
大功告成!