Repo下载AOSP源码:基于ubuntu22.04 环境配置,android-12.0.0_r32

1. 前言

使用高版本Ubuntu配置了编译环境后,发现repo不可使用,Python出了一堆问题,左右尝试无果,最终通过遍历常用的Python版本,发现3.9可以用。

  1. 对 Python 2 的支持已于 2020 年 1 月 1 日停止,Google 强烈建议您将所有脚本改用 Python 3。
  2. 目前使用google repo下载AOSP源码,需要使用Python3.9,测试其余版本皆不可用
  3. Ubuntu20.04 默认支持Python3.9,而Ubuntu22.04则默认是Python3.10
  4. 本文介绍基于Ubuntu22.04下载安卓源码,方法步骤适用于其余Ubuntu版本。

系列文章

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


2. 配置Python

2.1 安装python3.9

  • 添加ppa源,此源可安装多个python版本
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9
sudo apt install python3.7 #不用的省略,此处只是告知此PPA源支持多个版本

2.2 查看系统中存在的Python版本

  • 使用如下命令,发现系统中存在多个Python版本
  • sudo update-alternatives --list python

2.3 配置多Python版本共存

 sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7  3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.93
szhou@bc03:~/works/aosp/aosp$ 

2.4 选定Python3.9为当前版本

  • 如下选择列表中的第4个
szhou@bc03:~/works/aosp/aosp$ sudo update-alternatives --config python
There are 4 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                 Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.9    4         auto mode
  1            /usr/bin/python2.7    1         manual mode
  2            /usr/bin/python3.10   2         manual mode
  3            /usr/bin/python3.7    3         manual mode
  4            /usr/bin/python3.9    4         manual mode

Press <enter> to keep the current choice[*], or type selection number: 4

2.5 查看版本

  • 设置完后,确认下版本,已设置为Python 3.9版本
szhou@bc03:~/works/aosp/aosp$ python -V
Python 3.9.12
szhou@bc03:~/works/aosp/aosp$ 

3. 下载 repo 工具

mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

4. 下载AOSP源码包

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

5. 同步代码

  • 联网同步经常会失败,失败后再次repo sync直到提示完全成功

5.1 联网同步最新代码

cd AOSP   # 解压得到的 AOSP 工程目录
# 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录
repo sync
  • 示例
szhou@bc03:~/works/aosp/aosp$ repo sync -j4
Fetching: 100% (1125/1125), done in 4m0.280s
Garbage collecting: 100% (1125/1125), done in 5.500s
Checking out: 100% (1125/1125), done in 2.929s
repo sync has finished successfully.
szhou@bc03:~/works/aosp/aosp$ 

5.2 不联网直接检出代码

  • 此方法速度较快,直接从.repo仓库中检出代码
  • 缺点就是代码不是最新的,切分支时候可能出现代码不同步的编译问题
cd AOSP   # 解压得到的 AOSP 工程目录
repo sync -l 仅checkout代码

6.切分支

6.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” 只看S版本的分支

szhou@bc03:~/works/aosp/aosp/.repo/manifests$ git branch -a | grep "android-12"
  remotes/origin/android-12.0.0_r1
  remotes/origin/android-12.0.0_r10
  ……省略……
  remotes/origin/android-12.0.0_r19
  remotes/origin/android-12.0.0_r2
  remotes/origin/android-12.0.0_r20
  remotes/origin/android-12.0.0_r21
  remotes/origin/android-12.0.0_r25
  remotes/origin/android-12.0.0_r26
  remotes/origin/android-12.0.0_r27
  remotes/origin/android-12.0.0_r28
  remotes/origin/android-12.0.0_r29
  remotes/origin/android-12.0.0_r3
  remotes/origin/android-12.0.0_r30
  remotes/origin/android-12.0.0_r31
  remotes/origin/android-12.0.0_r32
  • 如下在 -b 后面追加分支名称,执行 repo init命令
  • repo sync 同步分支代码
szhou@bc03:~/works/aosp/aosp$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-12.0.0_r32
.repo/manifests/: discarding 491 commits

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

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

7.处理同Repo步错误

7.1 错误提示

正在终止
error: external/boringssl/: platform/external/boringssl checkout 8dbb9309b540a16b72b6cb23cc942e90a583cc32 
error: Cannot checkout platform/external/boringssl
Checking out: 13% (145/1051) platform/external/flatbufferserror: 工作区中下列未跟踪的文件将会因为检出操作而被覆盖:
     …… 省略 ……
        doc/vizualization/layout/pdf/sa-D1.pdf
        doc/vizualization/layout/pdf/sa-D2.pdf
        doc/vizualization/layout/pdf/sa-D2v.pd
