Android13源码下载和编译过程详解

前言

作为Android开发者人人都应该有一份自己Android源码,这样我们就可以随时对自己有疑惑的地方通过亲手调试来加强理解

一 源码下载

1.1 配置要求

官方推荐配置请参考:AOSP使用入门文档,重点有如下几项:

1.1.1 硬件配置要求

  1. 至少需要 250 GB 可用磁盘空间;如果要进行构建,则还需要 150 GB。如果要进行多次构建,则需要更多空间。
  2. 磁盘至少 250GB,实测建议至少 512G。

1.1.2 软件要求

推荐使用 Ubuntu 18.04 (Bionic Beaver)、 Docker、Linux。
2021年6月22日起,不再支持 Windows 或 MacOS 上构建。
2020年1月1日起,不再支持 python2,请使用 python3。

1.2 下载环境搭建

1.2.1 依赖安装

请使用如下命令安装相关依赖:

sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

执行结果如下

longzhiye@longzhiye-laptop:~$ sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
......
升级了 0 个软件包,新安装了 114 个软件包,要卸载 0 个软件包,有 5 个软件包未被升级。
需要下载 58.6 MB 的归档。
解压缩后会消耗 262 MB 的额外空间。
您希望继续执行吗? [Y/n] y
......
python3 已经是最新版 (3.6.7-1~18.04)。
python3 已设置为手动安装。
下列软件包是自动安装的并且现在不需要了:gir1.2-goa-1.0 gir1.2-snapd-1
使用'sudo apt autoremove'来卸载它(它们)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 5 个软件包未被升级。

1.2.2 git配置

请使用如下命令对git进行配置:

git config --global user.name 'xxx'
git config --global user.email 'xxx@xxx.com'

执行结果如下

longzhiye@longzhiye-laptop:~$ git config --global user.name 'longzhiye' 
longzhiye@longzhiye-laptop:~$ git config --global user.email 'longzhiye163@163.com'

1.2.3 repo配置

由于某墙的原因,这里我们采用国内的镜像源进行下载.
目前,可用的镜像源一般是科大和清华的,具体使用差不多,这里我选择清华大学镜像进行说明.(参考:科大源,清华源),请使用如下命令更新repo并进行配置:

mkdir ~/bin
PATH=~/bin:$PATH
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod +x ~/bin/repo

执行结果如下

longzhiye@longzhiye-laptop:~$ mkdir ~/bin
longzhiye@longzhiye-laptop:~$ PATH=~/bin:$PATH
longzhiye@longzhiye-laptop:~$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100 45805  100 45805    0     0   117k      0 --:--:-- --:--:-- --:--:--  117k
longzhiye@longzhiye-laptop:~$ chmod +x ~/bin/repo

1.3 源码下载

1.3.1 明确下载版本

请通过浏览器访问:分支列表,来选取需要的版本。
网页显示如下:

1.3.2 替换为清华源

请使用如下命令将源替换为清华源:

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

执行结果如下

longzhiye@longzhiye-laptop:~$ export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

1.3.3 初始化仓库并指定分支

请使用如下命令初始化仓库并指定分支,此处以android-13.0.0_r40分支为例。

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-13.0.0_r40

执行结果如下:

longzhiye@longzhiye-laptop:~/mount/project$ mkdir androidt    // 建立下载位置
longzhiye@longzhiye-laptop:~/mount/project$ cd androidt/
longzhiye@longzhiye-laptop:~/mount/project/androidt$ repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-13.0.0_r40
Downloading Repo source from https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/
remote: Enumerating objects: 4495, done.
remote: Counting objects: 100% (4495/4495), done.
remote: Compressing objects: 100% (2144/2144), done.
remote: Total 8060 (delta 3993), reused 2351 (delta 2351), pack-reused 3565
接收对象中: 100% (8060/8060), 3.81 MiB | 1016.00 KiB/s, 完成.
处理 delta 中: 100% (5177/5177), 完成.
repo: Updating release signing keys to keyset ver 2.3Your identity is: longzhiye <longzhiye163@163.com>
If you want to change this, please re-run 'repo init' with --config-nameTesting colorized output (for 'repo diff', 'repo status'):black    red      green    yellow   blue     magenta   cyan     white bold     dim      ul       reverse 
Enable color display in this user account (y/N)? yrepo has been initialized in /home/longzhiye/mount/project/androidt
longzhiye@longzhiye-laptop:~/mount/project/androidt$ ls -al
总用量 12
drwxrwxr-x 3 longzhiye longzhiye 4096 5月  20 00:48 .
drwxrwxrwx 3 root      root      4096 5月  20 00:44 ..
drwxrwxr-x 5 longzhiye longzhiye 4096 5月  20 00:48 .repo

