tadfisher/android-nixpkgs

NixOS cannot start dynamically linked executable: `emulator` command

HPRIOR opened this issue · 5 comments

When using the flake provided by nix flake init -t github:tadfisher/android-nixpkgs on nixOS, I cannot use the emulator command (/nix/store/86myy4i3igzb3g2s3ld154y9rfqgb7qp-android-project-dir/bin/emulator). I am getting the error:

Could not start dynamically linked executable: /nix/store/86myy4i3igzb3g2s3ld154y9rfqgb7qp-android-project-dir/bin/emulator
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld

Is this expected behaviour? How else should I start an emulator?

Attempting to debug this, but new to nix.

I noticed that when I ran ldd on /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/.emulator-wrapped, libX11.so.6 was not found. I updated my devshell.nix to:

{
  pkgs,
  lib,
}:
with pkgs;
# Configure your development environment.
#
# Documentation: https://github.com/numtide/devshell
  devshell.mkShell rec {
    name = "android-project";
    motd = ''
      Entered the Android app development environment.
    '';
    env = [
      {
        name = "ANDROID_HOME";
        value = "${android-sdk}/share/android-sdk";
      }
      {
        name = "ANDROID_SDK_ROOT";
        value = "${android-sdk}/share/android-sdk";
      }
      {
        name = "JAVA_HOME";
        value = jdk.home;
      }
      {
        name = "LD_LIBRARY_PATH";
        value = "$LD_LIBRARY_PATH:${builtins.toString (lib.makeLibraryPath packages)}";
      }
    ];
    packages =
      [
        nodejs_20
        android-sdk
        gradle
        jdk
      ]
      ++ lib.optionals (system == "x86_64-linux") [
        android-studio
        xorg.libX11
        xorg.libX11.dev
        xorg.libXcursor
        xorg.libXrandr
        xorg.libXi
      ];
  }

Which results in the ldd /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/.emulator-wrapped output of:

	linux-vdso.so.1 (0x00007fffef7c5000)
	libX11.so.6 => /nix/store/h0aal69rli3p604dmijx7mps1diwx4f3-libX11-1.8.9/lib/libX11.so.6 (0x00007f3ce9892000)
	libandroid-emu-protos.so => /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64/libandroid-emu-protos.so (0x00007f3ce9784000)
	libandroid-emu-metrics.so => /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64/libandroid-emu-metrics.so (0x00007f3ce9400000)
	libandroid-emu-curl.so => /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64/libandroid-emu-curl.so (0x00007f3ce9000000)
	libandroid-emu-agents.so => /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64/libandroid-emu-agents.so (0x00007f3ce977c000)
	libc++.so.1 => /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64/libc++.so.1 (0x00007f3ce92c3000)
	libandroid-emu-base-logging.so => /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64/libandroid-emu-base-logging.so (0x00007f3ce974c000)
	libdl.so.2 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libdl.so.2 (0x00007f3ce9747000)
	librt.so.1 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/librt.so.1 (0x00007f3ce9740000)
	libglib2_linux-x86_64.so => /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64/libglib2_linux-x86_64.so (0x00007f3ce8ec1000)
	libprotobuf.so.32 => /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64/libprotobuf.so.32 (0x00007f3ce8c00000)
	libpthread.so.0 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libpthread.so.0 (0x00007f3ce973b000)
	libm.so.6 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libm.so.6 (0x00007f3ce8b1d000)
	libgcc_s.so.1 => /nix/store/nrwkk6ak3rgkrxbqhsscb01jpzmslf2r-xgcc-13.2.0-libgcc/lib/libgcc_s.so.1 (0x00007f3ce9714000)
	libc.so.6 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libc.so.6 (0x00007f3ce8930000)
	libxcb.so.1 => /nix/store/cvbf30dc4mamggijbxwlwxaxd7q4wch1-libxcb-1.17.0/lib/libxcb.so.1 (0x00007f3ce96e9000)
	/lib64/ld-linux-x86-64.so.2 => /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib64/ld-linux-x86-64.so.2 (0x00007f3ce9b27000)
	libXau.so.6 => /nix/store/mhs3ys5lbahsvrai5y0fv49q2xp4pc31-libXau-1.0.11/lib/libXau.so.6 (0x00007f3ce96e2000)
	libXdmcp.so.6 => /nix/store/6gg4xf3abpmdpkhpqkqwx2hdvs7fmgwc-libXdmcp-1.1.5/lib/libXdmcp.so.6 (0x00007f3ce96da000)

