Android Studio: /dev/kvm device permission denied

后端 未结 27 3220
鱼传尺愫
鱼传尺愫 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 04:07

    Under Ubuntu, the permissions of /dev/kvm usually look like this:

    $ ls -l /dev/kvm
    crw-rw---- 1 root kvm 10, 232 May 24 09:54 /dev/kvm
    

    The user that runs the Android emulator (i.e. your user) needs to get access to this device.

    Thus, there are basically 2 ways how to get access:

    • Make sure that your user is part of the kvm group (requires a re-login of your user after the change)
    • Widen the permissions of that device such that your user has access (requires a change to the udev daemon configuration)

    Add User to KVM Group

    Check if your user is already part of the kvm group, e.g.:

    $ id 
    uid=1000(juser) gid=1000(juser) groups=1000(juser),10(wheel)
    

    If it isn't then add it with e.g.:

    $ sudo usermod --append --groups kvm juser
    

    After that change you have to logout and login again to make the group change effective (check again with id).

    Widen Permissions

    Alternatively, you can just can widen the permissions of the /dev/kvm device.

    Example:

    echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
        | sudo tee /etc/udev/rules.d/99-kvm4all.rules
    sudo udevadm control --reload-rules
    sudo udevadm trigger --name-match=kvm
    

    FWIW, this is the default on other distributions such as Fedora and CentOS.

    Check the effectiveness of the above commands with another ls. You should see output similar to:

    $ ls -l /dev/kvm
    crw-rw-rw-. 1 root kvm 10, 232 2020-05-16 09:19 /dev/kvm
    

    Big advantage: You don't need to logout and login again for this change to be effective.

    Non-Solutions

    • calling chmod and chown directly on /dev/kvm - 1) these changes aren't persistent over reboots and 2) since /dev/kvm permissions are controlled by the udev daemon, it can 'fix' its permissions at any time, e.g. after each emulator run
    • adding executable permissions to /dev/kvm - your emulator just requires read and write permissions
    • changing permissions recursively on /dev/kvm - I don't know what's up with that - looks like cargo cult
    • installing extra packages like qemu - you already have your emulator installed - you just need to get access to the /dev/kvm device

提交回复
热议问题