正在终止
error: external/libabigail/: platform/external/libabigail checkout c1c139bd6553bfd924c65a30e922e154e9a160e6 
error: Cannot checkout platform/external/libabigail
Checking out: 60% (640/1051) platform/external/wycheprooferror.GitError: Cannot checkout platform/libcore: platform/libcore rev-list ('^d8d7f29bb1dd51d3ed2f6e2766fcf449f9b60ee7', 'HEAD', '--'): fatal: bad object d8d7f29bb1dd51d3ed2f6e2766fcf449f9b60ee7

error: Cannot checkout platform/libcore
Checking out: 100% (1051/1051), done in 1m12.279s

error: Unable to fully sync the tree.
error: Checking out local projects failed.
Failing repos:
external/boringssl
cts
external/libabigail
libcore
Try re-running with "-j1 --fail-fast" to exit at the first error.
szhou@bc04:~/aosp/aosp$ 

7.2 解决办法

(1)删除失败的.git仓库
szhou@bc04:~/aosp/aosp$ rm -rf .repo/projects/external/boringssl.git/
szhou@bc04:~/aosp/aosp$ rm -rf .repo/projects/external/libabigail.git/
szhou@bc04:~/aosp/aosp$ rm -rf .repo/projects/libcore.git/

szhou@bc04:~/aosp/aosp$ rm -rf external/boringssl
szhou@bc04:~/aosp/aosp$ rm -rf external/libabigail
szhou@bc04:~/aosp/aosp$ rm -rf libcore
szhou@bc04:~/aosp/aosp$ 
(2)删除失败的代码目录
  • 若已有部分代码下载下来,则把其project代码目录删除,若还没有,这不用。
szhou@bc04:~/aosp/aosp$ rm -rf external/boringssl
szhou@bc04:~/aosp/aosp$ rm -rf external/libabigail
szhou@bc04:~/aosp/aosp$ rm -rf libcore
szhou@bc04:~/aosp/aosp$ 
(3)重新repo sync
  • 如果再出现同样问题,重复1,2,3步骤,直到成功
(4)完成代码同步
        .prebuilt_info/prebuilt_info_hostsidetests_stagedinstall_testdata_apex__x86_com_android_apex_cts_shi
正在终止
error: cts/: platform/cts checkout 5e3383612940c9d71af5d131be1433e104367cee 
error: Cannot checkout platform/cts
正在更新文件: 100% (2294/2294), 完成./external/rust/crates/atty正在更新文件:  98% (2249/2294)
Checking out: 100% (1051/1051), done in 13.087s

error: Unable to fully sync the tree.
error: Checking out local projects failed.
Failing repos:
cts
Try re-running with "-j1 --fail-fast" to exit at the first error.
szhou@bc04:~/aosp/aosp$ rm -rf cts/     
szhou@bc04:~/aosp/aosp$ rm -rf .repo/projects/cts.git/
  • repo sync has finished successfully.
szhou@bc04:~/aosp/aosp$ repo sync
Fetching: 100% (1051/1051), done in 4m40.573s
Garbage collecting: 100% (1051/1051), done in 3.153s
正在更新文件: 100% (22773/22773), 完成.test/vts-testcase/performance正在更新文件:  30% (6979/22773)
Checking out: 100% (1051/1051), done in 45.428s
repo sync has finished successfully.
szhou@bc04:~/aosp/aosp$ 

8.编译测试

builder@mm-aosp:~/code$ source build/envsetup.sh 
builder@mm-aosp:~/code$ lunch 
Which would you like? [aosp_arm-eng] 42
15:22:15 Build sandboxing disabled due to nsjail error.
15:22:17 Build sandboxing disabled due to nsjail error.

============================================
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-14.04.5-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=SQ1D.220205.004
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera
============================================

builder@mm-aosp:~/code$ make -j32
builder@mm-aosp:~/code$
[ 99% 137251/137272] //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 4281 other contexts)
Missing class org.jetbrains.annotations.Nullable (referenced from: android.graphics.fonts.Font com.android.keyguard.FontInterpolator$InterpKey.l and 1038 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% 137272/137272] Target vbmeta image: out/target/product/generic_x86_64/vbmeta.img

#### build completed successfully (01:09:58 (hh:mm:ss)) ####

builder@mm-aosp:~/code$

9.结尾

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

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿迷创客

感谢!您的支持是我写作的动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值