Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android-studio requires KVM? #41703

Closed
Radvendii opened this issue Jun 8, 2018 · 12 comments
Closed

android-studio requires KVM? #41703

Radvendii opened this issue Jun 8, 2018 · 12 comments

Comments

@Radvendii
Copy link
Contributor

Issue description

When I install android-studio, and then try to run a simple hello world app, I get the error

KVM is required to run this AVD.
Unknown Error

in a pop-up window.

I tried adding KVM to where I thought it would reach the target, i.e.

--- a/pkgs/applications/editors/android-studio/common.nix
+++ b/pkgs/applications/editors/android-studio/common.nix
@@ -15,6 +15,7 @@
 , gzip
 , fontconfig
 , freetype
+, kvm
 , libpulseaudio
 , libX11
 , libXext
@@ -61,6 +62,7 @@ let
           gnused
 
           # For Android emulator
+          kvm
           file
           glxinfo
           pciutils

but this had no discernible effect.

Steps to reproduce

  1. add android-studio to systemPackages
  2. sudo nixos-rebuild switch
  3. android-studio
  4. Go through setup wizard. Install everything.
  5. Try to run an app

Technical details

  • system: "x86_64-linux"
  • host os: Linux 4.14.43, NixOS, 18.09pre140958.696c6bed4e8 (Jellyfish)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.0.2
  • channels(root): "nixos"
  • channels(qolen): "nixos-18.09pre140682.5da85431fb1"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos
@Mic92
Copy link
Member

Mic92 commented Jun 8, 2018

The simulator is using virtualization if your image cpu architecture matches the one on your host (i.e. x86_64). Adding a package probably does not help here.
You should be able to see a kvm device on your machine:

ls -la /dev/kvm
crw-rw-rw- 10,232 root  6 Jun 10:44 /dev/kvm

Also enable depending on your cpu vendor the corresponding kernel module in configuration.nix:

boot.kernelModules = ["kvm-intel"];

@Radvendii
Copy link
Contributor Author

I have a kvm device on my machine, and I just added kvm-intel like you suggest, but the problem persists.

@Mic92
Copy link
Member

Mic92 commented Jun 8, 2018

I am not sure what they expect to be present on the system, you could try strace the avd manager to see what check they perform and what fails.

@Radvendii
Copy link
Contributor Author

@Mic92 How would I do that? running strace android-studio and then launching the avd manager doesn't seem to be doing the right thing, but I don't see how to run the avd manager from the command line.

Also, I'm starting to think this might be an ELF problem. There are a whole bunch of executables android-studio downloaded into ~/Android that seem to have the wrong rpath and interpreter. Is there a way to search through all executables in a directory and patchelf them all to the right paths? What would the "right paths" even be?

@Mic92
Copy link
Member

Mic92 commented Jun 13, 2018

strace does not follow childs, you are only seeing the output for the wrapper shell script. Try strace -f or even better try to start the avd-manager from the android-studio console with strace to be not so overwhelmed by the output. There is also an -o parameter to redirect the output to a file.

@Mic92
Copy link
Member

Mic92 commented Jun 13, 2018

android-studio builds a usernamespace that provides needed libraries in /usr/bin and /usr/lib using this function: https://nixos.org/nixpkgs/manual/#sec-fhs-environments
This means that inside android-studio you can use all elf binaries unpatched.

@Mic92
Copy link
Member

Mic92 commented Jun 13, 2018

See also: https://nixos.wiki/wiki/Android

@Radvendii
Copy link
Contributor Author

Radvendii commented Jun 14, 2018

Ah, right. I forgot about that. So now I'm having this weird issue where inside the android-studio console, none of the normal executeables can be found. So I have to run it like

/run/current-system/sw/bin/strace ~/Android/Sdk/tools/bin/avdmanager

But then I get the error /usr/bin/env: ‘sh’: No such file or directory

Which I think is just again the same issue of none of the normal executables can be found.

