在jenkins构建期间运行android模拟器

时间:2015-05-06 11:56:40

标签: jenkins android-emulator continuous-integration kvm

我已经安装了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

2 个答案:

答案 0 :(得分:31)

我设法解决了这个问题。

  1. 安装Qemu-KVM和cpu-checker

    apt-get 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. 重新启动

答案 1 :(得分:0)

在我的CI(gitlab)上,Ubuntu上不存在

usermod -a -G kvm gitlab-runner

或与詹金斯(Jenkins)

usermod -a -G kvm jenkins