Android apkanalyzer, invoked by command line, gives a "NoClassDefFoundError" exception
Asked Answered
A

3

15

I am trying to run the apkanalyzer tool provided by Android SDK (under Sdk/tool/bin), but I am not able to make it work. I know that I can also use this tool through AndroidStudio, but I need to automate the apk analysis to cover a lot of APKs. So, I followed this https://developer.android.com/studio/command-line/apkanalyzer to use it.

Anyway, when I try to launch apkanalyzer (e.g. apkanalyzer apk summary APKname.apk) it gives the following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156) at com.android.repository.api.SchemaModule.(SchemaModule.java:75) at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81) at com.android.tools.apk.analyzer.ApkAnalyzerCli.getAaptInvokerFromSdk(ApkAnalyzerCli.java:277) at com.android.tools.apk.analyzer.ApkAnalyzerCli.main(ApkAnalyzerCli.java:129) Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ... 5 more

Where is the problem?

Afternoons answered 14/11, 2018 at 11:22 Comment(2)
Did you resolve it? I'm having the same error.Piggish
No, unfortunately I did not figure out what was the problem. I just did the analysis that I needed by hand, by writing a little program that unpackages the APKs and extracts the information I was looking for.Afternoons
P
6

I had the same issue. All I had to do was set the JAVA_HOME correctly. I set the JAVA_HOME in my bashrc to $PATH_TO_ANDROIDSTUDIO/jre

my exact statement in ~/.bashrc:

export JAVA_HOME=/home/rahul/Softwares/android-studio/jre

Sample for Mac users:

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/jre"
Picardi answered 16/10, 2019 at 7:27 Comment(0)
S
2

Since Android Studio 4.2 runs with java 11 instead of java 8, you might also notice this error upon your Android Studio upgrade if you are pointing JAVA_HOME toward your AS bundled jdk. (See also)

To recover:

  1. Download jdk 8 yourself (https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html)
  2. Find out the 1.8 JAVA_HOME path (/usr/libexec/java_home -V on mac)
Matching Java Virtual Machines (2):
    15.0.1, x86_64: "OpenJDK 15.0.1"    <path to have home1>
    1.8.0_291, x86_64:  "Java SE 8"     <path to have home2>
  1. Run the following:
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/jre"
Subaqueous answered 10/5, 2021 at 1:42 Comment(0)
T
0

I had the same issue because i wasn't using the latest verion from SDK Manager

Tessietessier answered 23/6 at 20:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.