环境配置说明
交叉编译内核
- 某些发行版内核已自带了模块,但树莓派的内核不包含它们且不支持DKMS只能手动编译
从Ubuntu 19.04开始,自带的内核(>= 5.0)已包含上面两个模块,不再需要从PPA安装模块。
从Debian 10开始,自带的内核(>= 4.19)已包含上面两个模块,不再需要从DKMS安装模块。
- 在编译主机上安装交叉编译工具
1 2 3
| sudo apt-get update sudo apt install git bc bison flex libssl-dev make libncurses-dev gcc-aarch64-linux-gnu
|
- 获取内核源码
1 2 3 4
| mkdir /home/leux/rpi4 cd /home/leux/rpi4 git clone -b rpi-5.4.y --depth=1 https://github.com/raspberrypi/linux.git
|
- 为内核源码打补丁,使其可生成ashmem_linux和binder_linux模块
1 2 3 4 5 6
| wget https://salsa.debian.org/kernel-team/linux/-/blob/debian/5.4.19-1/debian/patches/debian/android-enable-building-ashmem-and-binder-as-modules.patch wget https://salsa.debian.org/kernel-team/linux/-/blob/debian/5.4.19-1/debian/patches/debian/export-symbols-needed-by-android-drivers.patch cd linux patch -p1 < ../android-enable-building-ashmem-and-binder-as-modules.patch patch -p1 < ../export-symbols-needed-by-android-drivers.patch
|
- 获取内核编译配置文件
1 2 3 4 5 6 7
| sudo modprobe configs zcat /proc/config.gz > ~/raspi4b.config
cp raspi4b.config /home/leux/rpi4/linux/.config
|
- 配置内核编译参数
1 2 3 4 5 6 7 8 9 10 11 12 13
| make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
CONFIG_ANDROID=y CONFIG_ANDROID_BINDER_IPC=m CONFIG_ANDROID_BINDER_DEVICES="binder,hwbinder,vndbinder" CONFIG_ASHMEM=m
Device Drivers > Android > Android Drivers > Android Binder IPC Driver Device Drivers > Staging drivers > Android > Enable the Anonymous Shared Memory Subsystem
|
- 编译内核并备份
1 2 3 4 5 6 7 8 9 10 11 12 13
| make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j12
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=/home/leux/rpi4/kernel/ modules_install
cp arch/arm64/boot/Image ../kernel/kernel-kvm.img
cd /home/leux/rpi4 tar -czvf kernel.tgz kernel/
|
- 安装内核到系统
1 2 3 4 5 6
| tar -xzvf kernel.tgz && cd kernel mv kernel-kvm.img /boot/ mv lib/modules/* /lib/modules/ echo "kernel=kernel-kvm.img" >> /boot/config.txt
|
- 安装完内核后重启来加载新内核,然后查看模块效果
1 2 3 4 5 6 7 8 9
| sudo modprobe ashmem_linux sudo modprobe binder_linux
ls -1 /dev/{ashmem,binder} /dev/ashmem /dev/binder
|
安装配置Anbox
- 安装Anbox
1 2 3
| sudo apt install anbox
|
- 下载Android镜像
1 2 3 4 5 6 7 8 9 10 11 12
|
https://build.anbox.io/android-images/2017/06/12/android_1_armhf.img https://build.anbox.io/android-images/2017/08/04/android_1_arm64.img https://build.anbox.io/android-images/2018/07/19/android_amd64.img
https://cdimage.ubports.com/anbox-images/android-armhf-32binder.img https://cdimage.ubports.com/anbox-images/android-armhf-64binder.img
cp android_1_arm64.img /var/lib/anbox/android.img
|
- 启动Anbox容器管理器
1 2 3 4 5 6 7 8 9
| sudo systemctl start anbox-container-manager
/usr/bin/anbox session-manager
/usr/bin/anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity
|
其他说明
- 在Session manager启动后,可通过lxc-attach来进入Abox的Shell环境
1 2 3 4 5 6 7 8 9 10 11 12
| sudo lxc-attach -q \ --clear-env \ -P /var/lib/anbox/containers \ -n default \ -v PATH=/sbin:/system/bin:/system/sbin:/system/xbin \ -v ANDROID_ASSETS=/assets \ -v ANDROID_DATA=/data \ -v ANDROID_ROOT=/system \ -v ANDROID_STORAGE=/storage \ -v ASEC_MOUNTPOINT=/mnt/asec \ -v EXTERNAL_STORAGE=/sdcard -- /system/bin/sh
|
- 在Anbox中安装应用
1 2 3 4 5 6 7 8 9 10 11 12
| sudo apt install android-tools-adb
adb devices adb install xxx.apk adb uninstall com.xx.xx adb shell adb shell pm list packages
adb: failed to install xx.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]
|