Android Studio: /dev/kvm device permission denied

后端 未结 27 3228
鱼传尺愫
鱼传尺愫 2020-12-02 03:12

When I try to run my Android app on an emulator I get this error:

/dev/kvm permission denied.

I checked the permissions and ad

27条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 03:49

    There's absolutely no need to install qemu-kvm (and all its dependencies) if you only want to run the Android Studio Emulator.

    The only thing you have to do is to give your user (i.e. the one you are logged in with) the right to access the /dev/kvm-device.

    This is done in three simple steps.

    First:

    Create the kvm-group

    groupadd -r kvm

    The option -r creates a system group, i.e. with a GID <= 999 (see /etc/login.defs => SYS_GID_MAX)

    Second:

    Change permissions on /dev/kvm. This could be done as part of the qemu-kvm-installation, because one of the dependencies is installing qemu-system-common (on current Ubuntu systems, package name may vary), which in turn installs the file /lib/udev/rules.d/60-qemu-system-common.rules containing the following:

    KERNEL=="kvm", GROUP="kvm", MODE="0660"
    

    So if you are just create a file /etc/udev/rules.d/60-qemu-permissions.rules containing the above line, you are done with the first step.

    Third:

    Add your username to the group by executing

    usermod -a -G kvm - the -a is important for adding your user to the kvm-group. Without that you will overwrite the group-settings for your user to only belonging to "kvm"...

    That's it.

    For the new udev rule and group setting to take effect it's easiest to reboot and login again.

    You can also execute

    udevadm control --reload-rules && udevadm trigger

    for reloading the rules but you still have to logout and login again with regard to the new group.

提交回复
热议问题