VMware虚拟机 ubuntu20.04编译rockpi4b 安卓11系统
VMware虚拟机 ubuntu20.04编译rockpi4b 安卓11系统
- 虚拟机信息
- 下载安卓11源码
- 编译
-
- 1.整体编译
-
- 配置
- 编译
-
- 缺少gawk
- 缺少openssl
- 2.单元编译
-
- 编译uboot
- 编译内核
- 编译AOSP(安卓11)
- 总结
- 参考文档
虚拟机信息
下载ubuntu20.04镜像
点我直接下载
以下所有配置都是针对于20.04版本的,如需其他版本配置请看参考文档1-7,谷歌的文档可能需要梯子才可以访问
VMware虚拟机配置信息
谷歌要求(原文看参考文档)
硬件要求
您的开发工作站必须达到或超出以下硬件要求:
如果是 Android 2.3.x (Gingerbread) 及更高版本(包括 master 分支),需要 64
位环境。如果是较低的版本,则可以在 32 位系统中进行编译。 如果要检出代码,至少需要 250 GB 可用磁盘空间;如果要进行构建,则还需要
150 GB。如果要进行多次构建,则需要更多空间。 注意:如果您要检出镜像,就需要更多空间,因为完整的 Android 开源项目
(AOSP) 镜像包含所有使用过的 Git 代码库。 至少需要 16 GB 的可用 RAM,但 Google 建议提供 64 GB。 从
2021 年 6 月起,Google 使用 72 核机器,内置 RAM 为 64 GB,完整构建过程大约需要 40
分钟(增量构建只需几分钟时间,具体取决于修改了哪些文件)。相比之下,RAM 数量相近的 6 核机器执行完整构建过程需要 3 个小时。
我的配置如下
需要注意的是虚拟机内存一定要大于16G,否则会报很多莫名其妙的错误,折腾了一周都没解完,后面 直接使用了钞能力,加了两条16G内存条。
硬盘建议大于500G,小编由于电脑资源有限,一个分区最大也就400G,最后编译完用了270G左右
更换阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
安装和配置
依赖库安装
sudo apt updatesudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig gawk libssl-devsudo ln -s /usr/bin/python3 /usr/bin/python
下载repo工具
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o /tmp/repo -ksudo cp /tmp/repo /usr/local/bin/reposudo chmod +x /usr/local/bin/repo
repo只支持python3.5以上版本,需要升级python后才能正常使用
谷歌 警告:对 Python 2 的支持已于 2020 年 1 月 1 日停止,详情请见 Sunsetting Python 2(废弃Python 2)一文。所有主要的 Linux 发行版都在停止支持 Python 2 软件包。Google 强烈建议您将所有脚本改用Python 3。
环境变量设置
在.bashrc末尾追加以下信息,然后关掉当前终端,重新打开一个,使环境变量生效
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
下载安卓11源码
如果没有设置git邮箱和名字的需要先设置一下
git config --global user.email "xxxx@qq.com" #设置邮箱git config --global user.name "xxxx" #设置名字
初始化repo
mkdir rock-android11cd rock-android11repo init -u https://gitee.com/a_little_progress/manifests.git -b Android11_Radxa_rk11 -m rockchip-r-release.xml
然后会看到如下打印,输入Y和N都可以,我选的n
Your identity is: xxx <xxxx@qq.com>If you want to change this, please re-run 'repo init' with --config-nameTesting colorized output (for 'repo diff', 'repo status'): black red green yellow blue magenta cyan white bold dim ulreverseEnable color display in this user account (y/N)?
然后开始同步源码
repo sync -d --no-tags -j12
有如下类似的报错信息,not a valid SHA1
Fetching: 60% (476/785) rk/hardware/rk29/mpi-mmzerror.GitError: Cannot fetch kernel/configs update-ref: fatal: 92eb6e4985f89504ea472eaec0be7c99c8d2cd4e^0: not a valid SHA1Fetching: 98% (777/785) platform/prebuilts/sdkerror.GitError: Cannot fetch rk/kernel update-ref: fatal: 66abf06fb1af001ddf8ae75640bc80f43adcf331^0: not a valid SHA1
原因是官方更新了代码,但是没有更新repo的manifests文件,所以报错。
只需要修改,.repo/manifests/Android11_Radxa_rk11.2_customization.xml文件中的revision与https://gitlab.com/rockchip_android_r中的commit SHA一致即可,
注意要选对分支,选Android11_Radxa_rk11分支,默认是安卓10的分支,需要手动切换,再复制SHA到manifests文件
修改完之后重新同步,如果还出现这个情况就一直循环修改,直到全部同步完为止
#我这边只需要改掉上面两个commit SHA就可以正常同步了repo sync -d --no-tags -j12Fetching: 77% (606/785) platform/prebuilts/gcc/darwin-x86/aarch64/aarch64-linux- Fetching: 77% (607/785) platform/prebuilts/gcc/darwin-x86/arm/arm-linux-androide Fetching: 77% (608/785) platform/prebuilts/gcc/darwin-x86/host/i686-apple-darwin Fetching: 78% (613/785) platform/prebuilts/gcc/linux-x86/mips/mips64el-linux-and Fetching: 78% (614/785) platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-androi Fetching: 78% (617/785) platform/prebuilts/gcc/darwin-x86/mips/mips64el-linux-an Fetching: 78% (618/785) platform/prebuilts/gcc/darwin-x86/x86/x86_64-linux-andro Fetching: 78% (619/785) platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-a Fetching: 78% (620/785) rk/prebuilts/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-lin Fetching: 100% (785/785), done in 45m51.043sGarbage collecting: 100% (785/785), done in 4.090sUpdating files: 100% (539/539), done.Updating files: 100% (558/558), done.Updating files: 100% (602/602), done.Updating files: 100% (497/497), done.Updating files: 100% (1647/1647), done.Updating files: 100% (273/273), done.Updating files: 100% (64/64), done.........省略N个Updating files打印..........Checking out: 100% (785/785), done in 45m48.548srepo sync has finished successfully.
到这里源码就成功下载好了。
编译
整体编译和单元编译二选一。
1.整体编译
配置
source build/envsetup.shlunch rk3399_ROCKPI4B_Android11-userdebug
配置完有如下打印
device/rockchip/common/device.mk:931: warning: Please set client id with your own MADA ID!============================================PLATFORM_VERSION_CODENAME=RELPLATFORM_VERSION=11TARGET_PRODUCT=rk3399_ROCKPI4B_Android11TARGET_BUILD_VARIANT=userdebugTARGET_BUILD_TYPE=releaseTARGET_ARCH=arm64TARGET_ARCH_VARIANT=armv8-aTARGET_CPU_VARIANT=cortex-a53TARGET_2ND_ARCH=armTARGET_2ND_ARCH_VARIANT=armv7-a-neonTARGET_2ND_CPU_VARIANT=cortex-a15HOST_ARCH=x86_64HOST_2ND_ARCH=x86HOST_OS=linuxHOST_OS_EXTRA=Linux-5.13.0-51-generic-x86_64-Ubuntu-20.04.4-LTSHOST_CROSS_OS=windowsHOST_CROSS_ARCH=x86HOST_CROSS_2ND_ARCH=x86_64HOST_BUILD_TYPE=releaseBUILD_ID=RQ3A.210705.001OUT_DIR=out============================================
编译
帮助文档
./build.sh --helpdevice/rockchip/common/device.mk:931: warning: Please set client id with your own MADA ID!./build.sh: illegal option -- -USAGE: [-U] [-CK] [-A] [-p] [-o] [-u] [-v VERSION_NAME]No ARGS means use default build optionWHERE: -U = build uboot-C = build kernel with Clang-K = build kernel-A = build android-p = will build packaging in IMAGE-o = build OTA package-u = build update.img-v = build android with 'user' or 'userdebug'-d = huild kernel dts name-V = build version-J = build jobs
开始编译
./build.sh -J12 -UACKup #我最大支持12线程编译
然后就 开始漫长的编译 阶段了。下面列出可能会遇到的问题
缺少gawk
awk: line 2: function strtonum never defined
Build uboot failed!
执行命令安装即可
sudo apt-get install gawk
缺少openssl
scripts/extract-cert.c:21:10: fatal error: openssl/bio.h: No such file or directory
21 | #include
| ^~~~~~~~~~~~~~~
执行命令安装即可
sudo apt-get install libssl-dev
2.单元编译
编译uboot
cd u-boot#清除编译信息make cleanmake mrpropermake distclean#配置和编译./make.sh rockpi4b
编译内核
cd kernel#配置ADDON_ARGS="CC=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/clang LD=../prebuilts/clang/host/linux-x86/clang-r383902b/bin/ld.lld"#清除make clean#编译make $ADDON_ARGS ARCH=arm64 rockchip_defconfig android-11.config rockpi_4b.configmake $ADDON_ARGS ARCH=arm64 rk3399-rockpi-4b.img -j12
编译AOSP(安卓11)
#配置source buile/envsetup.shlunch rk3399_ROCKPI4B_Android11-userdebug#编译make -j12
这一块比较耗时,我大概耗费了四个多小时。
# build completed successfully (04:18:29 (hh:mm:ss)) #Build android ok!
总结
经过几天的折腾终于编译成功了,浪费这么多时间的最大原因是内存低于16G,导致会出现很多莫名其妙的错误,当我主机内存加到32G时,之前遇到的问题都没了。其次就是rockpi提供的文档过于少,而谷歌官方文档又需要梯子(不得不使用钞能力)。源码过于庞大,编译环境没搞好就很耽误时间。以我这个配置为例,一路顺畅的话,下载加编译也需要8个小时以上才能编译完。
rockpi不建议小白入手!
参考文档
参考文档1
参考文档2
参考文档3
参考文档4
参考文档5
参考文档6
参考文档7
参考文档8