编辑
2025-03-03
工作知识
0
请注意,本文编写于 95 天前,最后修改于 95 天前,其中某些信息可能已经过时。

目录

一:编译组件
1.1 下载仓库
1.2 编译
1.3 安装
二:修改内核
2.1 binder和ashmem
2.2 网络配置
2.3 namespace配置
2.4 cgroups配置
2.5 总体配置参考
2.6 必要时开启psi
三:使用说明
3.1 初始化
3.2 体验
3.3 设置属性
3.4 安装程序
3.5 查看日志
3.6 进入shell环境
3.7 其他配置
3.8 X11上启动

Waydorid是从anbox演进的新的容器安卓的一种方案,我们的客户想要运行安卓程序,这里描述如何使用waydroid来兼容安卓10的系统

一:编译组件

1.1 下载仓库

git clone https://github.com/waydroid/libglibutil.git git clone https://github.com/waydroid/libgbinder.git git clone https://github.com/waydroid/gbinder-python git clone https://github.com/waydroid/waydroid.git

1.2 编译

apt build-dep . debuild -us -uc

这里 gbinder-python没用changlog,所有需要额外处理一下

dch --create --package "gbinder-python" --newversion "1.0.0~git20210909-1" foo bar dh_make --createorig -p "gbinder-python_1.0.0~git20210909"

1.3 安装

因为waydroid依赖容器,所以需要安装lxc

apt install lxc dpkg -i bridge-utils_1.6-2kylin1_arm64.deb liblxc1_1%3a4.0.2-0kylin1_arm64.deb liblxc-common_1%3a4.0.2-0kylin1_arm64.deb lxc_1%3a4.0.2-0kylin1_all.deb lxc-utils_1%3a4.0.2-0kylin1_arm64.deb

然后安装编译出来的包

dpkg -i libgbinder_1.1.25_arm64.deb libgbinder-tools_1.1.25_arm64.deb libglibutil_1.0.66_arm64.deb python3-gbinder_1.1_arm64.deb waydroid_1.3.0_all.deb

二:修改内核

2.1 binder和ashmem

安卓系统需要binder和ashmem,如果系统安装了linux-module包,可以直接加载,如下

modprobe ashmem_linux modprobe binder_linux

如果linux是可编译的,可以修改config增加如下

CONFIG_ASHMEM=y CONFIG_ANDROID=y CONFIG_ANDROID_BINDER_IPC=y CONFIG_ANDROID_BINDERFS=y

2.2 网络配置

CONFIG_BRIDGE / "802.1d Ethernet Bridging" ('Networking support -> Networking options -> 802.1d Ethernet Bridging') CONFIG_VETH / "Veth pair device" CONFIG_MACVLAN / "Macvlan" CONFIG_VLAN_8021Q / "Vlan" CONFIG_NETFILTER CONFIG_NF_NAT CONFIG_NF_TABLES CONFIG_NFT_NAT CONFIG_NETFILTER_XT_TARGET_CHECKSUM CONFIG_IP_NF_TARGET_MASQUERADE CONFIG_NF_CONNTRACK CONFIG_NETFILTER_XTABLES CONFIG_IP_NF_IPTABLES CONFIG_IP_NF_FILTER CONFIG_IP_NF_MANGLE

如下是kmre启动过程中需要的iptable_nat模块添加的宏:

CONFIG_PACKET=y CONFIG_NETFILTER=y CONFIG_IP_NF_CONNTRACK=y CONFIG_IP_NF_FTP=y CONFIG_IP_NF_IRC=y CONFIG_IP_NF_IPTABLES=y CONFIG_IP_NF_FILTER=y CONFIG_IP_NF_NAT=y CONFIG_IP_NF_MATCH_STATE=y CONFIG_IP_NF_TARGET_LOG=y CONFIG_IP_NF_MATCH_LIMIT=y CONFIG_IP_NF_TARGET_MASQUERADE=y CONFIG_NETFILTER_ADVANCED=y CONFIG_NF_CONNTRACK_IPV4=y

2.3 namespace配置

