Android Framwork从零上手(一)下载编译AOSP源码

Android Framwork从零上手(一)下载编译AOSP源码

Android 系统开发涉及的知识面很广,代码量大,复杂度高,相关的学习资料也非常匮乏。我也在努力学习,分享一些学习心得

什么是AOSP

AOSP,全称"Android Open Source Project",中文意为"Android 开放源代码项目"。发起者是谷歌,主要用途是移动设备的系统。

硬件要求

用于 Android Framework 开发的电脑需要较强的 CPU,大内存,大存储,一般来说需要满足以下要求:

  • CPU 不低于 6 核心,建议 8 核及以上
  • 内存不低于 32G,建议 64G
  • 存储空间不低于 500G,建议 1TB SSD

虚拟机安装

ubuntu国内镜像地址大全
安装过程可以参考这篇文章

开发环境搭建

安装好系统后需要安装必要的软件:

powershell 复制代码
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig python

下载编译源码

下载 repo 工具

powershell 复制代码
mkdir ~/bin
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o ~/bin/repo
chmod +x ~/bin/repo

repo 的运行过程中会尝试访问官方的 git 源更新自己,如果想使用 tuna 的镜像源进行更新,可以将如下内容复制到你的 ~/.bashrc 或者 ~/.zshrc 里。

powershell 复制代码
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
PATH=~/bin:$PATH

然后 source 一下:

powershell 复制代码
source ~/.bashrc
#如果使用的是 zsh
#source ~/.zshrc

初始化仓库并同步远程代码

powershell 复制代码
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
mkdir aosp 
cd aosp
#初始化仓库,-b 指示分支,这里使用 android10
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-10.0.0_r41
#同步远程代码
repo sync

-b 后面的值参考 源代码标记和 build。这里选用了 android-10.0.0_r41 版本用于学习。Android 每年都会更新一个大版本,学习的角度来说,选择一个不太老的版本即可,不必追新。

这里可能会遇到类型 SyntaxError: invalid syntax 'python': No such file or directory 等错误,这是 repo 和 Python 版本不一致导致的,我们可以用如下方式解决:

powershell 复制代码
# 安装 python3
sudo apt install python3
# 下载最新的 repo
curl https://storage.googleapis.com/git-repo-downloads/repo-1 > ~/bin/repo
chmod a+x ~/bin/repo
# 使用 python3 执行 repo
python3 ~/bin/repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-10.0.0_r41

还有一种比较简单的方法,直接建立软链接:

powershell 复制代码
# 安装 python3
sudo apt install python3
sudo apt install python-is-python3

# # 建立软链接
# sudo ln -s /usr/bin/python3.6 /usr/bin/python

编译源码

powershell 复制代码
source build/envsetup.sh
# 如果是 Android13
# lunch sdk_phone_x86_64
lunch aosp_x86_64-eng
make -j16

运行模拟器

powershell 复制代码
emulator -verbose -cores 4 -show-kernel
相关推荐
秋饼17 小时前
[EXPLAIN:SQL 执行计划分析与性能优化实战]
android·sql·性能优化
WangUnionpub17 小时前
别只盯着MDPI,又贵还卡单位,平替SCI/EI,免收版面费,这本15天录用!
大数据·人工智能·深度学习·物联网·计算机视觉
热点速递17 小时前
AI招聘重构人才入口:用友大易以大模型驱动全流程智能升级!
大数据·人工智能·重构·业界资讯
大报言看17 小时前
当AI进入“工程时代”,开发者开始重新思考大模型的接入方式
大数据·人工智能
方向研究17 小时前
低密度聚乙烯生产
大数据
山峰哥17 小时前
SQL优化全攻略:从索引策略到Explain实战解析
大数据·数据库·sql·oracle·性能优化·编辑器
培***事17 小时前
大数据技术专业必考证书清单?适合大专生报考
大数据
白宇横流学长17 小时前
Elasticsearch集群搭建
大数据·elasticsearch·搜索引擎
robotx17 小时前
如何从framework层面跳过app开屏广告(简单模拟)
android
GEO_Huang17 小时前
工作流定制选数谷,Agentoffice 让办公快人一步
大数据·人工智能·aigc·rpa·geo