漫漫Android路---1.AOSP源码获取编译及导入
写在前面
年轻时候的他,发际线尤在,互联网某厂开发Android多年,退三四线某城市苟且
空有撸码双手,却无处安放,子曰温故而知新可以为师矣…故记录此系列以防失能
环境准备
- 1.Ubuntu22.04(700G+8核+8G DDR4)
- 2.VMware® Workstation 16 Pro
AOSP源码获取
AOSP源码较为庞大,相关各模块均是基于git工具进行项目管理与代码提交,整个源码是基于多个git目录分模块整合的
Google基于Python开发了辅助开发者进行多个项目管理的工具Repo,Repo就是封装了git命令的python脚本
1.Repo下载配置
# 在home下创建bin文件夹
mkdir ~/bin
# 把bin文件夹加入环境变量的
PATH=~/bin:$PATH
#下载repo脚本
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
#添加权限
chmod a+x ~/bin/repo
若提示curl提示需要安装
sudo apt install curl
2.Git安装及配置
sudo apt-get install git
git config --global user.name YourName
git config --global user.email YourEmail@example.com
3.AOSP获取
由于某些不可控的网络因素,需要从清华源去获取对应的AOSP源码
https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar
AOSP项目所有的分支列表:代号、标记和 Build 号 | Android 开源项目 | Android Open Source Project
具体流程如下:
# 讲代码包下载到当前目录
wget https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar
# 解压对应的压缩包得到aosp源码目录
tar xf aosp-latest.tar
# 进入源码目录
cd aosp
# 初始化仓库
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
# repo制定android版本,末尾的-b android-9.0.0_r46用于指定具体的源码的版本
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-9.0.0_r46
# 同步源码,正常同步后即可获得完整目录
# 同步中提示无法连接到 gerrit.googlesource.com
# 需要修改~/bin/repo文件
# 找到REPO_URL,修改为https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
repo sync
# 遇到同步失败,可以将如下内容复制到shell脚本中(遇到错误,让循环同步源码)
repo s

本文详细介绍了在Ubuntu 22.04上配置环境、获取与编译AOSP源码的步骤,包括Repo和Git的安装,从清华源获取AOSP源码,解决Java和Python环境变量问题,以及编译过程中flex的错误。同时,讲解了如何生成idegen.jar和导入Android Studio进行源码开发。

398

被折叠的 条评论
为什么被折叠?



