为啥在使用 Cordova 构建 APK 时出现此错误?

Posted

技术标签:

【中文标题】为啥在使用 Cordova 构建 APK 时出现此错误?【英文标题】:Why do I get this error while building an APK with Cordova?为什么在使用 Cordova 构建 APK 时出现此错误? 【发布时间】:2020-08-04 10:11:33 【问题描述】:

我正在尝试制作一个网络应用程序的 APK,我将它包装到 Cordova 中。 我遵循了各种教程,安装了 Gradle 并使其工作。

当我从 CMD 运行 cordova build android ---verbose 时,我收到此错误:

ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\USER\AppData\Local\Android\sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app
Running command: C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\platforms\android\gradlew cdvBuildDebug -b C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\platforms\android\build.gradle
Exception in thread "main" java.lang.RuntimeException: Could not load wrapper properties from 'C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\platforms\android\gradle\wrapper\gradle-wrapper.properties'.
        at org.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:61)
        at org.gradle.wrapper.WrapperExecutor.forWrapperPropertiesFile(WrapperExecutor.java:45)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:62)
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 16: C:UsersUSERDownloadsgradle-6.3-bin.zip
        at java.net.URI$Parser.fail(URI.java:2848)
        at java.net.URI$Parser.checkChars(URI.java:3021)
        at java.net.URI$Parser.parse(URI.java:3058)
        at java.net.URI.<init>(URI.java:588)
        at org.gradle.wrapper.WrapperExecutor.readDistroUrl(WrapperExecutor.java:80)
        at org.gradle.wrapper.WrapperExecutor.prepareDistributionUri(WrapperExecutor.java:67)
        at org.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:54)
        ... 2 more
Command finished with error code 1: C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\platforms\android\gradlew cdvBuildDebug,-b,C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\platforms\android\build.gradle
C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\platforms\android\gradlew: Command failed with exit code 1 Error output:
Exception in thread "main" java.lang.RuntimeException: Could not load wrapper properties from 'C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\platforms\android\gradle\wrapper\gradle-wrapper.properties'.
        at org.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:61)
        at org.gradle.wrapper.WrapperExecutor.forWrapperPropertiesFile(WrapperExecutor.java:45)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:62)
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 16: C:UsersUSERDownloadsgradle-6.3-bin.zip
        at java.net.URI$Parser.fail(URI.java:2848)
        at java.net.URI$Parser.checkChars(URI.java:3021)
        at java.net.URI$Parser.parse(URI.java:3058)
        at java.net.URI.<init>(URI.java:588)
        at org.gradle.wrapper.WrapperExecutor.readDistroUrl(WrapperExecutor.java:80)
        at org.gradle.wrapper.WrapperExecutor.prepareDistributionUri(WrapperExecutor.java:67)
        at org.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:54)
        ... 2 more
Error: C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\platforms\android\gradlew: Command failed with exit code 1 Error output:
Exception in thread "main" java.lang.RuntimeException: Could not load wrapper properties from 'C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\platforms\android\gradle\wrapper\gradle-wrapper.properties'.
        at org.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:61)
        at org.gradle.wrapper.WrapperExecutor.forWrapperPropertiesFile(WrapperExecutor.java:45)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:62)
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 16: C:UsersUSERDownloadsgradle-6.3-bin.zip
        at java.net.URI$Parser.fail(URI.java:2848)
        at java.net.URI$Parser.checkChars(URI.java:3021)
        at java.net.URI$Parser.parse(URI.java:3058)
        at java.net.URI.<init>(URI.java:588)
        at org.gradle.wrapper.WrapperExecutor.readDistroUrl(WrapperExecutor.java:80)
        at org.gradle.wrapper.WrapperExecutor.prepareDistributionUri(WrapperExecutor.java:67)
        at org.gradle.wrapper.WrapperExecutor.<init>(WrapperExecutor.java:54)
        ... 2 more
    at ChildProcess.whenDone (C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\node_modules\cordova-common\src\superspawn.js:135:23)
    at ChildProcess.emit (events.js:310:20)
    at ChildProcess.cp.emit (C:\Users\USER\Desktop\Tlf Cordova\AngularToMobileProject-master\node_modules\cordova-common\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

使用 Gradle 6.3

我尝试了很多教程和 *** 解决方案,但没有一个适合我。

我的 gradle-wrapper.properties

2018 年 10 月 16 日星期二 17:39:45 IST

distributionBase=GRADLE_USER_HOME

distributionPath=wrapper/dists

zipStoreBase=GRADLE_USER_HOME

zipStorePath=wrapper/dists

distributionUrl=C:\Users\USER\Downloads\gradle-6.3-bin.zip

【问题讨论】:

【参考方案1】:

我将 gradle 5.1.1 用于 cordova9.0。 没有问题。

【讨论】:

显然没有解决我的问题,你认为是版本问题吗?我们使用的是相同的 Cordova 版本 我尝试过对 Gradle 进行降级,但问题仍然像以前一样...... 您必须重试删除和添加平台。科尔多瓦平台删除安卓科尔多瓦平台添加安卓

以上是关于为啥在使用 Cordova 构建 APK 时出现此错误?的主要内容,如果未能解决你的问题,请参考以下文章

为啥在尝试使用指针访问结构时出现此分段错误?

生成 apk 时出现 Cordova-plugin-file 错误

为啥在为 ROR 安装 DevKit 时出现此错误

为啥在运行此 OpenCV 程序时出现此异常?

上传我的应用时出现此错误:上传失败 您需要为您的 APK 使用与版本代码 1 不同的版本代码

为啥在将应用程序部署到 Heroku 时出现此错误?