1.3.4 同步全部源码

初始化仓库之后,就可以开始正式同步代码到本地了,命令如下:

repo sync -c -j8

此处为了加快速度使用了-c参数,表示只同步当前分支,-j8表示使用8个线程今天同步代码,使用多少个线程请根据自己的机器配置自行修改。
(提示:一定要确定代码完全同步了,不然在下面编译过程出现的错误会让你痛不欲生,不确定的童鞋可以多用repo sync同步几次)

执行结果如下:

longzhiye@longzhiye-laptop:~/mount/project/androidt$ repo sync -c -j8
Fetching: 100% (1135/1135), done in 4h51m48.506s
正在检出文件: 100% (1972/1972), 完成.
正在检出文件: 100% (1787/1787), 完成.
......
正在检出文件: 100% (724/724), 完成.orm/system/keymaster正在检出文件:  73% (534/724)   
Checking out: 100% (1135/1135), done in 44m21.860s
repo sync has finished successfully.

源码同步时间比较长,此时Android13源码已经同步完成。

二 Android源码编译

2.1 编译环境搭建

使用如下命令安装JDK:

sudo apt-get install openjdk-11-jdk

安装完成后可以使用如下命令查看是否按照成功:

longzhiye@longzhiye-laptop:javac -version
javac 11.0.17

2.2 全编译

2.2.1 初始化编译环境

执行如下命令进行编译环境初始化:

source build/envsetup.sh
或者:
. build/envsetup.sh

执行结果如下:

longzhiye@longzhiye-laptop:~/mount/project/androidt$ source build/envsetup.sh

2.2.2 选择构建目标

执行lunch命令执行结果如下:

longzhiye@longzhiye-laptop:~/mount/project/androidt$ lunchYou're building on LinuxLunch menu .. Here are the common combinations:1. aosp_arm-eng2. aosp_arm64-eng3. aosp_barbet-userdebug4. aosp_bluejay-userdebug5. aosp_bluejay_car-userdebug6. aosp_bramble-userdebug7. aosp_bramble_car-userdebug8. aosp_car_arm-userdebug9. aosp_car_arm64-userdebug10. aosp_car_x86-userdebug11. aosp_car_x86_64-userdebug12. aosp_cf_arm64_auto-userdebug13. aosp_cf_arm64_phone-userdebug14. aosp_cf_x86_64_foldable-userdebug15. aosp_cf_x86_64_pc-userdebug16. aosp_cf_x86_64_phone-userdebug17. aosp_cf_x86_64_tv-userdebug18. aosp_cf_x86_auto-userdebug19. aosp_cf_x86_phone-userdebug20. aosp_cf_x86_tv-userdebug21. aosp_cheetah-userdebug22. aosp_cloudripper-userdebug23. aosp_coral-userdebug24. aosp_coral_car-userdebug25. aosp_flame-userdebug26. aosp_flame_car-userdebug27. aosp_oriole-userdebug28. aosp_oriole_car-userdebug29. aosp_panther-userdebug30. aosp_raven-userdebug31. aosp_raven_car-userdebug32. aosp_ravenclaw-userdebug33. aosp_redfin-userdebug34. aosp_redfin_car-userdebug35. aosp_redfin_vf-userdebug36. aosp_slider-userdebug37. aosp_sunfish-userdebug38. aosp_sunfish_car-userdebug39. aosp_trout_arm64-userdebug40. aosp_trout_x86-userdebug41. aosp_whitefin-userdebug42. aosp_x86-eng43. aosp_x86_64-eng44. arm_krait-eng45. arm_v7_v8-eng46. armv8-eng47. armv8_cortex_a55-eng48. armv8_kryo385-eng49. beagle_x15-userdebug50. beagle_x15_auto-userdebug51. car_ui_portrait-userdebug52. car_x86_64-userdebug53. db845c-userdebug54. gsi_car_arm64-userdebug55. gsi_car_x86_64-userdebug56. hikey-userdebug57. hikey64_only-userdebug58. hikey960-userdebug59. hikey960_tv-userdebug60. hikey_tv-userdebug61. poplar-eng62. poplar-user63. poplar-userdebug64. qemu_trusty_arm64-userdebug65. rb5-userdebug66. sdk_car_arm-userdebug67. sdk_car_arm64-userdebug68. sdk_car_portrait_x86_64-userdebug69. sdk_car_x86-userdebug70. sdk_car_x86_64-userdebug71. sdk_pc_x86_64-userdebug72. silvermont-eng73. uml-userdebug74. yukawa-userdebug75. yukawa_sei510-userdebugWhich would you like? [aosp_arm-eng]
Pick from common choices above (e.g. 13) or specify your own (e.g. aosp_barbet-eng): aosp_arm64-engHint: next time you can simply run 'lunch aosp_arm64-eng'============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=13
TARGET_PRODUCT=aosp_arm64
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.4.0-148-generic-x86_64-Ubuntu-18.04.6-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=TQ2A.230405.003.B2
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera
============================================

