1.手机ROM下载
小米官方ROM
https://xiaomirom.com/rom/mi-5-gemini-global-fastboot-recovery-rom/#
驱动列表 https://mifirmware.com/xiaomi-usb-drivers/
1. Lineageos
https://www.lineageos.org/https://github.com/LineageOShttps://lineageosroms.com/ (历史版本) https://mirrors.tuna.tsinghua.edu.cn/lineage-rom/full/
2.刷机流程
- Fastboot 线刷包 (有电脑就下载用USB刷机)
- Recovery 卡刷包 (下载到手机内刷机)
3.线刷官方ROM
sh
#重启到bootloader
adb reboot bootloader
#刷入恢复镜像
fastboot flash recovery recovery.img
按住音量上键+开机进入recovery 这个恢复镜像是临时的,只能一次进入,失败需要重新执行上面步骤
清除数据
点击 Factory Reset 点击 Format data / factory reset
刷入系统
点击 Apply Update 点击 Apply from ADB 执行脚本
sh
adb sideload lineage-21.0-20240508-nightly-gemini-signed.zip
编译系统
环境:Ubuntu 22.04
安装ssh
sh
#配置代理
export ALL_PROXY="http://192.168.2.12:7890"
sudo apt update
sudo apt-get install ssh
service ssh start
service ssh status
#安装网络工具
sudo apt install net-tools
#查看本机IP
ifconfig
配置ssh免密登录
ps1
# windows电脑 查看公钥
cat C:\Users\Kpa\.ssh\id_rsa.pub
#登录到linux
ssh kpa@172.17.171.130
cd ~
mkdir .ssh
touch .ssh/authorized_keys
echo "上面公钥内容" > ./.ssh/authorized_keys
chmod 700 ./.ssh
chmod 600 ./.ssh/authorized_keys
#配置链接信息(Windows)
打开 C:\Users\Kpa\.ssh\config 文件 加入一行 rsa私钥
Host 172.17.171.130
HostName 172.17.171.130
User kpa
IdentityFile C:\Users\Kpa\.ssh\id_rsa
安装AOSP编译环境
sh
sudo apt update
sudo apt-get install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git git-lfs gnupg gperf imagemagick lib32readline-dev lib32z1-dev libelf-dev liblz4-tool libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev openjdk-11-jdk -y
#对于 23.10 (mantic) 之前的 Ubuntu 版本,只需安装:
sudo apt install lib32ncurses5-dev libncurses5 libncurses5-dev
#不同版本的LineageOS需要不同的JDK(Java开发工具包)版本。
#LineageOS 18.1+:OpenJDK 11(包含在源代码下载中)
#LineageOS 17.1+: Python 3 (安装python-is-python3)
sudo apt install python-is-python3
sudo apt clean && sudo apt autoremove -y
配置GIT
sh
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"
创建目录
sh
mkdir -p ~/bin
mkdir -p ~/android/lineage
安装Repo
sh
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
PATH=~/bin:$PATH
source ~/.profile
#下面的可以不执行
sudo apt install vim
sudo vim ~/.profile
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
配置cache加速
android 10 移除了cache,高版本不用配置
sh
sudo vim ~/.bashrc
#添加下面两行到文件中
export USE_CCACHE=1
export CCACHE_EXEC=/home/kpa/.ccache
#设置缓存大小
ccache -M 50G
source ~/.bashrc
配置内存交换空间
配置了40G内存完全不够用,编译到一半 编译被kill
sh
sudo swapoff /swapfile
sudo rm /swapfile
sudo fallocate -l 32G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
#配置永久交换
#/etc/fstab
#最后一行插入 进入后按i进入编辑模式 修改好按ESC :wq
sudo apt-get install vim
sudo vim /etc/fstab
/swapfile swap swap defaults 0 0
#配置交换规则
#/etc/sysctl.conf
sudo vim /etc/sysctl.conf
vm.min_free_kbytes=1500000 #大致1.5G 启用交换
#重启虚拟机
下载源码
- 14.1 (Android 7.1)
- 15.1 (Android 8.1)
- 16.0 (Android 9)
- 17.1 (Android 10)
- 18.1 (Android 11)
- 19.1 (Android 12L)
- 20 (Android 13)
- 21 (Android 14)
这里测试了18.1 遇到很多错误,无法编译,最终选择了最新版本
sh
cd ~/android/lineage
repo init -u https://github.com/LineageOS/android.git -b lineage-21.0 --git-lfs
repo sync
# repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/lineageOS/LineageOS/android.git -b lineage-21.0 --git-lfs
# repo sync -c --no-clone-bundle
配置内核
sh
cd ~/android/lineage
source build/envsetup.sh
breakfast gemini
提取驱动
sh
sudo apt install android-tools-adb
sudo apt install android-tools-fastboot
adb devices
cd ~/android/lineage/device/xiaomi/gemini
./extract-files.sh
croot
breakfast gemini
编译
croot
brunch gemini
使用asfp
查看branch指令里最后拼接的版本名称 vendor/lineage/build/envsetup.sh
检查 /vendor/lineage/vars/aosp_target_release里的值
sh
function breakfast()
{
target=$1
local variant=$2
source ${ANDROID_BUILD_TOP}/vendor/lineage/vars/aosp_target_release
if [ $# -eq 0 ]; then
# No arguments, so let's have the full menu
lunch
else
if [[ "$target" =~ -(user|userdebug|eng)$ ]]; then
# A buildtype was specified, assume a full device name
lunch $target
else
# This is probably just the Lineage model name
if [ -z "$variant" ]; then
variant="userdebug"
fi
lunch lineage_$target-$aosp_target_release-$variant
fi
fi
return $?
}
sh
"lunchTarget" : "lineage_gemini-ap1a-userdebug"
使用VSCODE
cd ~/android/lineage
source build/envsetup.sh
breakfast gemini
m aidegen
aidegen -i v frameworks/base
修改代码
sh
cd ~/android/lineage
source build/envsetup.sh
breakfast gemini
make api-stubs-docs-update-current-api
make api-stubs-docs-non-updatable-update-current-api
make update-api
brunch gemini