You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SSH启动Android模拟器失败,无头模式启动成功问题求助

Android模拟器SSH启动失败但无头模式正常的原因与解决方法

问题描述

我有一台用于自动化测试的服务器,日常通过SSH或NoMachine屏幕镜像访问。尝试从本地通过SSH启动服务器上的Android模拟器时失败,报错如下:

user@msb-10-r2u32-2u4n-b:~$ emulator @PH_nightly_10

INFO    | Android emulator version 31.3.13.0 (build_id 9189900) (CL:N/A)emulator: INFO: Found systemPath /home/user/android_sdk/system-images/android-30/google_apis_playstore/x86_64/

INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.

WARNING | unexpected system image feature string, emulator might not function correctly, please try updating the emulator.

INFO    | Warning: could not connect to display  ((null):0, (null))

INFO    | Info: Could not load the Qt platform plugin "xcb" in "/home/user/android_sdk/emulator/lib64/qt/plugins" even though it was found. ((null):0, (null))

Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.((null):0, (null))INFO    | Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.((null):0, (null))

但通过NoMachine屏幕镜像的终端执行相同命令时,模拟器可成功启动。随后尝试使用无头模式命令:

$ emulator -no-window @EMULATOR_ID

启动成功,日志如下:

INFO    | Android emulator version 31.3.13.0 (build_id 9189900) (CL:N/A)

emulator: INFO: Found systemPath /home/bukalapak/android_sdk/system-images/android-30/google_apis_playstore/x86_64/

INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.

WARNING | unexpected system image feature string, emulator might not function correctly, please try updating the emulator.

WARNING | cannot add library /home/bukalapak/android_sdk/emulator/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed

INFO    | added library /home/bukalapak/android_sdk/emulator/lib64/vulkan/libvulkan.so

INFO    | configAndStartRenderer: setting vsync to 60 hz

pulseaudio: Failed to initialize PA contextCould not init `pa' audio driver

WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.***

INFO    | Started GRPC server at 127.0.0.1:8554, security: Local, auth: none

INFO    | Advertising in: /run/user/1001/avd/running/pid_24535.ini

INFO    | setDisplayConfigs w 1080 h 2160 dpiX 440 dpiY 440

INFO    | Cold boot: incompatible snapshot version

INFO    | Your emulator is out of date, please update by launching Android Studio:
 - Start Android Studio
 - Select menu "Tools > Android > SDK Manager"
 - Click "SDK Tools" tab
 - Check "Android Emulator" checkbox
 - Click "OK"

INFO    | boot completed

INFO    | boot time 26691 ms

INFO    | Increasing screen off timeout, logcat buffer size to 2M.

INFO    | Revoking microphone permissions for Google App.

原因分析

  • SSH默认会话无X11环境:Android模拟器默认依赖图形界面,Qt平台插件xcb需要X11显示环境支撑,但普通SSH连接未分配有效的DISPLAY环境变量,导致插件初始化失败,启动崩溃。
  • NoMachine自带完整X11会话:NoMachine作为远程桌面工具,会为终端会话自动配置X11显示环境,DISPLAY变量被正确设置,因此模拟器能正常加载Qt插件并启动。
  • 无头模式绕过图形依赖:-no-window参数让模拟器以无界面模式运行,无需加载Qt图形插件和X11环境,直接后台渲染,因此可以成功启动。

解决方法

方法1:启用SSH X11转发

本地发起SSH连接时添加-X或-Y参数(-Y适用于信任的服务器,权限更高):

ssh -Y user@your-server-ip

连接成功后确认DISPLAY变量已设置:

echo $DISPLAY

此时执行emulator @PH_nightly_10即可正常启动模拟器。

方法2:在服务器创建虚拟X11显示

若无法使用X11转发,可安装虚拟显示工具创建虚拟X11会话:

  1. 安装Xvfb:
sudo apt install xvfb  # Debian/Ubuntu系统
# 或
sudo yum install xorg-x11-server-Xvfb  # RHEL/CentOS系统
  1. 启动虚拟显示并设置环境变量:
Xvfb :1 -screen 0 1024x768x16 &
export DISPLAY=:1
  1. 执行模拟器启动命令即可。

方法3:持续使用无头模式(自动化测试推荐)

如果自动化测试无需可视化界面,-no-window模式是最简洁的方案,完全规避图形环境依赖,适合服务器端自动化场景,可将命令封装到脚本中方便执行。

方法4:更新Android模拟器

日志提示模拟器版本过时,更新可解决unexpected system image feature string等兼容性问题:

  1. 启动Android Studio(或使用SDK Manager命令行工具)
  2. 进入Tools > Android > SDK Manager
  3. 切换到SDK Tools标签页
  4. 勾选Android Emulator并点击OK完成更新

内容的提问来源于stack exchange,提问作者N Hilmi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 20:00:58