Repo下载编译AOSP源码:基于Ubuntu 21.04,android-12.1.0_r27

Posted 阿迷创客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Repo下载编译AOSP源码:基于Ubuntu 21.04,android-12.1.0_r27相关的知识,希望对你有一定的参考价值。

文章目录

一、 前言

最近准备更新专栏文章,AOSP源码自然也需要进行更新了,但这次不是为最新的android 13, 而是取android 12的最新tag version: android-12.1.0_r27,这应该是市面上的主流版本。

  • 每次更新,自然也会遇到问题,所以就记录一下
  • 另外,这次我们将直接配置本地服务器,而不是通过docker,让每次执行更简单,o()o

二、系列文章

第1篇:Repo下载AOSP源码:基于ubuntu22.04 环境配置
第2篇:Repo下载、编译AOSP源码:基于Ubuntu 21.04,android-12.1.0_r27

三、 服务器配置

3.1 Repo 工具配置

请参考第1篇文章的第2节和第3节,完成repo、 python3.9的配置

3.2 AOSP 依赖配置

谷歌官方依赖

sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5-dev lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

补充依赖

sudo apt install libncurses5

四、 下载源码

4.1 下载 aosp tar ball

  • 直接下载tar包速度更快,所以直接列出此方法
wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下载初始化包
tar xf aosp-latest.tar

4.2 同步代码

  • 联网同步经常会失败,失败后再次repo sync直到提示完全成功
  • 对于遇到的错误,请参考楼下的错误处理方法
