- 1. 前言
- 2. 配置Python
- 2.1 安装python3.9
- 2.2 查看系统中存在的Python版本
- 2.3 配置多Python版本共存
- 2.4 选定Python3.9为当前版本
- 2.5 查看版本
- 3. 下载 repo 工具
- 4. 下载AOSP源码包
- 5. 同步代码
- 5.1 联网同步最新代码
- 5.2 不联网直接检出代码
- 6.切分支
- 6.1 查看可用分支
使用高版本Ubuntu配置了编译环境后,发现repo不可使用,Python出了一堆问题,左右尝试无果,最终通过遍历常用的Python版本,发现3.9可以用。
- 对 Python 2 的支持已于 2020 年 1 月 1 日停止,Google 强烈建议您将所有脚本改用 Python 3。
- 目前使用google repo下载AOSP源码,需要使用Python3.9,测试其余版本皆不可用
- Ubuntu20.04 默认支持Python3.9,而Ubuntu22.04则默认是Python3.10
- 本文介绍基于Ubuntu22.04下载安卓源码,方法步骤适用于其余Ubuntu版本。
- 添加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
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 Press2.5 查看版本to keep the current choice[*], or type selection number: 4
- 设置完后,确认下版本,已设置为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/repo4. 下载AOSP源码包
- 直接下载tar包速度更快,所以直接列出此方法
wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下载初始化包 tar xf aosp-latest.tar5. 同步代码
- 联网同步经常会失败,失败后再次repo sync直到提示完全成功
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: szhouIf 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



