如何获取 AOSP 中部分代码?

54 阅读1分钟

获取 AOSP 仅做阅读使用的方式

  • 处理器性能差,编译耗时太久,不做编译使用。
  • 磁盘空间不足,无法获取完整代码。
  • 只想翻看某个模块源码。

clone manifest

git clone https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest

查看 default.xml

cat manifest/default.xml

获取想要了解的项目的 Git 仓库地址。

比如阅读 Launcher3 源码

在 default.xml 文件中搜索 Launcher3

找到如下内容

<project path="packages/apps/Launcher3" name="platform/packages/apps/Launcher3" groups="pdk-fs,sysui-studio,pdk-cw-tvc" />

按照如下结构拼装出仓库地址。

mirrors.tuna.tsinghua.edu.cn/git/AOSP/ + name path

将项目 clone 到指定位置。

git clone https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/packages/apps/Launcher3 packages/apps/Launcher3

再比如查看 SurfaceFlinger 源码?

但是在 default.xml 文件中搜索不到。

可通过网上查找其在 AOSP 中的位置。

即 frameworks/native 目录下。

搜索 frameworks/native 后找到如下内容:

<project path="frameworks/native" name="platform/frameworks/native" groups="pdk" />

按照同样的拼接方式,将项目 clone 到指定位置。

git clone https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/frameworks/native frameworks/native

clone 后就可以在本地翻看源码了,同时支持随意 checkout 到不同的 Android 版本。