在无头服务器上运行android模拟器

时间:2018-01-09 23:41:34

标签: android android-emulator qemu kvm headless

我有一个无头的Debian服务器,我曾经用它来进行CI和测试。我不知道发生了什么,但它破了,所以我删除了整个SDK并从头开始。

我做了:

  • 使用以下内容检索最新的网址:

    curl -s 'https://developer.android.com/studio/index.html#downloads' \
        | grep -oP 'https?://dl.google.com/android/repository/sdk-tools-linux[^" ]+' \
        | sort | uniq
    
  • 下载了它&解压缩它
  • 更新了SDK管理器:

     ./tools/bin/sdkmanager --update
    
  • 接受了许可证:

     yes | ./tools/bin/sdkmanager --licenses
    
  • 为API级别27安装了所有内容:

    ./tools/bin/sdkmanager --install "platforms;android-27" "system-images;android-27;google_apis;x86"
    
  • 我已根据说明安装了KVM和Qemu
  • 我创建了一个AVD:

    echo no | ./tools/bin/avdmanager create avd --force --name avdname -k "system-images;android-27;google_apis;x86"
    
  • 然后启动了模拟器:

    ./emulator/emulator @avdname -no-window
    

它开始但是在logcat中它抱怨缺少Qemu:

01-09 23:15:19.278  4075  4075 D libEGL  : Emulator has vendor provided software renderer, qemu.gles is set to 2.
01-09 23:15:19.282  4075  4075 D libEGL  : loaded /vendor/lib/egl/libEGL_emulation.so
01-09 23:15:19.283  4075  4075 D libEGL  : loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
01-09 23:15:19.288  4075  4075 D libEGL  : loaded /vendor/lib/egl/libGLESv2_emulation.so
01-09 23:15:19.294  4075  4075 E         : connect: failed with fd -1 errno 22
01-09 23:15:19.294  4075  4075 E         : Failed to connect to host (QemuPipeStream)!!!
01-09 23:15:19.294  4075  4075 E EGL_emulation: Failed to establish connection with the host
01-09 23:15:19.294  4075  4075 W libEGL  : eglInitialize(0xab2fb014) failed (EGL_SUCCESS)
01-09 23:15:19.295  4075  4075 I /system/bin/surfaceflinger: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
01-09 23:15:19.295  4075  4075 E EGL_emulation: tid 4075: eglGetConfigs(774): error 0x3001 (EGL_NOT_INITIALIZED)
01-09 23:15:19.295  4075  4075 E EGL_emulation: tid 4075: eglChooseConfig(796): error 0x3001 (EGL_NOT_INITIALIZED)
01-09 23:15:19.295  4075  4075 E EGL_emulation: tid 4075: eglGetConfigs(774): error 0x3001 (EGL_NOT_INITIALIZED)
01-09 23:15:19.295  4075  4075 E EGL_emulation: tid 4075: eglChooseConfig(796): error 0x3001 (EGL_NOT_INITIALIZED)
01-09 23:15:19.295  4075  4075 W SurfaceFlinger: no suitable EGLConfig found, trying a simpler query
01-09 23:15:19.296  4075  4075 E EGL_emulation: tid 4075: eglGetConfigs(774): error 0x3001 (EGL_NOT_INITIALIZED)
01-09 23:15:19.296  4075  4075 E EGL_emulation: tid 4075: eglChooseConfig(796): error 0x3001 (EGL_NOT_INITIALIZED)
01-09 23:15:19.296  4075  4075 F SurfaceFlinger: no suitable EGLConfig found, giving up
01-09 23:15:19.296  4075  4075 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 4075 (surfaceflinger), pid 4075 (surfaceflinger)
01-09 23:15:19.305  4086  4086 I crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
01-09 23:15:19.306  1592  1592 I /system/bin/tombstoned: received crash request for pid 4075
01-09 23:15:19.307  4086  4086 I crash_dump32: performing dump of process 4075 (target tid = 4075)

我有hw.gpu.enabled = false,不确定它是否相关。

KVM很高兴:

$ ./tools/emulator -accel-check
accel:
0
KVM (version 12) is installed and usable.
accel

我不知道KVM是否存在问题,或者GPU加速是否是其他问题。

有趣的是,这就像一个魅力:

./tools/bin/sdkmanager --install "system-images;android-26;google_apis;x86_64" "platforms;android-26"
echo no | ./tools/bin/avdmanager create avd --force --name avd26 -k "system-images;android-26;google_apis;x86_64"
./emulator/emulator @avd26 -no-window

是因为它是x86_64图像吗?因为API 27系统映像有问题吗?为什么没有API 27 b的64位图像?

2 个答案:

答案 0 :(得分:1)

除了-no-window param:

之外,尝试使用这些参数运行模拟器

qemu -enable-kvm -snapshot

我最近在无头环境中启动模拟器时遇到了类似的问题,这有助于我解决它。系统映像版本无关紧要。

答案 1 :(得分:1)

尝试-gpu swiftshader。这似乎为我解决了这个问题。