中间会有选择需要构建的目标,此处以aosp_arm64-eng为例

2.2.3 编译固件

通过make指令进行代码编译,该指令通过-j参数来设置参与编译的线程数量,以提高编译速度.比如这里我们设置8个线程同时编译。需要注意的是,参与编译的线程并不是越多越好,通常是根据你机器cup的核心来确定:core*2,即当前cpu的核心的2倍.比如,我现在的笔记本是双核四线程的,因此根据公式,最快速的编译可以make -j8.
(通过cat /proc/cpuinfo查看相关cpu信息)

make -j8

执行结果如下:

longzhiye@longzhiye-laptop:~/mount/project/androidt$ make -j8
07:04:26 ************************************************************
07:04:26 You are building on a machine with 15.5GB of RAM
07:04:26 
07:04:26 The minimum required amount of free memory is around 16GB,
07:04:26 and even with that, some configurations may not work.
07:04:26 
07:04:26 If you run into segfaults or other errors, try reducing your
07:04:26 -j value.
07:04:26 ************************************************************
build/make/core/soong_config.mk:209: warning: BOARD_PLAT_PUBLIC_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS instead.
build/make/core/soong_config.mk:210: warning: BOARD_PLAT_PRIVATE_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS instead.
============================================
PLATFORM_VERSION_CODENAME=REL
......
[ 99% 120038/120059] //frameworks/base/packages/SystemUI:SystemUI-core javac
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
[ 99% 120044/120059] //frameworks/base/packages/SystemUI:SystemUI r8
Warning: Missing class android.compat.annotation.UnsupportedAppUsage (referenced from: void com.android.systemui.people.widget.PeopleBackupHelper.writeNewStateDescription(android.os.ParcelFileDescriptor))
[100% 120059/120059] Target vbmeta image: out/target/product/generic/vbmeta.img#### build completed successfully (05:56:23 (hh:mm:ss)) ####

如果一切顺利的化,在几个小时之后,便可以编译完成.看到### make completed successfully (00:48:15(hh:mm:ss)) ###表示你编译成功了.。Google 使用 72 核机器,内置 RAM 为 64 GB,完整构建过程大约需要 40 分钟(增量构建只需几分钟时间,具体取决于修改了哪些文件)。相比之下,RAM 数量相近的 6 核机器执行完整构建过程需要 3 个小时。

二 运行模拟器

在编译完成之后,就可以通过以下命令运行Android虚拟机了,命令如下:

source build/envsetup.sh
lunch   // 选择刚才你设置的目标版本,比如这里了我选择的是2
emulator

执行结果如下:

