Android系统源码的获取及其编译

AOSP(Android Open Source Project)是Google开放的Android 开源项目,中文官网为:https://source.android.google.cn/

AOSP就是一个Android系统源码项目,通过它可以定制 Android 操作系统,国内手机厂商都是在此基础上开发的定制系统。因为无法连接谷歌服务器获取AOSP源码,我们可以从清华大学镜像站获取。

下载 repo工具
Android源码包含数百个git库,光是下载这么多的git库就是一项繁重的任务,所以Google开发了repo,它是用于管理Android版本库的一个工具,使用了Python对git进行了一定的封装,简化了对多个Git版本库的管理。

#安装 Git
sudo apt-get install git

#创建bin,并加入到PATH中
mkdir ~/bin
PATH=~/bin:$PATH

#安装curl库
sudo apt-get install curl

#下载repo并设置权限
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo

#安装python,repo初始化时会用到
sudo apt-get install python

下载源码

#建立工作目录
mkdir aosp
cd aosp

#repo的运行过程中会尝试访问官方的git源更新自己,如果想使用tuna的镜像源进行更新
#在~/.bashrc文件加入
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

#设置邮箱和名字
git config --global user.email "piratemorgen@gmail.com"
git config --global user.name "piratemorgen"

#初始化仓库
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest

#初始化并指定版本
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-9.0.0_r8

#同步源码:
repo sync

如果需要某个特定的 Android 版本,版本列表:https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds

源码编译

#安装OpenJDK 8(参考 https://source.android.com/source/requirements.html)
sudo apt-get install openjdk-8-jdk

#安装依赖(参考 https://source.android.com/source/initializing.html)
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache
sudo apt-get install libssl-dev

#开始编译
source build/envsetup.sh
lunch 6
make -j16

#编译完成,运行Android虚拟机
emulator

编译环境初始化后可执行的命令

  - lunch
  - croot: Changes directory to the top of the tree.
  - m: Makes from the top of the tree.
  - mm: Builds all of the modules in the current directory.
  - mmm: Builds all of the modules in the supplied directories.
  - cgrep: Greps on all local C/C++ files.
  - jgrep: Greps on all local Java files.
  - resgrep: Greps on all local res/*.xml files.
  - godir: Go to the directory containing a file.

#模块编译
mmm packages/apps/Launcher2/

#重新打包系统镜像system.img
make snod

#SDK编译
make sdk

参考文章:
https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
https://blog.csdn.net/u013928208/article/details/89336157
https://zhuanlan.zhihu.com/p/59868777
Android源码编译环境搭建
Linux下载SDK最新教程
高通开源android源码下载

android源码编译
aosp基础
最全 下载AOSP android源码

换目录权限报错
https://juejin.cn/post/6844904153878118408

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值