Cordova Android 构建失败

Posted

技术标签:

【中文标题】Cordova Android 构建失败【英文标题】:Cordova Android Builds Failing 【发布时间】:2018-10-07 16:55:32 【问题描述】:

我按照https://cordova.apache.org/#getstarted 的说明创建了一个新的 Cordova 项目

当我运行cordova build android --verbose 时,我得到以下输出:

No scripts found for hook "before_build". No scripts found for hook "before_prepare". Checking config.xml and package.json for saved platforms that haven't been added to the project Config.xml and package.json platforms are the same. No pkg.json modification. Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms. PlatformApi successfully found for platform android Android Studio project detected Checking config.xml for saved plugins that haven't been added to the project Checking for any plugins added to the project that have not been installed in android platform No differences found between plugins added to project and installed in android platform. Continuing... Generating platform-specific config.xml from defaults for android at /Users/ben.carpenter/code/cordovatest/platforms/android/app/src/main/res/xml/config.xml Merging project's config.xml into platform-specific android config.xml Merging and updating files from [www, platforms/android/platform_www] to platforms/android/app/src/main/assets/www Wrote out android application name "HelloCordova" to /Users/ben.carpenter/code/cordovatest/platforms/android/app/src/main/res/values/strings.xml android-versionCode not found in config.xml. Generating a code based on version in config.xml (1.0.0): 10000 Wrote out Android package name "io.cordova.hellocordova" to /Users/ben.carpenter/code/cordovatest/platforms/android/app/src/main/java/io/cordova/hellocordova/MainActivity.java This app does not have launcher icons defined This app does not have splash screens defined This app does not have additional resource files defined Prepared android project successfully No scripts found for hook "after_prepare". No scripts found for hook "before_compile". ANDROID_HOME=/Users/ben.carpenter/Library/Android/sdk JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home (node:6593) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object] (node:6593) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejectionsthat are not handled will terminate the Node.js process with a non-zero exit code.

当我运行cordova requirements android 时,我得到了这个:

``` 检测到 Android Studio 项目

android 的需求检查结果: Java JDK:已安装 Android SDK:已安装 true Android目标:未安装 avdmanager:命令失败,退出代码 1 错误输出: 线程“主”java.lang.NoClassDefFoundError 中的异常:javax/xml/bind/annotation/XmlSchema 在 com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156) 在 com.android.repository.api.SchemaModule.(SchemaModule.java:75) 在 com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81) 在 com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213) 在 com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200) 引起:java.lang.ClassNotFoundException:javax.xml.bind.annotation.XmlSchema 在 java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) 在 java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) 在 java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ... 5 更多 Gradle:已安装 /usr/local/Cellar/gradle/4.7/bin/gradle (节点:6724)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):[object Object] (节点:6724)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程。 ```

我试过安装各种 Android SDK 平台,我试过 Android studio 2.3 和 3.1。我在这里以及在 cordova 和 ionic 论坛上阅读了各种问题,但到目前为止没有任何帮助。

【问题讨论】:

【参考方案1】:

您为什么使用 Java 10?我知道 Cordova 需要 JDK 8,因此请尝试安装该版本,然后相应地更新您的 JAVA_HOME

【讨论】:

【参考方案2】:

您的 JDK 版本似乎有问题。尝试安装 JDK 8 并更新您的 JAVA_HOME 路径。

【讨论】:

以上是关于Cordova Android 构建失败的主要内容,如果未能解决你的问题,请参考以下文章

Cordova android 构建:app:processDebugResources 失败

Cordova 构建/运行 android 失败:无法读取 null 的属性“标签”

Cordova android 运行/构建错误 - JDK 1.8 的要求检查失败

Cordova 构建 android 失败!!! JDK 8('1.8.*')的要求检查失败!检测到的版本:9.0.1 在 Windows 10 中

使用 CMD 行构建失败 --ionic cordova build android

Ionic Cordova 使用 Gradle 构建 Android 错误并且构建失败 [重复]