编译树莓派AOSP

本文总结:使用开源项目raspberry-vanilla,编译通过源码编译一个树莓派可用的镜像,android源使用的是清华镜像源。

你也可以先刷一个Konstakang制作的树莓派Android镜像,看看效果,下载地址见6.4节,下载后用Rpi Imager刷入SD卡,连接HDMI屏幕即可看到效果。

1. 安装repo工具

这里直接从清华源下载的repo.

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ cd ~/bin
$ curl -L https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
$ chmod +x repo

Note: 也可以使用google官方的repo, [https://storage.googleapis.com/git-repo-downloads/repo].

2. 安装开发环境

Ubuntu 22.04:

$ sudo apt update
$ sudo apt install openjdk-17-jdk
$ sudo apt install dosfstools e2fsprogs fdisk kpartx mtools rsync
$ sudo apt install build-essential flex bison gawk bc git ssh \
        g++-multilib gcc-multilib gperf libxml2-utils zlib1g-dev:i386 \
        zip unzip liblz4-tool libncurses-dev libssl-dev python-is-python3 \
        u-boot-tools file curl

3. 下载源码

3.1 下载Manifest

基于raspberry-vanilla开源项目。

创建目录:

$ mkdir ~/android16
$ cd ~/android16

有两种选择,一种是完整版(占用空间多,版本控制友好),一种是浅克隆版(占用空间少,版本控制不友好),两者二选一:

完整版:

$ repo init -u https://android.googlesource.com/platform/manifest -b android-16.0.0_r4
$ curl -o .repo/local_manifests/manifest_brcm_rpi.xml -L https://raw.githubusercontent.com/raspberry-vanilla/android_local_manifest/android-16.0/manifest_brcm_rpi.xml --create-dirs

浅克隆版:

$ repo init -u https://android.googlesource.com/platform/manifest -b android-16.0.0_r4 --depth=1
$ curl -o .repo/local_manifests/manifest_brcm_rpi.xml -L https://raw.githubusercontent.com/raspberry-vanilla/android_local_manifest/android-16.0/manifest_brcm_rpi.xml --create-dirs
$ curl -o .repo/local_manifests/remove_projects.xml -L https://raw.githubusercontent.com/raspberry-vanilla/android_local_manifest/android-16.0/remove_projects.xml

Note:可选android 版本参考列表,见6.1节。 

3.2 下载代码

$ repo sync -j4

如果你选择浅克隆版,这个过程通常会下载超过86 GB的文件。如果是全克隆会更多一些。

3.3 编译代码

初始化环境:

$ cd ~/android16
$ source build/envsetup.sh

然后选择设备配置,可供选择的设备配置见6.2节。

我的是树莓派5,所以选择:[aosp_rpi5-bp4a-userdebug],执行如下:

$ lunch aosp_rpi5-bp4a-userdebug

编译:

$ make bootimage systemimage vendorimage -j$(nproc)

Note:由于编译可能会读取配置,内存占用可能会超过34GB,所以,如果你的计算机内存小于等于32 GB则通过swap扩展内存,操作方法可以参考第6步相关内容。

编译完成之后,打包镜像,树莓派4打包:

$ ./rpi4-mkimg.sh

树莓派5打包:

$ ./rpi5-mkimg.sh

4. 刷机

[待补充]

5. 编译内核

[代补充]

6. 其它

6.1 Android版本列表

Version Vanilla Example Latest(2025) API Level
Android 16.0 android-16.0.0_r4 android-16.0.0_r4 36
Android 15.0 android-15.0.0_r32 android-15.0.0_r36 35
Android 14.0 android-14.0.0_r67 android-14.0.0_r75 34
Android 13.0 android-13.0.0_r75 android-13.0.0_r83 33
Android 12.1 android-12.1.0_r22 android-12.1.0_r26 32

6.2 树莓派设备配置

No. Android 16.0 Android 15.0 Android 14.0 Android 13.0 Android 12.1
1 aosp_rpi4-bp4a-userdebug aosp_rpi4-bp1a-userdebug aosp_rpi4-ap2a-userdebug aosp_rpi4-userdebug aosp_rpi4-userdebug
2 aosp_rpi4_tv-bp4a-userdebug aosp_rpi4_tv-bp1a-userdebug aosp_rpi4_tv-ap2a-userdebug aosp_rpi4_tv-userdebug /
3 aosp_rpi4_car-bp4a-userdebug aosp_rpi4_car-bp1a-userdebug aosp_rpi4_car-ap2a-userdebug aosp_rpi4_car-userdebug /
4 aosp_rpi5-bp4a-userdebug aosp_rpi5-bp1a-userdebug aosp_rpi5-ap2a-userdebug / /
5 aosp_rpi5_tv-bp4a-userdebug aosp_rpi5_tv-bp1a-userdebug aosp_rpi5_tv-ap2a-userdebug / /
6 aosp_rpi5_car-bp4a-userdebug aosp_rpi5_car-bp1a-userdebug aosp_rpi5_car-ap2a-userdebug / /

配置含义,以Android 16和树莓派5为例:

  • Tablet UI: aosp_rpi5-bp4a-userdebug
  • Android TV: rpi5_tv-bp4a-userdebug
  • Android Automotive: aosp_rpi5_car-bp4a-userdebug

6.3 树莓派配置链接

# Android 16.0
https://raw.githubusercontent.com/raspberry-vanilla/android_local_manifest/android-16.0/manifest_brcm_rpi.xml

# Android 15.0
https://raw.githubusercontent.com/raspberry-vanilla/android_local_manifest/android-15.0/manifest_brcm_rpi.xml

# Android 14.0
https://raw.githubusercontent.com/raspberry-vanilla/android_local_manifest/android-14.0/manifest_brcm_rpi.xml

# Android 13.0
https://raw.githubusercontent.com/raspberry-vanilla/android_local_manifest/android-13.0/manifest_brcm_rpi4.xml

# Android 12.1
https://raw.githubusercontent.com/raspberry-vanilla/android_local_manifest/android-12.1/manifest_brcm_rpi4.xml

6.4 链接

Konstakang镜像:[https://konstakang.com/devices/rpi5/].

Raspberry Pi Imager:[https://www.raspberrypi.com/software/].

posted @ 2025-12-09 21:19  this毛豆  阅读(2)  评论(0)    收藏  举报