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 "[email protected]"
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
相关推荐
Aric1 小时前
conan cross build for Android with NDK toolchain
android
viperrrrrrrrrr72 小时前
大数据学习(100)-kafka详解
大数据·学习·kafka
小吕学编程2 小时前
企业级开发SpringBoost玩转Elasticsearch
大数据·spring boot·elasticsearch·搜索引擎
菜只因C3 小时前
深入剖析嵌入式系统:从基础到实践的全面指南
大数据·网络·人工智能
Jayin_chan3 小时前
elasticsearch索引数据备份与恢复
大数据·elasticsearch·搜索引擎
喝醉酒的小白3 小时前
ES:geoip_databases
elasticsearch
哔哩哔哩技术3 小时前
Hologres实时数仓在B站游戏的建设与实践
大数据
namisoft1234 小时前
电源测试系统自动化转型:Chroma 8000 与 NSAT-8000 核心功能对比解析
大数据·自动化·电源测试系统·chroma8000
背影疾风4 小时前
Git版本管理系列:(一)使用Git管理单分支
大数据·开发语言·c++·git·学习·elasticsearch
IT成长日记4 小时前
【Hadoop入门】Hadoop生态圈概述:核心组件与应用场景概述
大数据·hadoop·分布式