5

Hi i'm trying to build a cordova project with android plugin in windows 7 with the following environment

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

i generated a cordova project

>cordova create CordovaProject io.xyz.hellocordova CordovaApp

and added the android plugin

>cordova platform add android

now after doing that i tried to build the android project

>cordova build android

this trying to download gradle-2.2.1-all.zip which leads to exception as

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

may be this was due to my office firewall/proxy which is not allowing to download the zip file. but i have the zip file extracted and set the path variable as

GRADLE_HOME = C:\gradle-2.2.1

even that also i'm not able to resolve this issue. I understand that the env. path variable is not accepted in build script but i'm not sure where to change or by-pass this step.

Gowtham S
  • 923
  • 14
  • 39

5 Answers5

16

As you mentioned, it looks more like a network issue. The gradle download will fail if you are using restricted proxy network. In case of network restrictions, you can work around this issue by following the steps below:

1) Download the required gradle version zip file from gradle distribution link and save it in local folder.

2) Navigate to PROJECT_ROOT_FOLDER/platforms/android/cordova/lib/builders folder and edit GradleBuilder.js file

3) Change the line from var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http\\://services.gradle.org/distributions/gradle-2.2.1-all.zip'; to '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'; and save the file

4) Try rebuilding android build.

You can also try the following as quick fix,

1) In command prompt execute the following command: export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=file:///local/path/to/folder/where/gradle/zip/is/saved/gradle-2.2.1-all.zip

2) Execute the following command: cordova run android

Community
  • 1
  • 1
Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • Thanks @Gandhi, working great...!!!. I just set the env. path variable as you mentioned .. CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=file:///local/path/to/folder/where/gradle/zip/is/saved/gradle-2.2.1-all.zip – Gowtham S May 23 '16 at 09:04
  • @SudarpoChong Glad it was helpful. Cheers – Gandhi May 09 '17 at 05:22
3

You need to set the gradle proxy by adding these lines to ~/.gradle/gradle.properties (create the file if it does not exist):

systemProp.http.proxyHost=myproxy.com
systemProp.http.proxyPort=123
systemProp.https.proxyHost=myproxy.com
systemProp.https.proxyPort=123

Substitute your proxy and port, of course.

wisbucky
  • 33,218
  • 10
  • 150
  • 101
  • I don't have a direct proxy host and port... My network proxy is on automatic configuration script works with *.pac file. I think the issue was due to unable to download a zip archive also i don't have a gradle.properties under .gradle folder. As i mentioned above i downloaded it seperatly and set my download path to that file path. thanks for the help.. – Gowtham S Jun 20 '16 at 13:38
0

I had the same problem when I execute the command cordova build android it through this error. I was tried more that 1hour finally I disable my antivirus software (Avast) and just execute the command again, now it was execute successfully.

Merbin Joe
  • 121
  • 1
  • 15
0

I have downloaded the certificate from https://services.gradle.org/distributions using the browser and added it to my Java installation cacert file and it worked for me after that..

Example:

C:\Program Files\Java\jdk1.8.0_40\jre\lib\security> keytool -import -alias gradle -keystore cacerts -trustcacerts -fi le D:\Configurations\certificates\gradle.cer

Sunil Kpmbl
  • 751
  • 8
  • 10
0

Finally, I found the solution,

The issue is due to the multiple java reference in the environment variables.

I have removed all the JDK installed, also removed all the java references from the environment variable. And reinstalled the jdk1.8.161 (as most of the people used this version in 8 series) and updated the environment variable accordingly.

Please find the packages and versions finally working for me.

Node.js version 13.8 with npm 6.13.6,
Cordova version 9 (installed globally),
Android SDK Latest with target up to android -25 & build tools.
Java JDK - 1.8.161.
Gradle - 2.14.1_all

Environment variable references:-

Node.js (installed in c drive),
Android SDK path,
Android SDK platforms path,
Android SDK build path,
Android SDK tools path,
Java JDK path (installed in c drive),
Java jre path (available along with jdk path in c drive),
Gradle path (extracted in c drive/gradle/),
Gradle zip path.

And I didn't make any reference to Cordova in the environment variable.

Also, updated the project/platforms/android/cordova/lib/builders/GradleBuilder.js with the distribution URL pointing to the local Gradle zip file. (Http link also working).

Created a hello world app with android@6.0.0 and successfully build the apk.

Abhinav Suman
  • 940
  • 1
  • 9
  • 29