Ubantu 20.04 下 AOSP源码构建(二)

549 阅读1分钟

一起养成写作习惯!这是我参与「掘金日新计划 · 4 月更文挑战」的第2天,点击查看活动详情

前言

开发的时候有些源码as是无法查看的,用android code search又少了点感觉,所以就打算下载源码编译。当然,还可以借此机会,深入了解Android底层原理和实现。以下便是AOSP源码编译过程的相关笔记,不正确的地方还望指正。

编译AOSP源码

设置缓存

prebuilts/misc/linux-x86/ccache/ccache -M 50G  

清空目录 编译前删除build文件夹

make -j8 clobber 

Jack server 配置

export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx6g"
./prebuilts/sdk/tools/jack-admin kill-server
./prebuilts/sdk/tools/jack-admin start-server 

配置环境

  1. 加载编译时需要的相应命令,如:help,lunch ,m,mm等。
  2. 添加系统默认编译项。
  3. 查找vendorsetup.sh文件,加载自定义编译项。
source build/envsetup.sh

后续步骤

# 选择执行虚拟机
lunch

# 编译文件,时间较长
make -j8

成功现象

#### build completed successfully (56:30 (mm:ss)) ####

报错1

日志
35 warnings generated.
[  1% 1196/66978] Lex: applypatch <= bootable/recovery/edify/lexer.ll
FAILED: out/target/product/generic/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp 
/bin/bash -c "prebuilts/misc/linux-x86/flex/flex-2.5.39 -oout/target/product/generic/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp bootable/recovery/edify/lexer.ll"
flex-2.5.39: loadlocale.c:130:_nl_intern_locale_data: ?? 'cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' ???
Aborted (core dumped)
[  1% 1203/66978] target thumb C++: libapplypatch <= bootable/recovery/applypatch/applypatch.cpp
ninja: build stopped: subcommand failed.
12:28:33 ninja failed with: exit status 1

#### failed to build some targets (05:07 (mm:ss)) ####
解决方案
export LC_ALL=C

生成ipr文件

整编步骤:

  1. source build/envsetup.sh 或 . build/envsetup.sh
  2. make idegen
  3. development/tools/idegen/idegen.sh

单编步骤:

假设单独编译setting应用模块,编译成功后会有提示生成文件的存放路径。

  1. source build/envsetup.sh 或 . build/envsetup.sh
  2. lunch
  3. cd packages/apps/Settings
  4. mm
  5. make snod 或 make -j8 顺序暂时没有研究出

其他命令

mmm:编译指定目录下的模块,不编译它所依赖的其它模块。 mma:编译当前目录下的模块及其依赖项。 mmma:编译指定路径下所有模块,并且包含依赖。

成功现象

find: 'out/target/product/generic/root/d': Permission denied
Read excludes: 2ms
Traversed tree: 16765ms

导入AS

配置AS的项目配置文件

但是源码的体积很大,如果全部导入会比较卡,我们可以排除一些代码。例如我只想查看framework里的代码,我们可以在android.iml了添加以下内容。

<excludeFolder url="file://$MODULE_DIR$/.repo" />
<excludeFolder url="file://$MODULE_DIR$/abi" />
<excludeFolder url="file://$MODULE_DIR$/art" />
<excludeFolder url="file://$MODULE_DIR$/bionic" />
<excludeFolder url="file://$MODULE_DIR$/bootable" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/cts" />
<excludeFolder url="file://$MODULE_DIR$/dalvik" />
<excludeFolder url="file://$MODULE_DIR$/developers" />
<excludeFolder url="file://$MODULE_DIR$/development" />
<excludeFolder url="file://$MODULE_DIR$/device" />
<excludeFolder url="file://$MODULE_DIR$/docs" />
<excludeFolder url="file://$MODULE_DIR$/external" />
<excludeFolder url="file://$MODULE_DIR$/hardware" />
<excludeFolder url="file://$MODULE_DIR$/libcore" />
<excludeFolder url="file://$MODULE_DIR$/libnativehelper" />
<excludeFolder url="file://$MODULE_DIR$/ndk" />
<excludeFolder url="file://$MODULE_DIR$/out" />
<excludeFolder url="file://$MODULE_DIR$/packages" />
<excludeFolder url="file://$MODULE_DIR$/pdk" />
<excludeFolder url="file://$MODULE_DIR$/prebuilt" />
<excludeFolder url="file://$MODULE_DIR$/prebuilts" />
<excludeFolder url="file://$MODULE_DIR$/sdk" />
<excludeFolder url="file://$MODULE_DIR$/system" />
<excludeFolder url="file://$MODULE_DIR$/tools" />

总结

以上便是我AOSP源码构建的全过程。