参考文档:

https://wiki.lineageos.org/devices/panther/build/

https://mirrors.tuna.tsinghua.edu.cn/help/lineageOS/

https://www.cnblogs.com/melona/p/22016019

https://www.cnblogs.com/hdykt/p/18764630

源码下载:

下载 repo 工具

https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/

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

添加环境变量

# 使用 vim 编辑 .bashrc
vim ~/.bashrc
# 加入以下内容并保存
export PATH="$HOME/bin:$PATH"
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
# 使环境变量生效
source ~/.bashrc

配置 Git 环境

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git lfs install
git config --global trailer.changeid.key "Change-Id"

启用缓存功能,加快构建速度

# 可以自行选择添加到环境变量中(~/.bashrc)
export USE_CCACHE=1
export CCACHE_EXEC=/usr/bin/ccache

# 指定ccache使用的磁盘空间上限
ccache -M 50G

初始化仓库

# 创建源码目录并进入
mkdir -p ~/android/lineage
cd ~/android/lineage
# 初始化仓库
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b lineage-23.2 --git-lfs --no-clone-bundle

修改为清华镜像

打开.repo/manifests/default.xml,将

  <remote  name="github"
           fetch=".."
           review="review.lineageos.org" />

改成

  <remote  name="github"
           fetch="https://github.com/" />

  <remote  name="lineage"
           fetch="https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/"
           review="review.lineageos.org" />

  <remote  name="aosp"
           fetch="https://android.googlesource.com"

改成(注意只是 fetch 部分的链接修改了)

  <remote  name="aosp"
           fetch="https://mirrors.tuna.tsinghua.edu.cn/git/AOSP"

  <default revision="..."
           remote="github"

改成(注意只是 remote 部分修改了)

  <default revision="..."
           remote="lineage"

同步源码树(以后只需执行这条命令来同步):

repo sync

异常处理

部分仓库例如 Lineage_framework_base 同步的时候会出现 bundle 错误,这时候可以使用命令 repo sync --no-clone-bundle 进行同步。