NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.97k stars 13.98k forks source link

androidenv.emulateApp fails to start emulator (libvulkan.so.1: full) #121146

Open s-ol opened 3 years ago

s-ol commented 3 years ago

Describe the bug

Emulators created with androidenv.emulateApp do not start correctly and only show a black screen until manually quit. Vulkan errors on STDOUT/STDERR.

To Reproduce

  1. create flake.nix:

    {
    inputs = {
    nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;
    };
    
    outputs = { self, nixpkgs, ... } @ inputs:
    with import nixpkgs {
      system = "x86_64-linux";
      config.android_sdk.accept_license = true;
    }; rec {
      packages.x86_64-linux.emulator =
        (androidenv.emulateApp {
          name = "emulate-MyAndroidApp";
          platformVersion = "30";
          abiVersion = "x86";
          systemImageType = "google_apis_playstore";
          enableGPU = true;
        });
    
      defaultApp.x86_64-linux = {
        type = "app";
        program = "${packages.x86_64-linux.emulator}/bin/run-test-emulator";
      };
    };
    }
  2. run (nix run)

Expected behavior The emulator should launch.

Logs

nix run
Looking for a free TCP port in range 5554-5584
We have a free TCP port: 5554
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/build-tools/30.0.3/package.xml. Probably the SDK is read-only
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/platform-tools/package.xml. Probably the SDK is read-only
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/platforms/android-30/package.xml. Probably the SDK is read-only
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/system-images/android-30/google_apis_playstore/x86/package.xml. Probably the SDK is read-only
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/tools/package.xml. Probably the SDK is read-only
Available Android targets:==============] 100% Fetch remote repository...
----------
id: 1 or "android-30"
     Name: Android API 30
     Type: Platform
     API level: 30
     Revision: 3
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/build-tools/30.0.3/package.xml. Probably the SDK is read-only
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/platform-tools/package.xml. Probably the SDK is read-only
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/platforms/android-30/package.xml. Probably the SDK is read-only
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/system-images/android-30/google_apis_playstore/x86/package.xml. Probably the SDK is read-only
Info: Exception while marshalling /nix/store/6y4rf9s4j8bhvp23kbyl74arkrgwjq19-androidsdk/libexec/android-sdk/tools/package.xml. Probably the SDK is read-only
Auto-selecting single ABI x86===========] 100% Fetch remote repository...
Do you wish to create a custom hardware profile? [no] Waiting until the emulator has booted the device and the package manager is ready...
emulator: Android emulator version 30.6.3.0 (build_id 7266284) (CL:N/A)
emulator: Requested console port 5554: Inferring adb port 5555.
handleCpuAcceleration: feature check for hvf
cannot add library /nix/store/axqq54w61jy1b38pakg1a15s63zjxwmd-emulator-30.6.3/libexec/android-sdk/emulator/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed
added library /nix/store/axqq54w61jy1b38pakg1a15s63zjxwmd-emulator-30.6.3/libexec/android-sdk/emulator/lib64/vulkan/libvulkan.so
cannot add library /nix/store/axqq54w61jy1b38pakg1a15s63zjxwmd-emulator-30.6.3/libexec/android-sdk/emulator/lib64/vulkan/libvulkan.so.1: full
emulator: ERROR: VkCommonOperations.cpp:537: Failed to create Vulkan instance.
queryCoreProfileSupport: swap interval not found
Your emulator is out of date, please update by launching Android Studio:
 - Start Android Studio
 - Select menu "Tools > Android > SDK Manager"
 - Click "SDK Tools" tab
 - Check "Android Emulator" checkbox
 - Click "OK"

Additional context This happens both with and without enableGPU = true. Vulkan is working on my AMD GPU system, vkcube in nix-shell -p vulkan-tools works ok. I have tried adding the libvulkan.so or libvulkan.so.1 from vulkan-loader to LD_PRELOAD_PATH (the ones used by vkcube, as revealed by ldd $(which vkcube), but that also did not help and the output was still the same, including the "added library" and "cannot add library" lines.

Notify maintainers I could not find any meta.maintainers, but it appears that @svanderburg and @erikarvstedt did extensive work on emulateApp and/or androidenv in general.

Metadata nix-shell -p nix-info --run "nix-info -m"

s-ol commented 3 years ago

Okay, so I realized after posting that I was overriding LD_PRELOAD_PATH, not LD_PRELOAD which is the correct env var. Fixing this curiously prevents the emulator from starting for different reasons:

nix run .#emulator
adding vulkan...
LD_PRELOAD_PATH: '/nix/store/si20clrvrfsjvdgs65z4zrsvwmwrqi3v-vulkan-loader-1.2.162.0/lib/libvulkan.so:'
Looking for a free TCP port in range 5554-5584
grep: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)
We have a free TCP port: 5554

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