longzhiye@longzhiye-laptop:~/mount/project/androidt$ source build/envsetup.sh
longzhiye@longzhiye-laptop:~/mount/project/androidt$ lunch
longzhiye@longzhiye-laptop:~/mount/project/androidt$ emulator

不出意外,在等待一会之后,你会看到运行界面

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/68452.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux之详谈——权限管理

目录 小 峰 编 程 ​编辑 一、权限概述 1、什么是权限 2、为什么要设置权限 3、Linux中的权限类别- 4、Linux中文件所有者 1&#xff09;所有者分类&#xff08;谁&#xff09; 2&#xff09;所有者的表示方法 ① u(the user who owns it)&#xff08;属主权限&…

python Flask-Redis 连接远程redis

当使用Flask-Redis连接远程Redis时&#xff0c;首先需要安装Flask-Redis库。可以通过以下命令进行安装&#xff1a; pip install Flask-Redis然后&#xff0c;你可以使用以下示例代码连接远程Redis&#xff1a; from flask import Flask from flask_redis import FlaskRedisa…

Go Fx 框架使用指南:深入理解 Provide 和 Invoke 的区别

1. 什么是 Fx 框架&#xff1f; Fx 是一个基于 Go 语言的依赖注入框架&#xff0c;专注于简化应用程序的生命周期管理和依赖的构建。在复杂的应用程序中&#xff0c;Fx 通过模块化的设计方式将组件连接起来&#xff0c;使开发者能够更高效地管理依赖关系。 Fx 的核心理念是&a…

基于金融新闻的大型语言模型强化学习在投资组合管理中的应用

“Financial News-Driven LLM Reinforcement Learning for Portfolio Management” 论文地址&#xff1a;https://arxiv.org/pdf/2411.11059 摘要 本研究探索了如何通过将大语言模型&#xff08;LLM&#xff09;支持的情感分析融入强化学习&#xff08;RL&#xff09;中&#…

K8s运维管理平台 - KubeSphere 3.x 和4.x 使用分析:功能较强,UI美观

目录标题 Lic使用感受优点&#xff1a;优化点&#xff1a; 实操首页项目 | 应用负载 | 配置 | 定制资源定义存储监控告警集群设置 **KubeSphere 3.x** 和 **4.x**1. **架构变化**&#xff1a;2. **多集群管理**&#xff1a;3. **增强的 DevOps 功能**&#xff1a;4. **监控与日…

当AI学会“顿悟”:DeepSeek-R1如何用强化学习突破推理边界?

开篇&#xff1a;一场AI的“青春期叛逆” 你有没有想过&#xff0c;AI模型在学会“推理”之前&#xff0c;可能也经历过一段“中二时期”&#xff1f;比如&#xff0c;解题时乱写一通、语言混搭、答案藏在火星文里……最近&#xff0c;一支名为DeepSeek-AI的团队&#xff0c;就…

【llm对话系统】 LLM 大模型推理python实现:vLLM 框架

在 LLM 的应用中&#xff0c;推理 (Inference) 阶段至关重要。它指的是利用训练好的 LLM 模型&#xff0c;根据输入 (Prompt) 生成文本的过程。然而&#xff0c;LLM 的推理速度往往较慢&#xff0c;尤其是在处理长序列或高并发请求时&#xff0c;效率瓶颈尤为突出。 为了解决这…

Ollama+DeepSeek本地大模型部署

1、Ollama 官网&#xff1a;https://ollama.com/ Ollama可以干什么&#xff1f; 可以快速在本地部署和管理各种大语言模型&#xff0c;操作命令和dokcer类似。 mac安装ollama&#xff1a; # 安装ollama brew install ollama# 启动ollama服务&#xff08;默认11434端口&#xf…

论文笔记(六十三)Understanding Diffusion Models: A Unified Perspective(三)

Understanding Diffusion Models: A Unified Perspective&#xff08;三&#xff09; 文章概括 文章概括 引用&#xff1a; article{luo2022understanding,title{Understanding diffusion models: A unified perspective},author{Luo, Calvin},journal{arXiv preprint arXiv:…

mybatis(104/134)