- 示例
```bash
szhou@bc04:~/aosp/aosp$ repo sync -j4

4.3 切分支

4.3.1 查看可用分支

  • 使用 git branch -a 可查看所有可用分支
szhou@bc03:~/works/aosp/aosp$cd .repo/manifests
szhou@bc03:~/works/aosp/aosp/.repo/manifests$ git branch -a 
  • 使用 git branch -a | grep “android-12.1” 只看S版本的最新分支情况

szhou@bc04:~/aosp/aosp/.repo/manifests.git$ git branch -a | grep "android-12.1"
  remotes/m/android-12.1.0_r27 -> origin/android-12.1.0_r27
  remotes/origin/android-12.1.0_r1
  remotes/origin/android-12.1.0_r10
  remotes/origin/android-12.1.0_r11
  remotes/origin/android-12.1.0_r12
  remotes/origin/android-12.1.0_r13
  remotes/origin/android-12.1.0_r14
  remotes/origin/android-12.1.0_r15
  remotes/origin/android-12.1.0_r16
  remotes/origin/android-12.1.0_r17
  remotes/origin/android-12.1.0_r18
  remotes/origin/android-12.1.0_r19
  remotes/origin/android-12.1.0_r2
  remotes/origin/android-12.1.0_r20
  remotes/origin/android-12.1.0_r21
  remotes/origin/android-12.1.0_r22
  remotes/origin/android-12.1.0_r23
  remotes/origin/android-12.1.0_r24
  remotes/origin/android-12.1.0_r25
  remotes/origin/android-12.1.0_r26
  remotes/origin/android-12.1.0_r27
  remotes/origin/android-12.1.0_r3
  remotes/origin/android-12.1.0_r4
  remotes/origin/android-12.1.0_r5
  remotes/origin/android-12.1.0_r6
  remotes/origin/android-12.1.0_r7
  remotes/origin/android-12.1.0_r8
  remotes/origin/android-12.1.0_r9
szhou@bc04:~/aosp/aosp/.repo/manifests.git$ 

可见 android-12.1.0_r27 为最新版本,我们就下载这一个版本

4.3.2 切换分支

  • 如下在 -b 后面追加分支名称,执行 repo init命令
  • repo sync 同步分支代码
szhou@bc04:~/aosp/aosp$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b  android-12.1.0_r27
.repo/manifests/: discarding 491 commits

Your identity is: szhou<66176468@qq.com>
If you want to change this, please re-run 'repo init' with --config-name

repo has been initialized in /home/szhou/aosp/aosp
szhou@bc04:~/aosp/aosp$ repo sync -j4

4.4 处理Repo错误

目前遇到的repo同步错误,通过删除错误的project子目录之后,基本都可以完成同步,尚未遇到过异常。也可详细参考第1篇文章的介绍

  • fatal: 包有 36684 个未解决的 delta
  • fatal: fetch-pack: invalid index-pack output
  • error: Cannot fetch platform/packages/apps/Settings from
处理 delta 中:  87% (249971/286655), 完成 1 个本地对象.
fatal: 包有 36684 个未解决的 delta
fatal: fetch-pack: invalid index-pack output
error: Cannot fetch platform/packages/apps/Settings from https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/packages/apps/Settings
Fetching: 100% (1/1), done in 2m18.049s
Checking out: 45% (474/1040) platform/external/rust/crates/lru-cacheerror.GitError: Cannot checkout platform/packages/apps/Settings: platform/packages/apps/Settings rev-list ('^1a2ab44a46f248a3ba5b1875efeee652c2a20747', 'HEAD', '--'): fatal: bad object 1a2ab44a46f248a3ba5b1875efeee652c2a20747

error: Cannot checkout platform/packages/apps/Settings
Checking out: 100% (1040/1040), done in 1m22.491s

error: Unable to fully sync the tree.
error: Downloading network changes failed.
error: Checking out local projects failed.
Failing repos:
packages/apps/Settings
Try re-running with "-j1 --fail-fast" to exit at the first error.

解决办法如下所示, 将失败的子项目,做 rm -rf 处理,记得同一个错误,要删除2个部分

szhou@bc04:~/aosp/aosp$ rm -rf packages/apps/Settings
szhou@bc04:~/aosp/aosp$ rm -rf .repo/projects/packages/apps/Settings.git/
szhou@bc04:~/aosp/aosp$ repo sync

4.5 同步完成

prebuilts/vndk/v28/: discarding 1 commits
prebuilts/vndk/v29/: discarding 1 commits
prebuilts/vndk/v30/: discarding 1 commits
正在更新文件: 100% (18247/18247), 完成.
sdk/: discarding 3 commits
system/apex/: discarding 238 commits
system/bpf/: discarding 51 commits
system/bpfprogs/: discarding 13 commits
system/bt/: discarding 415 commits
Checking out: 100% (1052/1052), done in 3m52.541s
repo sync has finished successfully.
szhou@bc04:~/aosp/aosp$        

五、编译测试

5.1 编译 aosp_x86_64-eng

  • 为了跑模拟器,选择使用aosp_x86_64-eng项目进行编译测试
szhou@bc04:~/aosp/aosp$ source build/envsetup.sh
szhou@bc04:~/aosp/aosp$ lunch aosp_x86_64-eng

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=12
TARGET_PRODUCT=aosp_x86_64
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_2ND_ARCH=x86
TARGET_2ND_ARCH_VARIANT=x86_64
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.11.0-49-generic-x86_64-Ubuntu-21.04
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=SP2A.220505.008
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera
============================================
szhou@bc04:~/aosp/aosp$  make -j64

5.3 编译错误处理

对于AOSP的官方源码的编译,出现错误大致有3种情况:

  • 代码未同步成功
  • 代码同步成功,但经过一系列git操作,导致分支信息错乱
  • 代码同步成功,但有部分代码基于之前的操作,可能出现个别子项目未对齐

大部分错误,就是代码未对齐、工具缺失依赖的错误

5.3.1 代码问题

  • 即便repo提示已经更新成功,但也会出现代码未对齐的情况,这个时候,将出现错误的project 子项目,使用楼上 rm -rf 将其删除,重新同步即可
  • 例如如下错误
[100% 1/1] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja
FAILED: out/soong/build.ninja
cd "$(dirname "out/soong/.bootstrap/bin/soong_build")" && BUILDER="$PWD/$(basename "out/soong/.bootstrap/bin/soong_build")" && cd / && env -i "$BUILDER"     --top "$TOP"     --out "out/soong"     -n "out"     -d "out/soong/build.ninja.d"     -t -l out/.module_paths/Android.bp.list -globFile out/soong/.bootstrap/build-globs.ninja -o out/soong/build.ninja --available_env out/soong/soong.environment.available --used_env out/soong/soong.environment.used Android.bp
error: frameworks/base/Android.bp:163:1: "framework-all" depends on undefined module "framework-permission.impl"
error: frameworks/base/Android.bp:163:1: "framework-all" depends on undefined module "framework-permission-s.impl"
13:58:17 soong bootstrap failed with: exit status 1

#### failed to build some targets (21 seconds) ####

szhou@bc04:~/aosp/aosp$

5.3.2 依赖缺失错误

  • 经过多个ubuntu版本测试,基本就是缺 libncurses5
sudo apt install libncurses5

5.4 编译成功

  • 没想到32核心64线程的服务器,在使用 -j32和 - j64的编译时间,只相差了不到15分钟
  • 当然,-j32的时候,我是使用docker编译,也许因此会慢一些,后面再做个对比
[ 99% 129266/129287] //frameworks/base/packages/SystemUI:SystemUI r8 [common]
Warning: Missing class android.compat.annotation.UnsupportedAppUsage (referenced from: void com.android.systemui.people.widget.PeopleBackupHelper.writeNewStateDescription(android.os.ParcelFileDescriptor))
Missing class android.support.annotation.Keep (referenced from: kotlinx.coroutines.android.AndroidExceptionPreHandler)
Missing class org.jetbrains.annotations.NotNull (referenced from: java.util.List com.android.keyguard.FontInterpolator$VarFontKey.sortedAxes and 4935 other contexts)
Missing class org.jetbrains.annotations.Nullable (referenced from: android.graphics.fonts.Font com.android.keyguard.FontInterpolator$InterpKey.l and 1143 other contexts)
Info: Stripped invalid locals information from 1 method.
Info in ./out/soong/.intermediates/frameworks/base/packages/SystemUI/SystemUI/android_common/combined/SystemUI.jar:kotlinx/coroutines/scheduling/WorkQueue.class:
  Methods with invalid locals information:
  void kotlinx.coroutines.scheduling.WorkQueue.offloadAllWork$kotlinx_coroutines_core(kotlinx.coroutines.scheduling.GlobalQueue)
  Type information in locals-table is inconsistent. Cannot constrain type: BOTTOM (empty) for value: v15 by constraint INT.
Info: Some warnings are typically a sign of using an outdated Java toolchain. To fix, recompile the source with an updated toolchain.
[100% 129287/129287] Target vbmeta image: out/target/product/generic_x86_64/vbmeta.img

#### build completed successfully (56:40 (mm:ss)) ####

szhou@bc04:~/aosp/aosp$ 

六、结尾

一个简单的下代码,编译,每次总会遇到新问题,这次算是又盘完了

以上是关于Repo下载编译AOSP源码:基于Ubuntu 21.04,android-12.1.0_r27的主要内容,如果未能解决你的问题,请参考以下文章

Repo下载AOSP源码:基于ubuntu22.04 环境配置

Repo下载AOSP源码:基于ubuntu22.04 环境配置

Android 11使用Android Studio调试系统应用:编译服务器的配置AOSP源码的下载编译运行

MacBook下载和编译Android AOSP源码

[Android Pro] AOSP download

AOSP android 源码下载