EDIT: Whoops. I'm being silly, I just had to add /run/current-system/sw/bin to $PATH for some reason I thought it was already there.

@Radvendii
Copy link
Contributor Author

So $PATH didn't have all the necessary directories, and neither does $LD_LIBRARY_PATH (missing libGL and libXdamage). I'm going to go and piecemeal add all of the necessary ones, but is there a reason these wouldn't be set right? Can I fix that easily?

@Radvendii
Copy link
Contributor Author

So it turns out the AVD Manager UI can't be launched from the command line, and there are other unrelated issues I'm getting trying to run the emulator directly. Is there some way I can find the relevant part of the output of strace -f? Neither "avd" nor "kvm" appear anywhere in the output.

@Radvendii
Copy link
Contributor Author

Okay, I think I've managed to narrow it down to a range of 4 PIDs (those are the ones that connected when I tried to start the emulator from the UI), which gives me 1300 lines of strace to look through. I'm not sure what I'm looking for though, given that "kvm" never comes up.

@redfish64
Copy link
Contributor

redfish64 commented Jun 30, 2018

I had the same issue, and this is what I found running a strace:

[tim@yellowhat:~]$ grep open  strace.out
1763  openat(AT_FDCWD, "/nix/store/27x7pinqdsl9f3rpbm8bsszd9fhwq266-glibc-2.27/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1763  openat(AT_FDCWD, "/nix/store/27x7pinqdsl9f3rpbm8bsszd9fhwq266-glibc-2.27/lib/tls/haswell/x86_64/libGL.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1763  openat(AT_FDCWD, "/nix/store/27x7pinqdsl9f3rpbm8bsszd9fhwq266-glibc-2.27/lib/tls/haswell/libGL.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1763  openat(AT_FDCWD, "/nix/store/27x7pinqdsl9f3rpbm8bsszd9fhwq266-glibc-2.27/lib/tls/x86_64/libGL.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1763  openat(AT_FDCWD, "/nix/store/27x7pinqdsl9f3rpbm8bsszd9fhwq266-glibc-2.27/lib/tls/libGL.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1763  openat(AT_FDCWD, "/nix/store/27x7pinqdsl9f3rpbm8bsszd9fhwq266-glibc-2.27/lib/haswell/x86_64/libGL.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1763  openat(AT_FDCWD, "/nix/store/27x7pinqdsl9f3rpbm8bsszd9fhwq266-glibc-2.27/lib/haswell/libGL.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1763  openat(AT_FDCWD, "/nix/store/27x7pinqdsl9f3rpbm8bsszd9fhwq266-glibc-2.27/lib/x86_64/libGL.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1763  openat(AT_FDCWD, "/nix/store/27x7pinqdsl9f3rpbm8bsszd9fhwq266-glibc-2.27/lib/libGL.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
1763  writev(2, [{iov_base="/home/tim/Android/Sdk/emulator/e"..., iov_len=45}, {iov_base=": ", iov_len=2}, {iov_base="error while loading shared libra"..., iov_len=36}, {iov_base=": ", iov_len=2}, {iov_base="libGL.so.1", iov_len=10}, {iov_base=": ", iov_len=2}, {iov_base="cannot open shared object file", iov_len=30}, {iov_base=": ", iov_len=2}, {iov_base="No such file or directory", iov_len=25}, {iov_base="\n", iov_len=1}], 10) = 155

I added libGL to the list of requirements and it fixed it. I'll create a pull request.

@Radvendii FYI, when using strace with a large program, use the "-p" option to connect to a running process. This way you can monitor it right before you perform the action that triggers the bug. ex. strace -p (pid) -o strace.out -f

redfish64 added a commit to redfish64/nixpkgs that referenced this issue Jun 30, 2018
Without it, when starting an android emulator in some cases results in the
cryptic, "KVM is required to run this AVD. Unknown Error"

Fixes NixOS#41703
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants