apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

cordova build ok, cordova run fails --> avdmanager list avd #1665

Closed patrickinminneapolis closed 7 months ago

patrickinminneapolis commented 7 months ago

I build to cordova android@12 with OpenJDK 11 and gradle 8.3. I'm using Android SDK Tools 33.0.2. Android Studio list a virtual device targetting API 33.

The .apk builds ok and runs on Windows Subsystem for Android, so I think its fine, but I can't run in with 'cordova run' (which I need for debugging) -- I get the same error with 'cordova run' that I get with 'cordova requirements'

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.(SchemaModule.java:156) at com.android.repository.api.SchemaModule.(SchemaModule.java:75) at com.android.sdklib.repository.AndroidSdkHandler.(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:582) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 5 more

All results on google talk about downgrading to Java 8, but that can't be the way forward.

breautek commented 7 months ago

You likely have $ANDROID_HOME/tools in your path which are the java 8 tools and that's where the java 8 requirements come from.

You can use which avdmanager to confirm which avdmanager you're hitting/using. The which command should be available for mac/linux, not sure about windows. But it's a command to simply print the path to the executable.

The SDK Manager has a cmdline-tools package, which contains newer versions of these tools when installed, it will be located in $ANDROID_HOME/cmdline-tools/<cmdline-tools_version>/bin. You'll want to add this path to your PATH environment variable. These tools supports java 11+. I'm currently using version 9, but the latest probably works too.

You'll also want to remove $ANDROID_HOME/tools if it's present. from your PATH variable if it's present.

While you're in the SDK manager, you can also uninstall Android SDK Tools (Obsolete) which is the $ANDROID_HOME/tools stuff.

You may also want to set other PATHs too..., see the Android Setup Guide (dev docs but it's more relevant than the current docs, atm)

Closing as not a bug.