前言
Linux 环境:
- 安装Ubuntu(或VM虚拟机安装)
- win10开启内置Ubuntu
现在WIN10内置Ubuntu方便使用
AOSP
AOSP(Android Open Source Project)是Google开放的Android 开源项目,中文官网为:https://source.android.google.cn/
国内获取AOSP源镜像源:清华大学镜像站、中科大镜像
AOSP Google 官方教程下载 https://source.android.com/source/downloading.html
网站直接查看代码:
http://androidxref.com/也可访问 https://cs.android.com 或 https://github.com/aosp-mirror 在线搜索及浏览 AOSP 源码。- AOSPXRef
AOSP | 镜像站使用帮助 | 清华大学开源软件镜像站
按照“镜像站使用帮助”说明就可以了
需要注意:
1、Ubuntu更换国内源
#先备份原来的源列表文件
mv /etc/apt/sources.list /etc/apt/sourses.list.backup
#新建源列表文件
vim /etc/apt/sources.list#加入源地址(推荐用阿里云源)
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
#更新软件列表
sudo apt-get update
#更新软件(把已安装的软件与刚刷新的软件列表中的版本进行对比,如果发现已安装的软件版本太低,就会提示更新)
sudo apt-get upgrade
2、下载 git、repo工具sudo apt-get install git
mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo
3、配置gitconfig
git config --global user.email xhbruce@foxmail.com
git config --global user.name xhbrucexuhun@Bruce-xu:/mnt/d/AOSP/android-10.0.0_r36/frameworks/base$ git config --global --list core.filemode=false core.autocrlf=true user.email=xbruce@foxmail.com user.name=xbruce
4、可下载android-10.0.0_r36
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-10.0.0_r36
5、替换已有的 AOSP 源代码的 remote
如果你之前已经通过某种途径获得了 AOSP 的源码(或者你只是 init 这一步完成后), 你希望以后通过 TUNA 同步 AOSP 部分的代码,只需要将 .repo/manifest.xml 把其中的 aosp 这个 remote 的 fetch 从 https://android.googlesource.com 改为 https://mirrors.tuna.tsinghua.edu.cn/git/AOSP。<manifest> <remote name="aosp" - fetch="https://android.googlesource.com" + fetch="https://mirrors.tuna.tsinghua.edu.cn/git/AOSP" review="android-review.googlesource.com" /> <remote name="github"
同时,修改 .repo/manifests.git/config,将
url = https://android.googlesource.com/platform/manifest
更改为
url = https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
推荐使用单仓下载
对绝大多数人查看Android源码不会涉及全部代码,一般需要platform/frameworks/base 和 platform/frameworks/native
初始化仓库:
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
下载单仓platform/frameworks/base 和 platform/frameworks/native:
repo sync platform/frameworks/base
repo sync platform/frameworks/native
参看对应分支
git branch -a
git branch -a |grep android11-
切换到对应分支,如remotes/aosp/android11-release
git checkout -b android11-release remotes/aosp/android11-release