NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.07k stars 14.12k forks source link

Android SDK Tools broken: Cannot locate latest build tools #237721

Open yakimant opened 1 year ago

yakimant commented 1 year ago

Describe the bug

Android SDK Tools are broken. For example running apkanalyzer from them:

Exception in thread "main" java.lang.IllegalStateException: Cannot locate latest build tools
        at com.android.tools.apk.analyzer.AaptInvoker.getPathToAapt(AaptInvoker.java:99)
        at com.android.tools.apk.analyzer.AaptInvoker.<init>(AaptInvoker.java:41)
        at com.android.tools.apk.analyzer.ApkAnalyzerCli.getAaptInvokerFromSdk(ApkAnalyzerCli.java:278)
        at com.android.tools.apk.analyzer.ApkAnalyzerCli.main(ApkAnalyzerCli.java:129)

Possible reason

208793, build-tools are not linked to tools

https://github.com/NixOS/nixpkgs/blob/6d1d80a232a355a65dc4d3bfea1f108e8dac1340/pkgs/development/mobile/androidenv/compose-android-packages.nix#L147-L156

Possible fix

Add a link, but it will couse infinite cycle, as build-tools also links to the tools.

Workaround

Switch to JDK11 and Android SDK Command-Line Tools

Steps To Reproduce

Steps to reproduce the behavior:

  1. Run a shell with androidenv
  2. Run apkanalyzer from ${ANDROID_HOME}/tools/bin/apkanalyzer

Expected behavior

Should print help

Additional context

SDK Tools can only run on JDK8

Notify maintainers

@hadilq

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 22.3.0, macOS 13.2.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.13.4`
 - channels(status): `""`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
hadilq commented 1 year ago

Thank you for reporting this. I'm not a user of apkanalyzer so I didn't face this problem before. I'll check it today.

hadilq commented 1 year ago

why do you want to use the apkanalyzer that exists in the tools? You may know that tools is obsoleted. There's a newer version of it in the cmdline-tools

[nix-shell:/nix/store/h0j69b6wq56kfjz0xj4h6w8qr6apgq06-androidsdk/libexec/android-sdk]$ ls -al $ANDROID_SDK_ROOT/cmdline-tools/9.0/bin/apkanalyzer
-r-xr-xr-x 1 root root 858 Dec 31  1969 /nix/store/h0j69b6wq56kfjz0xj4h6w8qr6apgq06-androidsdk/libexec/android-sdk/cmdline-tools/9.0/bin/apkanalyzer

to have access to it you don't even need to know that! For instance, you can use the examples/shell.nix, then just run apkanalyzer --version

[nix-shell:/nix/store/h0j69b6wq56kfjz0xj4h6w8qr6apgq06-androidsdk/libexec/android-sdk]$ apkanalyzer --help
Verb must be one of: 

Usage:
apkanalyzer [global options] <subject> <verb> [options] <apk> [<apk2>]

Option            Description                         
------            -----------                         
--human-readable  Print sizes in human readable format

Let me know if you have more concerns.

yakimant commented 1 year ago

I mentioned this workaround in my initial message.

A bit of our case: apkanalyzer from tools was used historicatlly (it can only run on JDK8). So now we are switching Android SDK Tools to Android SDK Command-Line Tools (it can only run on JDK11, so we upgrade it too).

This issue was created to highlight the issue with apkanalyzer from tools in nixpkgs. It is there, but you cannot run it. I propose either to remove tools or fix the issue for better clarity.

hadilq commented 1 year ago

unfortunately, we cannot remove the tools because the standard Android SDK keeps installing it, so we have to follow their steps, unless it's not the case anymore :D Regarding the fix, it doesn't look like it's adding any value, because of the reasons we mentioned above. If I had infinite time I would spend some of it to solve this interesting problem, but unfortunately I don't, but if someone solves it, I would be happy :)

yakimant commented 1 year ago

No prob, I actually didn't expect this unpopular issue to be fixed. Let it be here as motivation to use newer tools an JDK =)

BenceBakos commented 11 months ago

I run into a problem regarding platform tools. I trited to install packages necessary to develop flutter for android (with devbox), but when I run flutter doctor, I get this error:

    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`

just for reference, I installed these:

devbox global add openjdk11@latest android-tools@latest flutter@latest

I found this issue when I researched this issue, maybe you know what is the problem.

hadilq commented 11 months ago

@BenceBakos :| devbox? here is an issue related to NixOS, not devbox, as you can see in the address bar!!

BenceBakos commented 11 months ago

@BenceBakos :| devbox? here is an issue related to NixOS, not devbox, as you can see in the address bar!!

@hadilq

Sorry for the misunderstanding.

Devbox is just a package manager making the management of nix packages simpler.

I only mentioned it for additional context, the nix package is the same.