So it looks as though everything is being linked properly. I'm still getting the same error though

Found some more unresolved dependencies using libtree.

libtree /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/.emulator-wrapped :

/nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/.emulator-wrapped 
├── libandroid-emu-protos.so [rpath]
│   ├── libprotobuf.so.32 [rpath of 1]
│   │   └── libc++.so.1 [rpath of 1]
│   │       ├── libpthread.so.0 not found
│   │       └── librt.so.1 not found
│   │           ┊ Paths considered in this order:
│   │           ┊ 1. rpath is skipped because runpath was set
│   │           ┊ 2. LD_LIBRARY_PATH:
│   │           ┊    $LD_LIBRARY_PATH
│   │           ┊    /nix/store/7g98q0w4ymrfwv6f543l45f71p383pll-nodejs-20.12.2/lib
│   │           ┊    /nix/store/x1a77aw84v85bl9acdn8xaix15kihxzq-android-sdk-env/lib
│   │           ┊    /nix/store/3fymjlf5sdscapjhgpriq22a2chcl7g0-gradle-8.7/lib
│   │           ┊    /nix/store/7r44xx5jz5plr1qg2mznsk7g7dh1szdq-openjdk-21+35/lib
│   │           ┊    /nix/store/pj9nawsivfvyy0blsrck2scz4xycg7i5-android-studio-stable-2023.2.1.25/lib
│   │           ┊    /nix/store/h0aal69rli3p604dmijx7mps1diwx4f3-libX11-1.8.9/lib
│   │           ┊ 3. runpath:
│   │           ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64/../lib/x86_64-unknown-linux-gnu
│   │           ┊ 4. ld config files:
│   │           ┊ 5. Standard paths:
│   │           ┊    /lib
│   │           ┊    /lib64
│   │           ┊    /usr/lib
│   │           ┊    /usr/lib64
│   └── libc++.so.1 [rpath of 1]
├── libprotobuf.so.32 [rpath]
├── libglib2_linux-x86_64.so [rpath]
├── libandroid-emu-metrics.so [rpath]
│   ├── libandroid-emu-curl.so [rpath of 1]
│   │   ├── libandroid-emu-base-logging.so [rpath of 1]
│   │   │   ├── libc++.so.1 [rpath of 1]
│   │   │   └── libpthread.so.0 not found
│   │   │       ┊ Paths considered in this order:
│   │   │       ┊ 1. rpath:
│   │   │       ┊    depth 1
│   │   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
│   │   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
│   │   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
│   │   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
│   │   │       ┊ 2. LD_LIBRARY_PATH:
│   │   │       ┊    $LD_LIBRARY_PATH
│   │   │       ┊    /nix/store/7g98q0w4ymrfwv6f543l45f71p383pll-nodejs-20.12.2/lib
│   │   │       ┊    /nix/store/x1a77aw84v85bl9acdn8xaix15kihxzq-android-sdk-env/lib
│   │   │       ┊    /nix/store/3fymjlf5sdscapjhgpriq22a2chcl7g0-gradle-8.7/lib
│   │   │       ┊    /nix/store/7r44xx5jz5plr1qg2mznsk7g7dh1szdq-openjdk-21+35/lib
│   │   │       ┊    /nix/store/pj9nawsivfvyy0blsrck2scz4xycg7i5-android-studio-stable-2023.2.1.25/lib
│   │   │       ┊    /nix/store/h0aal69rli3p604dmijx7mps1diwx4f3-libX11-1.8.9/lib
│   │   │       ┊ 3. runpath was not set
│   │   │       ┊ 4. ld config files:
│   │   │       ┊ 5. Standard paths:
│   │   │       ┊    /lib
│   │   │       ┊    /lib64
│   │   │       ┊    /usr/lib
│   │   │       ┊    /usr/lib64
│   │   ├── libc++.so.1 [rpath of 1]
│   │   ├── librt.so.1 not found
│   │   └── libpthread.so.0 not found
│   │       ┊ Paths considered in this order:
│   │       ┊ 1. rpath:
│   │       ┊    depth 1
│   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
│   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
│   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
│   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
│   │       ┊ 2. LD_LIBRARY_PATH:
│   │       ┊    $LD_LIBRARY_PATH
│   │       ┊    /nix/store/7g98q0w4ymrfwv6f543l45f71p383pll-nodejs-20.12.2/lib
│   │       ┊    /nix/store/x1a77aw84v85bl9acdn8xaix15kihxzq-android-sdk-env/lib
│   │       ┊    /nix/store/3fymjlf5sdscapjhgpriq22a2chcl7g0-gradle-8.7/lib
│   │       ┊    /nix/store/7r44xx5jz5plr1qg2mznsk7g7dh1szdq-openjdk-21+35/lib
│   │       ┊    /nix/store/pj9nawsivfvyy0blsrck2scz4xycg7i5-android-studio-stable-2023.2.1.25/lib
│   │       ┊    /nix/store/h0aal69rli3p604dmijx7mps1diwx4f3-libX11-1.8.9/lib
│   │       ┊ 3. runpath was not set
│   │       ┊ 4. ld config files:
│   │       ┊ 5. Standard paths:
│   │       ┊    /lib
│   │       ┊    /lib64
│   │       ┊    /usr/lib
│   │       ┊    /usr/lib64
│   ├── libc++.so.1 [rpath of 1]
│   ├── libandroid-emu-protos.so [rpath of 1]
│   ├── libandroid-emu-base-logging.so [rpath of 1]
│   ├── libandroid-emu-agents.so [rpath of 1]
│   │   ├── libandroid-emu-base-logging.so [rpath of 1]
│   │   ├── libc++.so.1 [rpath of 1]
│   │   ├── librt.so.1 not found
│   │   └── libpthread.so.0 not found
│   │       ┊ Paths considered in this order:
│   │       ┊ 1. rpath:
│   │       ┊    depth 1
│   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
│   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
│   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
│   │       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
│   │       ┊ 2. LD_LIBRARY_PATH:
│   │       ┊    $LD_LIBRARY_PATH
│   │       ┊    /nix/store/7g98q0w4ymrfwv6f543l45f71p383pll-nodejs-20.12.2/lib
│   │       ┊    /nix/store/x1a77aw84v85bl9acdn8xaix15kihxzq-android-sdk-env/lib
│   │       ┊    /nix/store/3fymjlf5sdscapjhgpriq22a2chcl7g0-gradle-8.7/lib
│   │       ┊    /nix/store/7r44xx5jz5plr1qg2mznsk7g7dh1szdq-openjdk-21+35/lib
│   │       ┊    /nix/store/pj9nawsivfvyy0blsrck2scz4xycg7i5-android-studio-stable-2023.2.1.25/lib
│   │       ┊    /nix/store/h0aal69rli3p604dmijx7mps1diwx4f3-libX11-1.8.9/lib
│   │       ┊ 3. runpath was not set
│   │       ┊ 4. ld config files:
│   │       ┊ 5. Standard paths:
│   │       ┊    /lib
│   │       ┊    /lib64
│   │       ┊    /usr/lib
│   │       ┊    /usr/lib64
│   ├── libprotobuf.so.32 [rpath of 1]
│   ├── librt.so.1 not found
│   └── libpthread.so.0 not found
│       ┊ Paths considered in this order:
│       ┊ 1. rpath:
│       ┊    depth 1
│       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
│       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
│       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
│       ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
│       ┊ 2. LD_LIBRARY_PATH:
│       ┊    $LD_LIBRARY_PATH
│       ┊    /nix/store/7g98q0w4ymrfwv6f543l45f71p383pll-nodejs-20.12.2/lib
│       ┊    /nix/store/x1a77aw84v85bl9acdn8xaix15kihxzq-android-sdk-env/lib
│       ┊    /nix/store/3fymjlf5sdscapjhgpriq22a2chcl7g0-gradle-8.7/lib
│       ┊    /nix/store/7r44xx5jz5plr1qg2mznsk7g7dh1szdq-openjdk-21+35/lib
│       ┊    /nix/store/pj9nawsivfvyy0blsrck2scz4xycg7i5-android-studio-stable-2023.2.1.25/lib
│       ┊    /nix/store/h0aal69rli3p604dmijx7mps1diwx4f3-libX11-1.8.9/lib
│       ┊ 3. runpath was not set
│       ┊ 4. ld config files:
│       ┊ 5. Standard paths:
│       ┊    /lib
│       ┊    /lib64
│       ┊    /usr/lib
│       ┊    /usr/lib64
├── libandroid-emu-curl.so [rpath]
├── libandroid-emu-base-logging.so [rpath]
├── libc++.so.1 [rpath]
├── libandroid-emu-agents.so [rpath]
├── libX11.so.6 [LD_LIBRARY_PATH]
│   ├── libxcb.so.1 [runpath]
│   │   ├── libXau.so.6 [runpath]
│   │   └── libXdmcp.so.6 [runpath]
│   └── libpthread.so.0 [runpath]
├── libpthread.so.0 not found
└── librt.so.1 not found
    ┊ Paths considered in this order:
    ┊ 1. rpath:
    ┊    depth 1
    ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
    ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
    ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/lib64
    ┊    /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2
    ┊ 2. LD_LIBRARY_PATH:
    ┊    $LD_LIBRARY_PATH
    ┊    /nix/store/7g98q0w4ymrfwv6f543l45f71p383pll-nodejs-20.12.2/lib
    ┊    /nix/store/x1a77aw84v85bl9acdn8xaix15kihxzq-android-sdk-env/lib
    ┊    /nix/store/3fymjlf5sdscapjhgpriq22a2chcl7g0-gradle-8.7/lib
    ┊    /nix/store/7r44xx5jz5plr1qg2mznsk7g7dh1szdq-openjdk-21+35/lib
    ┊    /nix/store/pj9nawsivfvyy0blsrck2scz4xycg7i5-android-studio-stable-2023.2.1.25/lib
    ┊    /nix/store/h0aal69rli3p604dmijx7mps1diwx4f3-libX11-1.8.9/lib
    ┊ 3. runpath was not set
    ┊ 4. ld config files:
    ┊ 5. Standard paths:
    ┊    /lib
    ┊    /lib64
    ┊    /usr/lib
    ┊    /usr/lib64

