9

I'm trying to run apkanalyzer from Android SDK tools from command line. However, it won't start and prints the following exception:

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

My cmdline is:

~/Programs/android-sdk-linux$ tools/bin/apkanalyzer apk summary ~/projects/mservice.apk

ANDROID_SDK_ROOT is set.

Here is my installation (sdkmanager --list):

Installed packages:=====================] 100% Computing updates...             
  Path                 | Version | Description                    | Location             
  -------              | ------- | -------                        | -------              
  build-tools;28.0.3   | 28.0.3  | Android SDK Build-Tools 28.0.3 | build-tools/28.0.3/  
  build-tools;29.0.2   | 29.0.2  | Android SDK Build-Tools 29.0.2 | build-tools/29.0.2/  
  platform-tools       | 29.0.6  | Android SDK Platform-Tools     | platform-tools/      
  platforms;android-28 | 6       | Android SDK Platform 28        | platforms/android-28/
  platforms;android-29 | 4       | Android SDK Platform 29        | platforms/android-29/
  tools                | 1.0.0   | Android SDK Tools 1            | tools/               

What is wrong?

Giorgos Neokleous
  • 1,709
  • 1
  • 14
  • 25
olegst
  • 1,209
  • 1
  • 13
  • 33
  • Which command are you using to open your APK? – MatPag Mar 30 '20 at 07:31
  • @MatPag I get the same error with any command. Or do you mean what exactly my cmdline is? – olegst Mar 30 '20 at 07:40
  • yes, I mean what is exactly your command – MatPag Mar 30 '20 at 07:50
  • @MatPag updated in description – olegst Mar 30 '20 at 07:56
  • 1
    `sdkmanager --list` is giving you all the installable packages, not the one installed on your machine. Open Android Studio and in the SDK Tools tab be sure to have download `Android SDK Tools 26.1.1` – MatPag Mar 30 '20 at 08:01
  • This problem also happen to me. I can't run apkanalyzer. Error msg: "The tools directory property is not set". Seems it can't detect "build-tools\30.0.3" directory. – dns Dec 08 '20 at 22:46

2 Answers2

2

apkanalyzer expects to live in a different folder than it is actually in. This is the same error as with sdkmanager, also part of cmdline-tools. See this question: The solution is to move /path/to/cmdline-tools to /path/to/cmdline-tools/latest.

I found this by googling for The tools directory property is not set > https://android.googlesource.com/platform/development/.../Main.java > com.android.sdkmanager.toolsdir > run sdkmanager > Error: Could not determine SDK root. > Failed to run sdkmanager --list with Java 9.

phil294
  • 10,038
  • 8
  • 65
  • 98
1

your tools version is version is very old.

It should be atleast greater than 26.0

Use

sdkmanager --install tools
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103