NoClassDefFoundError when calling apkanalyzer running cordova

353 views Asked by At

I'm setting up an enviroment for deploying android app with cordova. The OS is Xubuntu 20.04.

I downloaded the sdk and jdk11 and set the enviroment variables in ~/.bashrc as follows

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export ANDROID_SDK_ROOT=/home/nik/Android/Sdk
export ANDROID_HOME=/home/nik/Android/Sdk
export PATH=$ANDROID_HOME/build-tools:$PATH
export PATH=$ANDROID_HOME/emulator:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH

I created a project with cordova create, I add browser and ran it, everithing went good. Building for android was a little tricky but i figured out. If i try to run with cordova run android i always get this error when is called apkanalyzer on my project, this is the output of cordova run android:

Checking Java JDK and Android SDK versions
ANDROID_HOME=/home/nik/Android/Sdk (recommended setting)
ANDROID_SDK_ROOT=/home/nik/Android/Sdk (DEPRECATED)
Using Android SDK: /home/nik/Android/Sdk
Subproject Path: CordovaLib
Subproject Path: app
Starting a Gradle Daemon (subsequent builds will be faster)

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 12s
50 actionable tasks: 50 up-to-date
Built the following apk(s): 
        /home/nik/Desktop/cordova/first/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Checking Java JDK and Android SDK versions
ANDROID_HOME=/home/nik/Android/Sdk (recommended setting)
ANDROID_SDK_ROOT=/home/nik/Android/Sdk (DEPRECATED)
Using Android SDK: /home/nik/Android/Sdk
Command failed with exit code 1: apkanalyzer manifest target-sdk /home/nik/Desktop/cordova/first/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
        at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
        at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
        at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(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:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 5 more

Googling I found out the problem could be the java version and so I tried to set JAVA_HOME to jdk8 and then to jdk17 and nothing changed. The real problem is I can not test the app on my laptop but it actually works, after it was built I just moved the .apk on smartphone and installed it and got no problem.

I also follwed this link but I not solved.

Hope someone can help me, thank you in advance

0

There are 0 answers