grep: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

/nix/store/3y52qkcx7knmfdjzycsp82091ncn2h6i-emulate-MyAndroidApp/bin/run-tost-emulator: line 59: /tmp/nix-android-vm-NNXY/.android/avd/device.avd/config.ini: No such file or directory
Waiting until the emulator has booted the device and the package manager is ready...
emulator: Android emulator version 30.6.3.0 (build_id 7266284) (CL:N/A)
emulator: ERROR: Unknown AVD name [device], use -list-avds to see valid list.
ANDROID_SDK_HOME is defined but there is no file device.ini in $ANDROID_SDK_HOME/avd
(Note: Directories are searched in the order $ANDROID_AVD_HOME, $ANDROID_SDK_HOME/avd and $HOME/.android/avd)

and then, after also adding export JAVA_HOME="${jdk8.home}":

nix run .#emulator
adding vulkan...
LD_PRELOAD_PATH: '/nix/store/si20clrvrfsjvdgs65z4zrsvwmwrqi3v-vulkan-loader-1.2.162.0/lib/libvulkan.so:'
Looking for a free TCP port in range 5554-5584
grep: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)
We have a free TCP port: 5554
sed: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)
sed: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)

Usage:
      avdmanager [global options] [action] [action options]
      Global options:
  -s --silent     : Silent mode, shows errors only.
  -v --verbose    : Verbose mode, shows errors, warnings and all messages.
     --clear-cache: Clear the SDK Manager repository manifest cache.
  -h --help       : Help on a specific command.

Valid actions are composed of a verb and an optional direct object:
-   list              : Lists existing targets or virtual devices.
-   list avd          : Lists existing Android Virtual Devices.
-   list target       : Lists existing targets.
-   list device       : Lists existing devices.
- create avd          : Creates a new Android Virtual Device.
-   move avd          : Moves or renames an Android Virtual Device.
- delete avd          : Deletes an Android Virtual Device.
grep: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)
sed: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)
sed: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)
sed: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)
sed: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)
sed: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)
sed: /nix/store/0c7c96gikmzv87i7lv3vq5s1cmfjd6zf-glibc-2.31-74/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/v8q6nxyppy1myi3rxni2080bv8s9jxiy-glibc-2.32-40/lib/libpthread.so.0)

Usage:
      avdmanager [global options] [action] [action options]
      Global options:
  -s --silent     : Silent mode, shows errors only.
  -v --verbose    : Verbose mode, shows errors, warnings and all messages.
     --clear-cache: Clear the SDK Manager repository manifest cache.
  -h --help       : Help on a specific command.

Valid actions are composed of a verb and an optional direct object:
-   list              : Lists existing targets or virtual devices.
-   list avd          : Lists existing Android Virtual Devices.
-   list target       : Lists existing targets.
-   list device       : Lists existing devices.
- create avd          : Creates a new Android Virtual Device.
-   move avd          : Moves or renames an Android Virtual Device.
- delete avd          : Deletes an Android Virtual Device.
/nix/store/lcz0p582a6vjhd453vhh0pw5v62liqy9-emulate-MyAndroidApp/bin/run-tost-emulator: line 59: /tmp/nix-android-vm-TFT3/.android/avd/device.avd/config.ini: No such file or directory
Waiting until the emulator has booted the device and the package manager is ready...
emulator: Android emulator version 30.6.3.0 (build_id 7266284) (CL:N/A)
emulator: ERROR: Unknown AVD name [device], use -list-avds to see valid list.
ANDROID_SDK_HOME is defined but there is no file device.ini in $ANDROID_SDK_HOME/avd
(Note: Directories are searched in the order $ANDROID_AVD_HOME, $ANDROID_SDK_HOME/avd and $HOME/.android/avd)