gpt4 book ai didi

java - 构建 Cordova Android 项目时出错

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:36:46 26 4
gpt4 key购买 nike

您好,我正在尝试在 Windows 7 中使用 android 插件构建一个 cordova 项目以下环境

ANDROID_HOME=D:\DevTools\Android\Android_SDK_NDK\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45

我生成了一个cordova项目

>cordova create CordovaProject io.xyz.hellocordova CordovaApp

并添加了android插件

>cordova platform add android

现在在这样做之后我尝试构建 android 项目

>cordova build android

尝试下载 gradle-2.2.1-all.zip 会导致异常

E:\Cordova\Workspace\HelloCordova>cordova build android --verbose
Executing "before_build" hook for all plugins.
Executing "before_prepare" hook for all plugins.
Searching PlatformJson files for differences between project vs. platform instal
led plugins
No differences found between project and android platform. Continuing...
Generating config.xml from defaults for platform "android"
Wrote out Android application name to "HelloCordova"
Wrote out Android package name to "com.gowtham.HelloCordova"
This app does not have launcher icons defined
updated project successfully
Executing "after_prepare" hook for all plugins.
Executing "before_compile" hook for all plugins.
ANDROID_HOME=D:\DevTools\Android\Android_SDK_NDK\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45
Downloading http://services.gradle.org/distributions/gradle-2.2.1-all.zip

Exception in thread "main" java.lang.RuntimeException: java.net.ConnectException
: Connection timed out: connect
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc
essManager.java:78)
at org.gradle.wrapper.Install.createDist(Install.java:47)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketI
mpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.ja
va:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket
Impl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java
:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
at sun.net.www.http.HttpClient.New(HttpClient.java:308)
at sun.net.www.http.HttpClient.New(HttpClient.java:326)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLC
onnection.java:996)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
ction.java:932)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
.java:850)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1300)
at org.gradle.wrapper.Download.downloadInternal(Download.java:59)
at org.gradle.wrapper.Download.download(Download.java:45)
at org.gradle.wrapper.Install$1.call(Install.java:60)
at org.gradle.wrapper.Install$1.call(Install.java:47)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc
essManager.java:65)
... 3 more
Error: Error code 1 for command: cmd with args: /s,/c,"E:\Cordova\Workspace\Hell
oCordova\platforms\android\gradlew cdvBuildDebug -b E:\Cordova\Workspace\HelloCo
rdova\platforms\android\build.gradle -Dorg.gradle.daemon=true -Pandroid.useDepre
catedNdk=true"

E:\Cordova\Workspace\HelloCordova>gradle -version

------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------

Build time: 2014-11-24 09:45:35 UTC
Build number: none
Revision: 6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a

Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_45 (Oracle Corporation 24.45-b08)
OS: Windows 7 6.1 x86

可能是因为我办公室的防火墙/代理不允许下载 zip 文件。但我提取了 zip 文件并将路径变量设置为

GRADLE_HOME = C:\gradle-2.2.1

即便如此,我也无法解决这个问题。我知道环境。构建脚本不接受路径变量,但我不确定在哪里更改或绕过此步骤。

最佳答案

如您所述,它看起来更像是网络问题。如果您使用受限代理网络,gradle 下载将失败。如果出现网络限制,您可以按照以下步骤解决此问题:

1) 从 gradle 分发链接下载所需的 gradle 版本 zip 文件并将其保存在本地文件夹中。

2) 导航到 PROJECT_ROOT_FOLDER/platforms/android/cordova/lib/builders 文件夹并编辑 GradleBuilder.js 文件

3) 从 var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 更改行'http\\://services.gradle.org/distributions/gradle-2.2.1-all.zip';

'var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'file:///local/path/to/folder/where/gradle/zip/is/saved/gradle-2.2.1-all.zip';并保存文件

4) 尝试重建 android 构建。

您也可以尝试以下方法作为快速修复,

1) 在命令提示符下执行以下命令:export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=file:///local/path/to/folder/where/gradle/zip/is/saved/gradle-2.2.1-all。 zip

2) 执行以下命令:cordova run android

关于java - 构建 Cordova Android 项目时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37349019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com