Home > Blockchain >  Can't build Cordova App due to "Failure: Build failed with an exception"
Can't build Cordova App due to "Failure: Build failed with an exception"

Time:11-23

I have been trying for hours to create a simple cordova project and somehow I cannot get past the building process. After installing all requirements (Java SDK, Gradle, Android Studio) and defining my environment variables I still get this error:

What I did so far:
cordova create Testproject com.example.hello Testproject
cd Testproject
cordova platform add android (10.1.1)

Then I wanted to check the "cordova requirements" command to check if I set everything up correctly and then this happened:

C:\Users\NAME\Desktop\TestProject>cordova requirements

Requirements check results for android:
Java JDK: installed 19.0.1
Android SDK: installed true
Android target: not installed
Command failed with exit code 1: avdmanager list target
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.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213)
        at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 5 more
Gradle: installed C:\gradle-6.9.3\bin\gradle.BAT
Some of requirements check failed

C:\Users\NAME\Desktop\TestProject>cordova build
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\NAME\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\NAME\AppData\Local\Android\Sdk
Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* Where:
Settings file 'C:\Users\NAME\Desktop\TestProject\platforms\android\settings.gradle'

* What went wrong:
Could not compile settings file 'C:\Users\NAME\Desktop\TestProject\platforms\android\settings.gradle'.
> startup failed:
  General error during semantic analysis: Unsupported class file major version 63

My settings.gradle file:

// GENERATED FILE - DO NOT EDIT
apply from: "cdv-gradle-name.gradle"
include ":"
include ":CordovaLib"
include ":app"

Java Version: 19.0.1
Cordova Version: 11.0.0
NPM Version: 7.15.0
Gradle Version: 6.9.3

(If you need anymore information, I am happy to provide them!)

What I did so far:
cordova create Testproject com.example.hello Testproject
cd Testproject
cordova platform add android (10.1.1)

Then I wanted to check the "cordova requirements" command to check if I set everything up correctly and then the error from above occured.

CodePudding user response:

With Cordova version 11.0.0, I got it working by downgrading from Java 19 to java 11. Java Development Kit (JDK)

You could try using java version 11

  • Related