小编典典

在Jenkins构建过程中运行android模拟器

jenkins

我已经安装了Jenkins,并配置了在构建过程中运行模拟器的构建作业。但是,当我执行作业时,出现错误消息,表明jenkins用户没有运行kvm的权限。我该如何解决。

$ android list target
[android] Using Android SDK: /opt/android/sdk
$ adb start-server
* daemon not running. starting it now on port 5973 *
* daemon started successfully *
$ adb start-server
[android] Starting Android emulator
[android] Erasing existing emulator data...
$ emulator -ports 5971,5972 -prop persist.sys.language=en -prop persist.sys.country=US -avd hudson_en-US_160_1024x768_android-15_x86 -no-snapshot-load -no-snapshot-save -wipe-data
emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure KVM is properly installed and usable.
CPU acceleration status: This user doesn't have permissions to use KVM (/dev/kvm).
[android] Emulator did not appear to start; giving up
$ adb disconnect localhost:5972
[android] Stopping Android emulator
$ adb kill-server

权限

$ ls -l /dev/kvm
crw-rw----+ 1 root root 10, 232 May  6 13:46 /dev/kvm

$ groups jenkins
jenkins : jenkins

阅读 592

收藏
2020-07-25

共1个答案

小编典典

我设法解决了这个问题。

  1. 安装Qemu-KVM和cpu-checker:
    sudo apt install qemu-kvm cpu-checker

  2. 检查KVM是否可用(以jenkins用户身份):
    $ kvm-ok
    INFO: /dev/kvm exists
    KVM acceleration can be used

  3. 创建组kvm并添加jenkins到该组:
    addgroup kvm
    usermod -a -G kvm jenkins

  4. 更改以下组的所有权/dev/kvm
    chgrp kvm /dev/kvm

  5. 创建udev规则:
    $ sudo nano /etc/udev/rules.d/60-qemu-kvm.rules
    KERNEL=="kvm", GROUP="kvm", MODE="0660"

  6. 重启

2020-07-25