Android Studio 2.3 使用控制台中的模拟器,root 用户的“/dev/kvm 设备:权限被拒绝”
Posted
技术标签:
【中文标题】Android Studio 2.3 使用控制台中的模拟器,root 用户的“/dev/kvm 设备:权限被拒绝”【英文标题】:Android Studio 2.3 using emulator from console, "/dev/kvm device: permission denied" for root user 【发布时间】:2017-08-06 11:22:32 【问题描述】:我正在尝试启动我使用 Android Studio 2.3 的 avdmanager 创建的虚拟 android 设备(通过命令行)
所有命令都以 root 用户
身份执行当我尝试通过$ ~/Android/Sdk/tools/./emulator @Nexus_5X_Api_23_x86
启动模拟器时,输出为:
emulator: ERROR: x86_64 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)
我使用的是 64 位的 Ubuntu 16.04 服务器,Android Studio 是通过 x11 转发启动的,因此使用了我的桌面环境(也是 ubuntu 16.04,64 位!)
当我输入 $ kvm-ok
时,它给了我:
INFO: /dev/kvm exists
KVM acceleration can be used
为了证明我尝试访问的 .avd 存在:
$ ~/Android/Sdk/tools/bin/./avdmanager list avd
给出输出:
März 15, 2017 4:30:53 NACHM. sun.util.PropertyResourceBundleCharset$PropertiesFileDecoder decodeLoop
INFO: Invalid or unmappable UTF-8 sequence detected. Switching encoding from UTF-8 to ISO-8859-1
Available Android Virtual Devices:
Name: Nexus_5X_Api_23_x86
Device: Nexus 5X (Google)
Path: /root/.android/avd/Nexus_5X_Api_23_x86.avd
Target: Google APIs (Google Inc.)
Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86_64
Sdcard: 800M
/dev/kvm
的进一步权限是:
root@h2627852:~# ls -l /dev/kvm
crwxrwxrwx 1 root kvm 10, 232 Mär 15 10:48 /dev/kvm
root@h2627852:~# groups root
root : root kvm libvirtd libvirt
执行emulator-check
给了我:
root@h2627852:~# ~/Android/Sdk/tools/./emulator-check accel hyper-v cpu-info window-mgr desktop-env
accel:
11
This user doesn't have permissions to use KVM (/dev/kvm)
accel
hyper-v:
0
Hyper-V runs only on Windows
hyper-v
cpu-info:
146
Intel CPU|Virtualization is supported|64-bit CPU|
cpu-info
debug1: client_input_channel_open: ctype x11 rchan 3 win 65536 max 16384
debug1: client_request_x11: request from ::1 36346
debug1: channel 1: new [x11]
debug1: confirm x11
debug1: channel 1: FORCE input drain
window-mgr:
0
GNOME Shell
window-mgr
desktop-env:
0
mate
desktop-env
我真的不知道该怎么办了,搜索了整个论坛,但没有为我的系统找到此问题的复制品,其他系统上相同问题的修复对我不起作用,已经尝试完全清除并重新安装所有 qemu、libvirt、libvirtd 和 kvm 软件包,但没有成功。
感谢任何帮助!
编辑:~/Android/Sdk/tools/./emulator @Nexus_5X_Api_23_x86 -verbose
给我,
以下输出:
emulator:Android emulator version 25.3.0.0 (build_id 3394391)
emulator:Found AVD name 'Nexus_5X_Api_23_x86'
emulator:Found AVD target architecture: x86_64
emulator:argv[0]: '/root/Android/Sdk/tools/./emulator'; program directory: '/root/Android/Sdk/tools'
emulator: Found directory: /root/Android/Sdk/system-images/android-23/google_apis/x86_64/
emulator:Probing for /root/Android/Sdk/system-images/android-23/google_apis/x86_64//kernel-ranchu: file exists
emulator:Auto-config: -engine qemu2 (based on configuration)
emulator: Found directory: /root/Android/Sdk/system-images/android-23/google_apis/x86_64/
emulator:try dir /root/Android/Sdk/tools
emulator:try dir /root/Android/Sdk/tools/./
emulator:try dir /root/Android/Sdk/emulator
emulator:Found target-specific 64-bit emulator binary: /root/Android/Sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64
emulator:Adding library search path: '/root/Android/Sdk/emulator/lib64'
emulator:Adding library search path: '/root/Android/Sdk/emulator/lib64/libstdc++'
emulator: Found directory: /root/Android/Sdk/system-images/android-23/google_apis/x86_64/
emulator: Found directory: /root/Android/Sdk/system-images/android-23/google_apis/x86_64/
emulator:GPU emulation is disabled
emulator: Adding library search path for Qt: '/root/Android/Sdk/emulator/lib64/qt/lib'
emulator: Setting Qt plugin search path: QT_QPA_PLATFORM_PLUGIN_PATH=/root/Android/Sdk/emulator/lib64/qt/plugins
emulator: Running :/root/Android/Sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64
emulator: qemu backend: argv[00] = "/root/Android/Sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64"
emulator: qemu backend: argv[01] = "@Nexus_5X_Api_23_x86"
emulator: qemu backend: argv[02] = "-verbose"
emulator: Concatenated backend parameters:
/root/Android/Sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64 @Nexus_5X_Api_23_x86 -verbose
emulator: Android virtual device file at: /root/.android/avd/Nexus_5X_Api_23_x86.ini
emulator: virtual device content at /root/.android/avd/Nexus_5X_Api_23_x86.avd
emulator: virtual device config file: /root/.android/avd/Nexus_5X_Api_23_x86.avd/config.ini
emulator: using core hw config path: /root/.android/avd/Nexus_5X_Api_23_x86.avd/hardware-qemu.ini
emulator: Found AVD target API level: 23
emulator: Read property file at /root/Android/Sdk/system-images/android-23/google_apis/x86_64//build.prop
emulator: No boot.prop property file found.
emulator: Warning: config.ini contains invalid skin.path entry: (null)
emulator: autoconfig: -skin HVGA
emulator: autoconfig: -skindir (null)
emulator: autoconfig: -kernel /root/Android/Sdk/system-images/android-23/google_apis/x86_64//kernel-ranchu
emulator: Target arch = 'x86_64'
emulator: Auto-detect: Kernel image requires new device naming scheme.
emulator: Auto-detect: Kernel does not support YAFFS2 partitions.
emulator: autoconfig: -ramdisk /root/Android/Sdk/system-images/android-23/google_apis/x86_64//ramdisk.img
emulator: Using initial system image: /root/Android/Sdk/system-images/android-23/google_apis/x86_64//system.img
emulator: autoconfig: -data /root/.android/avd/Nexus_5X_Api_23_x86.avd/userdata-qemu.img
emulator: autoconfig: -initdata /root/.android/avd/Nexus_5X_Api_23_x86.avd/userdata.img
emulator: autoconfig: -cache /root/.android/avd/Nexus_5X_Api_23_x86.avd/cache.img
emulator: autoconfig: -sdcard /root/.android/avd/Nexus_5X_Api_23_x86.avd/sdcard.img
emulator: Increasing RAM size to 1024MB
emulator: VM heap size 0MB is below hardware specified minimum of 256MB,setting it to that value
emulator: System image is read only
emulator: GPU emulation is disabled
emulator: Found 2 DNS servers: 85.214.7.22 81.169.163.106
emulator: skin name 'HVGA' aliased to '320x480'
emulator: found magic skin width=320 height=480 bpp=16
emulator: CPU Acceleration: DISABLED
emulator: CPU Acceleration status: This user doesn't have permissions to use KVM (/dev/kvm)
emulator: ERROR: x86_64 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_HOME/emulator/emulator` 问题依旧,因为'$ANDROID_HOME/emulator/emulator' 只是符号链接到'$ANDROID_HOME/tools/emulator' 因为Android Studio 2.3 Android Studio: /dev/kvm device permission denied的可能重复 【参考方案1】:试试这个。 这对我有用
$ sudo chown username -R /dev/kvm
有时您还需要运行此代码
$ cd Android/Sdk/emulator/lib64/libstdc++
$ mv libstdc++.so.6 libstdc++.so.6.bak
$ ln -s /usr/lib64/libstdc++.so.6
【讨论】:
每次我尝试打开模拟器时都必须这样做吗?这是应该的吗?没有一次性解决方法吗?【参考方案2】:试试这些步骤:
如下安装qemu-kvm
sudo apt install qemu-kvm
使用以下命令将用户添加到 kvm 组:
sudo adduser <username> kvm
如果您得到权限被拒绝,请尝试以下命令
sudo chown <username> /dev/kvm
它在 Ubuntu 18.04
中对我有用【讨论】:
每次我尝试打开模拟器时都必须这样做吗?这是应该的吗?没有一次性解决方法吗? 这可行,但不是解决方案。一旦我们想再次打开模拟器,错误就会再次出现。 @SherinBinu 你找到一次性修复了吗?【参考方案3】:假设您要使用当前操作系统用户应用此所有权更改,请使用以下命令:
sudo chown $(whoami) -R /dev/kvm
【讨论】:
chown: invalid user: 'whoami' -- 所以我把它包装成这样:$(whoami)【参考方案4】:我解决了运行问题
sudo apt install qemu-kvm
sudo chown username -R /dev/kvm
【讨论】:
【参考方案5】:检查nano /etc/group
包含以kvm
开头并以您的用户名结尾的行。如果没有,则运行:
sudo gpasswd -a $USER kvm
【讨论】:
以上是关于Android Studio 2.3 使用控制台中的模拟器,root 用户的“/dev/kvm 设备:权限被拒绝”的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio 2.3使用来自控制台的模拟器,“/ dev / kvm device:
Android Studio 2.3 正式版新功能,你不来看看?!