This is resolved by adding glibc as a dependency:

{
  pkgs,
  lib,
}:
with pkgs;
# Configure your development environment.
#
# Documentation: https://github.com/numtide/devshell
  devshell.mkShell rec {
    name = "android-project";
    motd = ''
      Entered the Android app development environment.
    '';
    env = [
      {
        name = "ANDROID_HOME";
        value = "${android-sdk}/share/android-sdk";
      }
      {
        name = "ANDROID_SDK_ROOT";
        value = "${android-sdk}/share/android-sdk";
      }
      {
        name = "JAVA_HOME";
        value = jdk.home;
      }
      {
        name = "LD_LIBRARY_PATH";
        value = "$LD_LIBRARY_PATH:${builtins.toString (lib.makeLibraryPath packages)}";
      }
    ];
    packages =
      [
        nodejs_20
        android-sdk
        gradle
        jdk
      ]
      ++ lib.optionals (system == "x86_64-linux") [
        android-studio
        xorg.libX11
        glibc
      ];
  }

libtree /nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/.emulator-wrapped now returns:

/nix/store/98w9jh9s6phm3pg3m0jv1zs8gdpx8gzb-emulator-35.1.2/.emulator-wrapped 
├── libandroid-emu-protos.so [rpath]
│   ├── libprotobuf.so.32 [rpath of 1]
│   │   └── libc++.so.1 [rpath of 1]
│   │       ├── libpthread.so.0 [LD_LIBRARY_PATH]
│   │       └── librt.so.1 [LD_LIBRARY_PATH]
│   └── libc++.so.1 [rpath of 1]
├── libprotobuf.so.32 [rpath]
├── libglib2_linux-x86_64.so [rpath]
├── libandroid-emu-metrics.so [rpath]
│   ├── libandroid-emu-curl.so [rpath of 1]
│   │   ├── libandroid-emu-base-logging.so [rpath of 1]
│   │   │   ├── libc++.so.1 [rpath of 1]
│   │   │   └── libpthread.so.0 [LD_LIBRARY_PATH]
│   │   ├── libc++.so.1 [rpath of 1]
│   │   ├── librt.so.1 [LD_LIBRARY_PATH]
│   │   └── libpthread.so.0 [LD_LIBRARY_PATH]
│   ├── libc++.so.1 [rpath of 1]
│   ├── libandroid-emu-protos.so [rpath of 1]
│   ├── libandroid-emu-base-logging.so [rpath of 1]
│   ├── libandroid-emu-agents.so [rpath of 1]
│   │   ├── libandroid-emu-base-logging.so [rpath of 1]
│   │   ├── libc++.so.1 [rpath of 1]
│   │   ├── librt.so.1 [LD_LIBRARY_PATH]
│   │   └── libpthread.so.0 [LD_LIBRARY_PATH]
│   ├── libprotobuf.so.32 [rpath of 1]
│   ├── librt.so.1 [LD_LIBRARY_PATH]
│   └── libpthread.so.0 [LD_LIBRARY_PATH]
├── libandroid-emu-curl.so [rpath]
├── libandroid-emu-base-logging.so [rpath]
├── libc++.so.1 [rpath]
├── libandroid-emu-agents.so [rpath]
├── libX11.so.6 [LD_LIBRARY_PATH]
│   ├── libpthread.so.0 [LD_LIBRARY_PATH]
│   └── libxcb.so.1 [runpath]
│       ├── libXau.so.6 [runpath]
│       └── libXdmcp.so.6 [runpath]
├── libpthread.so.0 [LD_LIBRARY_PATH]
└── librt.so.1 [LD_LIBRARY_PATH]

