Skip to content

Redroid编译

1.前情提要

记录一下一次Redoird AOSP编译过程,以下是编译前的基础设施

  • Windows10
  • Ubuntu 22.04
    • 12核 40g内存 1T硬盘

提示

最低内存好像是16G 第一次配置32G 8线程编译 内存不够会经常出错


2.系统装好后配置ssh远程

安装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

打开 Window终端(推荐下载Window商店的 Windows Terminal )
对于正在运行的虚拟机 可以
ctrl+alt+f2 切换桌面模式
ctrl+alt+f3 切换终端模式

ssh kpa@172.17.171.130

配置ssh免密登录

ps1
# windows电脑 查看公钥 
cat C:\Users\Kpa\.ssh\id_rsa.pub
#登录到linux
ssh kpa@172.17.171.130
cd ~

mkdir -p .ssh && 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 install flex bison build-essential zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc fontconfig -y
sudo apt install make git-core gnupg zip unzip curl python3 openjdk-11-jdk -y

sudo apt clean && sudo apt autoremove -y

配置GIT

sh
sudo apt install git
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

配置科大源下载

sh
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
## 如果上述 URL 不可访问,可以用下面的:
## curl -sSL  'https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT' |base64 -d > ~/bin/repo
chmod a+x ~/bin/repo

#下载一个80G初始文件
wget --continue https://mirrors.ustc.edu.cn/aosp-monthly/aosp-latest.tar
tar xf aosp-latest.tar

mv ~/aosp ~/redroid
cd redroid
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-11.0.0_r48

同步redroid代码

sh
mkdir ~/redroid && cd ~/redroid

repo init -u https://github.com/remote-android/platform_manifests.git -b redroid-11.0.0_r48 --depth=1 --git-lfs
# check @remote-android/platform_manifests for supported branch / manifest

repo sync -c

redroid补丁

sh
cd ~/
git clone https://github.com/remote-android/redroid-patches.git ~/redroid-patches
~/redroid-patches/apply-patch.sh ~/redroid

配置内存交换空间

配置了32G内存完全不够用,编译到一半 编译被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 启用交换

#重启虚拟机

安装docker

源代码调试阅读工具

  1. 配置Android Studio for Platform
sh
#需要设置代理访问
wget https://dl.google.com/android/asfp/asfp-2023.2.1.20-linux.deb
cd ~
sudo dpkg -i asfp-2023.2.1.20-linux.deb
  1. 安装vscode
    安装Remote插件