Android --- AOSP下载及编译
AOSP下载
Step1. 使用清华开源镜像库下载:
AOSP | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
Step2. repo 工具
mkdir ~/binPATH=~/bin:$PATHcurl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repochmod a+x ~/bin/rep
Step3. 初始化
mkdir WORKING_DIRECTORYcd WORKING_DIRECTORY
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-15.0.0_
这里采用的是android-15.0.0_r14,它来自Android官网:
代号、标记和 build 号 | Android Open Source Project
repo sync -c --no-tags
只同步当前分支的代码,不下载 Git 标签。
AOSP编译
下载完成后,终端执行
source build/envsetup.sh
lunch
lunch后发现menu消失了,而且构建目标的格式也发生了
构建 Android | Android Open Source Project
lunch product_name-release_config-build_variant
为什么 menu 消失了?
分析build/envsetup.sh
function print_lunch_menu(){local uname=$(uname)local choiceschoices=$(TARGET_BUILD_APPS= TARGET_PRODUCT= TARGET_RELEASE=
TARGET_BUILD_VARIANT= _get_build_var_cached COMMON_LUNCH_CHOICES
2>/dev/null)local ret=$?echoecho "You're building on" $unameechoif [ $ret -ne 0 ]thenecho "Warning: Cannot display lunch menu."echoecho "Note: You can invoke lunch with an explicit target:"echoecho " usage: lunch [target]" >&2echoreturnfiecho "Lunch menu .. Here are the common combinations:"local i=1local choicefor choice in $(echo $choices)doecho " $i. $choice"i=$(($i+1))doneecho}
Warning输出的函数是print_lunch_menu(),它输出Warning的逻辑是:
① 通过 _get_build_var_cached 获取 COMMON_LUNCH_CHOICES 环境变量的值
② 如果获取失败,ret 会是非零值
③ 如果 _get_build_var_cached 返回非零值,表示无法获取 COMMON_LUNCH_CHOICES,此时会输出: Warning: Cannot display lunch menu
④ 如果成功获取 COMMON_LUNCH_CHOICES,会将其逐行打印,格式为: Lunch menu .. Here are the common combinations: 1. 2. ...
OK。关键函数是_get_build_var_cached。 因为这个函数就是处于envsetup.sh中,我们在source build/envsetup.sh后直接执行这个函数
我们可以看到缺少对于TARGET_RELEASE的定义,它的定义是和构建目标名的 release_config对应的。因此我们需要声明TARGET_RELEASE后,才可以获取所有可 以lunch的目标menu。这个release_config该如何选择,我们做个测试:
这里我随意声明了一个叫做test,然后去获取menu,从报错我们可以看到。AOSP默认 支持的release_config只有如下: aosp_current ap2a ap3a ap4a root trunk_staging. 我们这里采用trunk_staging,trunk_staging 是一种开发版本配置,Google 会在正式发 布之前使用它来测试功能。 所以设置trunk_staging后,menu结果如下:
对于以前的版本,我们例如要编译运行模拟器的时候,我们会选择
lunch sdk_phone_x86_64
(Android 12之后的版本,我们在lunch列表里并没有看到sdk_phone_x86_64,但是仍可 以lunch成功
为什么没有在列表中:因为没有添加到COMMON_LUNCH_CHOICES中
为什么可以lunch:因为PRODUCT_MAKEFILES存在该目标的mk文件)
我们按照提示配置上 - 发现并没有sdk_phone_x86_64这个 product
经调查,是由于sdk_phone的product被删除,全部替换成了sdk_phone64,它们被放置 在了/device/generic/goldfish目录下
aosp_15.0.0_r14/build/make/target/product/AndroidProducts.mk
aosp_15.0.0_r14/device/generic/goldfish/AndroidProducts.mk
因此我们应该使用
lunch sdk_phone64_x86_64-trunk_staging-eng
然后
make
待make结束后,我们执行
emulator
模拟器便启动成功~