CONFIG_NAMESPACES / "Namespaces" ('General Setup -> Namespaces support') CONFIG_UTS_NS / "Utsname namespace" ('General Setup -> Namespaces Support / UTS namespace') CONFIG_IPC_NS / "Ipc namespace" ('General Setup -> Namespaces Support / IPC namesapce') CONFIG_USER_NS / "User namespace" ('General Setup -> Namespaces Support / User namespace (EXPERIMENTAL)') CONFIG_PID_NS / "Pid namespace" ('General Setup -> Namespaces Support / PID Namespaces') CONFIG_NET_NS / "Network namespace" ('General Setup -> Namespaces Support -> Network namespace')

2.4 cgroups配置

CONFIG_CGROUP_SCHED / "Cgroup sched" ('General Setup -> Control Group support -> Group CPU scheduler') CONFIG_FAIR_GROUP_SCHED / "Group scheduling for SCHED_OTHER" ('General Setup -> Control Group support -> Group CPU scheduler -> Group scheduling for SCHED_OTHER') CONFIG_BLK_CGROUP / "Block IO controller" ('General Setup -> Control Group support -> Block IO controller') CONFIG_CFQ_GROUP_IOSCHED / "CFQ Group Scheduling support" ('Enable the block layer -> IO Schedulers -> CFQ I/O scheduler -> CFQ Group Scheduling support') CONFIG_CGROUP_CPUACCT / "Cgroup cpu account" ('General Setup -> Control Group support -> Simple CPU accounting cgroup subsystem') CONFIG_MEMCG_SWAP / Memory Resource Controller Swap Extension

2.5 总体配置参考

内核配置可以按照如下脚本检测docker启动必须的脚本:check-config.sh;使用命令如下:

./check-config.sh rockchip_linux_defconfig

配置如下

General setup ---> [*] Control Group support ---> [*] Freezer cgroup subsystem [*] Device controller for cgroups [*] Cpuset support [*] Include legacy /proc/<pid>/cpuset file [*] Simple CPU accounting cgroup subsystem [*] Resource counters [*] Memory Resource Controller for Control Groups [*] Memory Resource Controller Swap Extension [*] Memory Resource Controller Swap Extension enabled by default [*] Enable perf_event per-cpu per-container group (cgroup) monitoring [*] Group CPU scheduler ---> [*] Group scheduling for SCHED_OTHER [*] Group scheduling for SCHED_RR/FIFO <*> Block IO controller -*- Namespaces support [*] UTS namespace [*] IPC namespace [*] User namespace (EXPERIMENTAL) [*] PID Namespaces [*] Network namespace [*] Configure standard kernel features (expert users) [*] Networking support ---> Networking options ---> <M> 802.1d Ethernet Bridging <M> 802.1Q VLAN Support Device Drivers ---> [*] Network device support ---> <M> MAC-VLAN support (EXPERIMENTAL) <M> Virtual ethernet pair device Character devices ---> -*- Unix98 PTY support [*] Support multiple instances of devpts

2.6 必要时开启psi

在cmdline,也就是chosen的bootarge下追加 psi=1,可以降低oom的风险

三:使用说明

3.1 初始化

默认需要下载system.img和vendor.img

如果已存在上述文件,可以直接使用

mkdir -p /usr/share/waydroid-extra/images mv system.img vendor.img /usr/share/waydroid-extra/images/ waydroid init

如果没有system vendor,则会自动下载

下载地址为:https://sourceforge.net/projects/waydroid/files/images/

3.2 体验

使用之前,建议重启一下容器服务,如下:

systemctl restart waydroid-container.service

重启之后,在机器环境下直接启动安卓UI如下

waydroid show-full-ui

3.3 设置属性

安卓容器可以获取/设置属性,通过如下命令

waydroid prop get ro.hardware.egl waydroid prop set ro.hardware.egl=swiftshader

3.4 安装程序

waydroid app install *.apk waydroid app launch com.android.calculator2

3.5 查看日志

waydroid logcat

3.6 进入shell环境

waydroid shell

3.7 其他配置

ro.hardware.gralloc和ro.hardware.egl是选择显卡驱动的。

如果没有选择,默认走gbm和mesa。如果为了兼容,可以走

ro.hardware.gralloc=default ro.hardware.egl=swiftshader

当然不同机器按照实际情况走即可

3.8 X11上启动

waydroid是基于wayland后端,如果要在X11平台启动,则需要启动一个wayland后端,这里可以是weston

然后在weston里面启动waydroid ui即可