本文介绍了在 jenkins 构建期间运行 android 模拟器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经安装了 Jenkins 并配置了一个在构建过程中运行模拟器的构建作业.但是当我执行作业时,我收到 jenkins 用户无权运行 kvm 的错误消息.我该如何解决它.
I have installed Jenkins and configured a build job with emulator running during build. But when I execute the job, I get error message that jenkins user doesn't have permission to run kvm. How can I fix it.
$ 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
推荐答案
我已经设法解决了这个问题.
I have managed to fix the problem.
- 安装 Qemu-KVM 和 cpu-checker:
sudo apt install qemu-kvm cpu-checker
- 检查 KVM 是否可用(作为
jenkins
用户):$ kvm-ok
INFO:/dev/kvm 存在
可以使用KVM加速
- 创建组 kvm 并将
jenkins
添加到该组:addgroup kvm
usermod -a -G kvm jenkins
- 更改
/dev/kvm
的组所有权:chgrp kvm/dev/kvm
- 创建udev规则:
$ sudo nano/etc/udev/rules.d/60-qemu-kvm.rules
KERNEL=="kvm", GROUP="kvm", MODE="0660"
- 重启
- Install Qemu-KVM and cpu-checker:
sudo apt install qemu-kvm cpu-checker
- Check if KVM is available (as
jenkins
user):$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
- Create group kvm and add
jenkins
to this group:addgroup kvm
usermod -a -G kvm jenkins
- Change group ownership for
/dev/kvm
:chgrp kvm /dev/kvm
- Create udev rule:
$ sudo nano /etc/udev/rules.d/60-qemu-kvm.rules
KERNEL=="kvm", GROUP="kvm", MODE="0660"
- Reboot
这篇关于在 jenkins 构建期间运行 android 模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!