Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 435
Alessio Mora Avatar asked Nov 14 '18 11:11

Alessio Mora


2 Answers

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"
like image 182
takladev Avatar answered Oct 31 '22 15:10

takladev


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"
like image 1
Teng-pao Yu Avatar answered Oct 31 '22 15:10

Teng-pao Yu