android-sdk-image icon indicating copy to clipboard operation
android-sdk-image copied to clipboard

`apkanalyser` which is part of cmdline-tools is able to run due to exception

Open leroy0211 opened this issue 1 year ago • 1 comments

When running apkanalyzer it won't run and throws an exception.

Exception in thread "main" java.lang.IllegalStateException: The tools directory property is not set, please make sure you are executing apkanalyzer. Got /opt/android-sdk-linux/cmdline-tools
        at com.android.tools.apk.analyzer.ApkAnalyzerCli.getAaptInvokerFromSdk(ApkAnalyzerCli.java:271)
        at com.android.tools.apk.analyzer.ApkAnalyzerCli.main(ApkAnalyzerCli.java:128)

Expected behaviour

When running apkanalyzer it should show the help text of apk analyzer

Actual behaviour

It throws an exception.

Steps to reproduce the behaviour

  • run apkanalyzer (located in /opt/android-sdk-linux/cmdline-tools/bin/apkanalyzer)

Which Docker version is used?

Docker for mac desktop 24.0.6

Which host operation system is used?

  • [ ] Linux
  • [ ] Windows
  • [x] macOS

leroy0211 avatar Dec 28 '23 13:12 leroy0211

It appears that the cmdline-tools are installed in the wrong directory. As soon as I relocate them from /opt/android-sdk-linux/cmdline-tools/bin/apkanalyzer to /opt/android-sdk-linux/cmdline-tools/latest/bin/apkanalyzer it works perfectly.

I use the following RUN in my own Dockerfile to correct this, which is forwards compatible if eventually that latest directory is created.

FROM mobiledevops/android-sdk-image:34.0.0-jdk17

# ...

RUN         cd $ANDROID_HOME/cmdline-tools && \
                mkdir latest && find . -maxdepth 1 ! -path . ! -name "latest" -exec mv {} ./latest/ \;

leroy0211 avatar Dec 28 '23 13:12 leroy0211