我正在设置一个使用 cordova 部署 Android 应用程序的环境。操作系统是 Xubuntu 20.04。
我下载了sdk和jdk11并在
~/.bashrc
中设置环境变量如下
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
我用
cordova create
创建了一个项目,我添加了浏览器并运行它,一切都很顺利。
为 Android 构建有点棘手,但我想通了。如果我尝试使用 cordova run android
运行,当我的项目中调用 apkanalyzer 时,我总是会收到此错误,这是 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
谷歌搜索我发现问题可能是java版本,所以我尝试将JAVA_HOME设置为jdk8,然后设置为jdk17,但没有任何改变。 真正的问题是我无法在我的笔记本电脑上测试该应用程序,但它实际上可以工作,在构建之后我只是将 .apk 移动到智能手机上并安装它,没有任何问题。
我也关注了此链接,但我没有解决。
希望有人能帮助我,先谢谢你了
这看起来很疯狂,但我通过以下步骤解决了这个问题:
adb devices
。cordova run android
。希望有帮助!