安装依赖的库,顺便把vim 也安装一下
sudo apt-get install vim
sudo apt-get install git gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
找不到libncurses5,可以使用本机更高版本替代
sudo ln -s /usr/lib/x86_64-linux-gnu/libncurses.so.6.4 /usr/lib/x86_64-linux-gnu/libncurses.so.5
sudo ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4 /usr/lib/x86_64-linux-gnu/libtinfo.so.5
注意下边的命令下载的不是repo的python代码,而是网站的错误信息html
curl -L https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
手动在浏览器中输入 https://mirrors.tuna.tsinghua.edu.cn/git/git-repo ,然后保存以下,修改名字为repo
mkdir ~/bin
cp ~/Downloads/git-repo ~/bin/repo
cd ~/bin
chmod +x repo
在 ~/.bashrc 文件尾部增加如下内容
export PATH=~/bin/:$PATH
export REPO_URL='http://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
注意一下,这里的清华源的都是http,而不是https,主要是https下载比较慢,都是源代码,也没啥不安全的。
配置一下git信息
git config --global user.email “you@example.com”
git config --global user.name “Your Name”
repo init -u http://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b master
source build/envsetup.sh
lunch aosp_cf_x86_64_phone-trunk_staging-userdebug
1. 禁用沙箱
export TRUSTY_DISABLE_SANDBOX=1
2. 显式指定库路径(双重保障)
export LD_LIBRARY_PATH= P W D / o u t / s o o n g / h o s t / l i n u x − x 86 / l i b 64 : PWD/out/soong/host/linux-x86/lib64: PWD/out/soong/host/linux−x86/lib64:LD_LIBRARY_PATH
3. 启动构建
make -j8
find ./ -name “index.lock” -exec rm -f {} ;
find ./ -name “index.lock” -exec rm -i {} ;
sudo find ./ -name “index.lock” -exec rm -f {} ;
repo sync -j8 --force-sync --no-clone-bundle
参数说明:
-j8:多线程加速(根据网络调整)。
--force-sync:强制覆盖本地文件。
--no-clone-bundle:绕过 Git 分发包(避免因分发包损坏导致失败)。
repo forall -c ‘git clean -dfx; git reset --hard’
repo sync -c --no-tags -j8
定期校验源码完整性
repo forall -c ‘git fsck --full’
单独同步问题模块
repo sync -j4 device/google/gs-common
清理残留文件
repo forall -c ‘git reset --hard HEAD; git clean -fdx’
rm -rf .repo/project-objects
进入问题项目的目录(如 cd frameworks/base
)
rm -rf .git/index.lock # 确保锁文件已清除
git clean -dfx # 删除所有未跟踪文件(慎用!先备份)
git reset --hard # 强制重置到远程分支状态
git fetch --all # 重新拉取远程数据
git checkout -f # 强制切换分支(如当前分支)
git clean -dfx; git reset --hard