NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.41k stars 14.35k forks source link

Android avdmanager Using Wrong Java Version #353444

Closed mcmah309 closed 4 weeks ago

mcmah309 commented 1 month ago

Describe the bug

avdmanager seem to be using java 11 rather than java 17.

henry@nixos:~/my_system_config (master)$ avdmanager
Error: LinkageError occurred while loading main class com.android.sdklib.tool.AvdManagerCli
        java.lang.UnsupportedClassVersionError: com/android/sdklib/tool/AvdManagerCli has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
henry@nixos:~/my_system_config (master)$ whereis java
java: /nix/store/hzci24n481nnnm365g3gjy1wp1fqi25a-home-manager-path/bin/java
henry@nixos:~/my_system_config (master)$ java --version
openjdk 21.0.3 2024-04-16
OpenJDK Runtime Environment (build 21.0.3+9-nixos)
OpenJDK 64-Bit Server VM (build 21.0.3+9-nixos, mixed mode, sharing)

Steps To Reproduce

Steps to reproduce the behavior:

Add

pkgs.androidenv.androidPkgs.androidsdk

(defined here https://github.com/NixOS/nixpkgs/blob/ca6305bdf65dbc34baf9ad88cbb73f203042a4a9/pkgs/development/mobile/androidenv/default.nix#L18 )

from unstable to your system. Alternatively, since this package is a little heavy, you could use composeAndroidPackages instead.

let
androidComposition = pkgs.androidenv.composeAndroidPackages {
    platformVersions = [ "33" ];
    includeEmulator = true;
    includeSystemImages = true;
  };
in
{
  home.packages = [
      androidComposition.androidsdk
  ];
}

Expected behavior

The cli tool should work.

Additional context

From the manual: https://nixos.org/manual/nixpkgs/unstable/#android

Notify maintainers

@numinit @hadilq

Metadata

- system: `"x86_64-linux"`
 - host os: `Linux 6.11.0, NixOS, 24.05 (Uakari), 24.05.20240916.086b448`
 - multi-user?: `yes`
 - sandbox: `relaxed`
 - version: `nix-env (Nix) 2.18.5`
 - channels(henry): `"nixos-23.05"`
 - channels(root): `"nixos-24.05"`
 - nixpkgs: `/home/henry/.nix-defexpr/channels/nixpkgs`

Add a :+1: reaction to issues you find important.

mcmah309 commented 1 month ago

I was able to manually get past this issue with

henry@nixos:~/my_system_config (master)$ echo $JAVA_HOME

henry@nixos:~/my_system_config (master)$ export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
henry@nixos:~/my_system_config (master)$ echo $JAVA_HOME
/nix/store/5zij17yckck93248rb2grkpm1y3dzy1f-openjdk-21.0.3+9/lib/openjdk
henry@nixos:~/my_system_config (master)$ avdmanager

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.
hadilq commented 1 month ago

Thank you for reporting this. I'll check it out this week.

hadilq commented 4 weeks ago

please review https://github.com/NixOS/nixpkgs/pull/353914