动态sql标签&#xff0c;用于选择查询 if标签 where标签 &#xff1a;自动生成where&#xff0c;取决于后面有没有条件&#xff0c;会自动去除条件前面的and和or&#xff0c;不会去除语句后面的 trim标签&#xff1a;自动生成where&#xff0c;在语句后自动去除后缀and和or for…

【数据结构】动态内存管理函数

动态内存管理 为什么存在动态内存管理动态内存函数的介绍&#x1f38a;malloc补充&#xff1a;perror函数&#x1f38a;free&#x1f38a;calloc&#x1f38a;realloc 常见动态内存错误对空指针的解引用操作对动态开辟空间的越界访问对非动态开辟内存使用free释放使用free释放一…

在FreeBSD下安装Ollama并体验DeepSeek r1大模型

在FreeBSD下安装Ollama并体验DeepSeek r1大模型 在FreeBSD下安装Ollama 直接使用pkg安装即可&#xff1a; sudo pkg install ollama 安装完成后&#xff0c;提示&#xff1a; You installed ollama: the AI model runner. To run ollama, plese open 2 terminals. 1. In t…

C++类和对象下详细指南

C类和对象下详细指南 1. 初始化列表与构造函数 1.1 初始化列表概述 初始化列表在C中用于初始化对象的成员变量&#xff0c;特别是当你需要在对象构造时就明确成员变量的值时。通过初始化列表&#xff0c;成员变量的初始化可以在进入构造函数体之前完成。这不仅可以提升性能&…

文档智能扫描,提升无纸化办公效率

随着无纸化办公的推广和移动设备的普及&#xff0c;用户迫切需要将纸质文档快速、准确地转换成电子格式&#xff0c;以提高工作效率和信息管理的便捷性。同时&#xff0c;用户将文档扫描成电子版后&#xff0c;可以自行通过加密和访问控制提高电子文档的安全性&#xff0c;以满…

汇编的使用总结

一、汇编的组成 1、汇编指令&#xff08;指令集&#xff09; 数据处理指令: 数据搬移指令 数据移位指令 位运算指令 算术运算指令 比较指令 跳转指令 内存读写指令 状态寄存器传送指令 异常产生指令等 2、伪指令 不是汇编指令&#xff0c;但是可以起到指令的作用&#xff0c;伪…

【玩转全栈】----Django模板的继承

先赞后看&#xff0c;养成习惯&#xff01;&#xff01;&#xff01; 目录 模板继承的好处 模板继承的语法规则 更新代码 上文中的部门管理页面&#xff1a; 【玩转全栈】----Django制作部门管理页面-CSDN博客 大家会发现&#xff0c;由于定义了多个html文件&#xff0c;多个ht…

nosql mysql的区别

NoSQL 和 MySQL 是两种不同类型的数据库管理系统&#xff0c;它们在设计理念、数据模型、可扩展性和应用场景等方面有着本质的区别。 NoSQL 数据库 特点: 灵活的数据模型: NoSQL 数据库通常没有固定的表结构&#xff0c;可以很容易地存储不同结构的文档或键值对。水平扩展: …

python实现dbscan

python实现dbscan 原理 DBSCAN(Density-Based Spatial Clustering of Applications with Noise)是一个比较有代表性的基于密度的聚类算法。它将簇定义为密度相连的点的最大集合&#xff0c;能够把具有足够高密度的区域划分为簇&#xff0c;并可在噪声的空间数据库中发现任意形…

Lustre Core 语法 - 比较表达式

概述 Lustre v6 中的 Lustre Core 部分支持的表达式种类中&#xff0c;支持比较表达式。相关的表达式包括 , <>, <, >, <, >。 相应的文法定义为 Expression :: Expression Expression | Expression <> Expression | Expression < Expression |…

gesp(C++六级)(4)洛谷:B3874:[GESP202309 六级] 小杨的握手问题

gesp(C六级)&#xff08;4&#xff09;洛谷&#xff1a;B3874&#xff1a;[GESP202309 六级] 小杨的握手问题 题目描述 小杨的班级里共有 N N N 名同学&#xff0c;学号从 0 0 0 至 N − 1 N-1 N−1。 某节课上&#xff0c;老师安排全班同学进行一次握手游戏&#xff0c;具…