The previous nixos dynamic linking error when running emulator -avd android-em-test has been resolved. Although a new one has appeared:

/nix/store/5lr5n3qa4day8l1ivbwlcby2nknczqkq-bash-5.2p26/bin/bash: symbol lookup error: /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31/lib/libc.so.6: undefined symbol: __tunable_is_initialized, version GLIBC_PRIVATE

nix-store -q --references /nix/store/5lr5n3qa4day8l1ivbwlcby2nknczqkq-bash-5.2p26 shows:

/nix/store/1rm6sr6ixxzipv5358x0cmaw8rs84g2j-glibc-2.38-44
/nix/store/5lr5n3qa4day8l1ivbwlcby2nknczqkq-bash-5.2p26

I have tried using an overlay to pin the version of glibc to 2.38-44, but the error persists:

{
  pkgs,
  lib,
}:
with pkgs;
# Configure your development environment.
#
# Documentation: https://github.com/numtide/devshell
  devshell.mkShell rec {
    name = "android-project";
    motd = ''
      Entered the Android app development environment.
    '';
    env = [
      {
        name = "ANDROID_HOME";
        value = "${android-sdk}/share/android-sdk";
      }
      {
        name = "ANDROID_SDK_ROOT";
        value = "${android-sdk}/share/android-sdk";
      }
      {
        name = "JAVA_HOME";
        value = jdk.home;
      }
      {
        name = "LD_LIBRARY_PATH";
        value = "$LD_LIBRARY_PATH:${builtins.toString (lib.makeLibraryPath packages)}";
      }
    ];
    packages =
      [
        nodejs_20
        android-sdk
        gradle
        jdk
      ]
      ++ lib.optionals (system == "x86_64-linux") [
        android-studio
        xorg.libX11
        (pkgs.glibc.overrideAttrs (oldAttrs: rec {
          version = "2.38-44";
        }))
      ];
  }

I don't think I have the required knowledge of linux/nixos to debug this further. Any help would be much appreciated!

Thank you. The emulator command is working now